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

Bug fix: JWTAuthenticator must reload when spec.audience or spec.claims changes #2090

Merged
merged 4 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
4 changes: 2 additions & 2 deletions generated/1.28/apis/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions generated/1.28/apis/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated/1.28/client/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions generated/1.28/client/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated/1.29/apis/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions generated/1.29/apis/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions generated/1.29/client/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions generated/1.29/client/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated/1.30/apis/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions generated/1.30/apis/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions generated/1.30/client/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions generated/1.30/client/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated/1.31/apis/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions generated/1.31/apis/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions generated/1.31/client/go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions generated/1.31/client/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions hack/lib/kube-versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# Whenever a new version is added to this file, or when a version number
# is edited in this file, please run hack/update.sh.
#
1.31.1
1.30.5
1.29.9
1.28.14
1.31.2
1.30.6
1.29.10
1.28.15
1.27.16
1.26.15
1.25.16
16 changes: 13 additions & 3 deletions internal/controller/authenticator/jwtcachefiller/jwtcachefiller.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ type tokenAuthenticatorCloser interface {
type cachedJWTAuthenticator struct {
authenticator.Token
issuer string
audience string
claims authenticationv1alpha1.JWTTokenClaims
caBundleHash tlsconfigutil.CABundleHash
cancel context.CancelFunc
}
Expand Down Expand Up @@ -239,7 +241,7 @@ func (c *jwtCacheFillerController) syncIndividualJWTAuthenticator(ctx context.Co
// are for administrator convenience at the time of a configuration change, to catch typos and blatant
// misconfigurations, rather than to constantly monitor for external issues.
foundAuthenticatorInCache, previouslyValidatedWithSameEndpointAndBundle := c.havePreviouslyValidated(
cacheKey, jwtAuthenticator.Spec.Issuer, tlsBundleOk, caBundle.Hash(), logger)
cacheKey, jwtAuthenticator.Spec, tlsBundleOk, caBundle.Hash(), logger)
if previouslyValidatedWithSameEndpointAndBundle {
// Because the authenticator was previously cached, that implies that the following conditions were
// previously validated. These are the expensive validations to repeat, so skip them this time.
Expand Down Expand Up @@ -331,7 +333,7 @@ func (c *jwtCacheFillerController) doExpensiveValidations(

func (c *jwtCacheFillerController) havePreviouslyValidated(
cacheKey authncache.Key,
issuer string,
spec authenticationv1alpha1.JWTAuthenticatorSpec,
tlsBundleOk bool,
caBundleHash tlsconfigutil.CABundleHash,
logger plog.Logger,
Expand All @@ -345,7 +347,13 @@ func (c *jwtCacheFillerController) havePreviouslyValidated(
if authenticatorFromCache == nil {
return false, false
}
if authenticatorFromCache.issuer == issuer &&
// Compare all spec fields to check if they have changed since we cached the authenticator.
// Instead of directly comparing spec.TLS, compare the effective result of spec.TLS,
// which is the CA bundle that was dynamically loaded.
// If any spec field has changed, then we need a new in-memory authenticator.
if authenticatorFromCache.issuer == spec.Issuer &&
authenticatorFromCache.audience == spec.Audience &&
authenticatorFromCache.claims == spec.Claims &&
tlsBundleOk && // if there was any error while validating the latest CA bundle, then do not consider it previously validated
authenticatorFromCache.caBundleHash.Equal(caBundleHash) {
return true, true
Expand Down Expand Up @@ -702,6 +710,8 @@ func (c *jwtCacheFillerController) newCachedJWTAuthenticator(
return &cachedJWTAuthenticator{
Token: oidcAuthenticator,
issuer: spec.Issuer,
audience: spec.Audience,
claims: spec.Claims,
caBundleHash: caBundleHash,
cancel: cancel,
}, conditions, nil
Expand Down
Loading
Loading