Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InMemoryChannel ingress: added getOIDC #8104

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pkg/auth/token_verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,19 @@
SubjectTypes []string `json:"subject_types_supported"`
SigningAlgs []string `json:"id_token_signing_alg_values_supported"`
}

// Getting the OIDCIdentity
func (c *OIDCTokenVerifier) GetOIDCIdentity(ctx context.Context, r *http.Request, audience string) (*IDToken, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the other comment, the goal if your function is to get OIDC Identity and not verify the request as you are doing on line 191.

token := GetJWTFromHeader(r.Header)
if token == "" {
return nil, fmt.Errorf("no JWT token found in request")
}

// Verify the JWT token
oidcToken, err := c.VerifyJWT(ctx, token, audience)
if err != nil {
return nil, fmt.Errorf("failed to verify JWT: %v", err)
}

return oidcToken, nil
}
5 changes: 3 additions & 2 deletions pkg/channel/event_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,13 @@ func (r *EventReceiver) ServeHTTP(response nethttp.ResponseWriter, request *neth
features := feature.FromContext(ctx)
if features.IsOIDCAuthentication() {
r.logger.Debug("OIDC authentication is enabled")
err = r.tokenVerifier.VerifyJWTFromRequest(ctx, request, &r.audience, response)
oidcToken, err := r.tokenVerifier.GetOIDCIdentity(ctx, request, r.audience)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal here is to verify the the request, I'd not change the existing code instead use a seperate function to get the OIDC Token!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay , I'll add a separate function to do that and leave it as it was ..
Thanks !

if err != nil {
r.logger.Warn("Error when validating the JWT token in the request", zap.Error(err))
response.WriteHeader(nethttp.StatusUnauthorized)
return
}
r.logger.Debug("Request contained a valid JWT. Continuing...")
r.logger.Debug("Request contained a valid JWT. Continuing...", zap.String("subject", oidcToken.Subject))
}

err = r.receiverFunc(request.Context(), channel, *event, utils.PassThroughHeaders(request.Header))
Expand Down
Loading