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

feat: make oidc discovery url configurable #8145

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Cali0707
Copy link
Member

@Cali0707 Cali0707 commented Aug 9, 2024

Fixes #8121

Proposed Changes

  • Add feature flag for OIDC discovery base url
  • Use feature flag in token verifier when building discovery config

Release Note

The OIDC discovery url is now configurable with the oidc-discovery-base-url feature flag in the config-features configmap.

@knative-prow knative-prow bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 9, 2024
@knative-prow knative-prow bot requested review from creydr and Leo6Leo August 9, 2024 16:48
Copy link

knative-prow bot commented Aug 9, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Cali0707

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 9, 2024
@Cali0707
Copy link
Member Author

Cali0707 commented Aug 9, 2024

/cc @pierDipi @creydr

Should we also backport this at all to make OIDC work on EKS in previous releases?

@knative-prow knative-prow bot requested a review from pierDipi August 9, 2024 16:49
Copy link

codecov bot commented Aug 9, 2024

Codecov Report

Attention: Patch coverage is 18.30986% with 58 lines in your changes missing coverage. Please review.

Project coverage is 67.37%. Comparing base (e79f3b6) to head (eee1320).

Files with missing lines Patch % Lines
pkg/auth/verifier.go 0.00% 32 Missing ⚠️
cmd/jobsink/main.go 0.00% 9 Missing ⚠️
cmd/broker/filter/main.go 0.00% 4 Missing ⚠️
cmd/broker/ingress/main.go 0.00% 4 Missing ⚠️
pkg/apis/feature/features.go 55.55% 2 Missing and 2 partials ⚠️
...econciler/inmemorychannel/dispatcher/controller.go 55.55% 3 Missing and 1 partial ⚠️
pkg/broker/filter/filter_handler.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8145      +/-   ##
==========================================
- Coverage   67.47%   67.37%   -0.10%     
==========================================
  Files         371      371              
  Lines       18036    18068      +32     
==========================================
+ Hits        12169    12173       +4     
- Misses       5088     5114      +26     
- Partials      779      781       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -57,14 +53,14 @@ type IDToken struct {
AccessTokenHash string
}

func NewOIDCTokenVerifier(ctx context.Context) *OIDCTokenVerifier {
func NewOIDCTokenVerifier(ctx context.Context, features feature.Flags) *OIDCTokenVerifier {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason, for not getting the feature store from the given context?

Copy link
Member Author

@Cali0707 Cali0707 Aug 12, 2024

Choose a reason for hiding this comment

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

This made it easier to re-create the verifier in the callback functions when the config-features cm changes

@Cali0707
Copy link
Member Author

/cc @creydr

@knative-prow knative-prow bot requested a review from creydr August 16, 2024 14:28
@knative-prow-robot knative-prow-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 16, 2024
@Cali0707
Copy link
Member Author

/cc @creydr @pierDipi

@pierDipi
Copy link
Member

/assign @creydr

Can you take a look?

@Cali0707
Copy link
Member Author

/cc @creydr @pierDipi

@pierDipi
Copy link
Member

@creydr can you take a look?

@creydr
Copy link
Member

creydr commented Sep 16, 2024

/cc

@creydr
Copy link
Member

creydr commented Sep 17, 2024

Rebased after #8195

@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 17, 2024
@creydr
Copy link
Member

creydr commented Sep 17, 2024

@Cali0707, on testing with oidc-discovery-base-url: "https://oidc.eks.eu-west-1.amazonaws.com/id/1", I saw

Get \"https://oidc.eks.eu-west-1.amazonaws.com/id/1/.well-known/openid-configuration\": tls: failed to verify certificate: x509: certificate signed by unknown authority}

This was because the used HTTP client of the TokenVerifier (now only Verifier) only took the CA certs from the API server. I addressed this in eee1320 (which should support Trustbundles too).

@creydr
Copy link
Member

creydr commented Sep 17, 2024

I can also check on #8145 (comment) and get the features from the ctx in auth.NewVerifier()

@Cali0707
Copy link
Member Author

I can also check on #8145 (comment) and get the features from the ctx in auth.NewVerifier()

Would this work if the features were updated to have a new url?

@creydr
Copy link
Member

creydr commented Sep 17, 2024

I can also check on #8145 (comment) and get the features from the ctx in auth.NewVerifier()

Would this work if the features were updated to have a new url?

When we make sure we pass a context, which has the features (e.g. featureStore.ToContext(ctx)), I'd guess so

Anyhow not totally sure about it, as having it as a parameter shows directly, that this is required for the function call 🤔

@creydr
Copy link
Member

creydr commented Sep 18, 2024

@pierDipi As I also committed to this PR, could you give it a quick review from your side too?

featureStore := feature.NewStore(logging.FromContext(ctx).Named("feature-config-store"), func(name string, value interface{}) {
logger.Info("Updated", zap.String("name", name), zap.Any("value", value))
if flags, ok := value.(feature.Flags); ok && h != nil {
h.authVerifier = auth.NewVerifier(ctx, eventpolicyinformer.Get(ctx).Lister(), trustBundleConfigMapLister, flags)
Copy link
Member

@pierDipi pierDipi Sep 19, 2024

Choose a reason for hiding this comment

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

This is changing a variable which is shared across goroutines, we might want to use a mutex or atomic handles

Now that I think more, maybe adding this "update logic" to the verifier might encapsulate that and we won't duplicate "multi-threading" everywhere this is used

Copy link
Member

Choose a reason for hiding this comment

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

@Cali0707 just as an idea, you could pass a configmapwatcher to auth.NewVerifier(), which then retriggers the initOIDCProvider() on changes

Copy link
Member Author

Choose a reason for hiding this comment

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

I like that idea @creydr - let me try this tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make OIDC Discovery URL configurable
4 participants