-
Notifications
You must be signed in to change notification settings - Fork 618
Support for configurable tls in remote jwks store #13014
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
Open
dmitri-d
wants to merge
31
commits into
kgateway-dev:main
Choose a base branch
from
dmitri-d:remote-jwks-with-refs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
4eb5267
only reconcile jwks for policies that have changed
dmitri-d 3ed1725
use a controller to sync jwks store to ConfigMaps
dmitri-d 04a8cef
fixed lost event in jwks source collection
dmitri-d cca6e30
parse BackendTLSPolicy to use with remote jwks
dmitri-d 519e877
an initial implementation for supporting of backendRefs in Agentgatew…
dmitri-d c87df28
added support for setting of InsecureSkipVerify in tls options
dmitri-d 19f87bd
Merge remote-tracking branch 'upstream/main' into remote-jwks-with-cm…
dmitri-d 91fc675
fixed spelling mistakes and such
dmitri-d c7b4a54
fix tests
dmitri-d c3d2cd5
make fmt
dmitri-d 3d60d4d
fixed liniting issues
dmitri-d 04d038d
Merge remote-tracking branch 'upstream/main' into remote-jwks-with-cm…
dmitri-d 1ffdf58
Merge remote-tracking branch 'upstream/main' into remote-jwks-with-cm…
dmitri-d 1c37386
Merge remote-tracking branch 'upstream/main' into remote-jwks-with-cm…
dmitri-d 5e70df0
cleaned up reusable labels
dmitri-d a6931ae
small fixes
dmitri-d 2937ceb
Merge branch 'remote-jwks-with-cm-controller' into remote-jwks-with-refs
dmitri-d 7b034fa
post-merge fixes
dmitri-d ef548f1
use BackendTLS
dmitri-d 2f2b513
broke up jwksUri into jwksPath + fqdn from backend/service
dmitri-d 9fbd9a9
Merge remote-tracking branch 'upstream/main' into remote-jwks-with-refs
dmitri-d 84880b2
added comments
dmitri-d 427f5ce
make linter happy
dmitri-d 2fbae93
make fmt
dmitri-d 0cd442c
added missing String() func to TargetRefIndexKey
dmitri-d e7b6aa4
handle missing AgentgatewayPolicy when computing jwks url
dmitri-d 86cf818
updated existing tests and added more
dmitri-d 3daf6e9
added missing rbac tests
dmitri-d 48e2830
updated mcp backend resource configs used in tests
dmitri-d 4340373
moar tests
dmitri-d be91d1d
make linter happy
dmitri-d File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| package agentjwksstore | ||
|
|
||
| import ( | ||
| "context" | ||
| "math" | ||
| "time" | ||
|
|
||
| "golang.org/x/time/rate" | ||
| "istio.io/istio/pkg/kube/controllers" | ||
| "istio.io/istio/pkg/kube/kclient" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/client-go/tools/cache" | ||
| "k8s.io/client-go/util/workqueue" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| "github.com/kgateway-dev/kgateway/v2/internal/kgateway/jwks" | ||
| "github.com/kgateway-dev/kgateway/v2/pkg/apiclient" | ||
| "github.com/kgateway-dev/kgateway/v2/pkg/logging" | ||
| ) | ||
|
|
||
| var cmLogger = logging.New("jwks_store_config_map_controller") | ||
|
|
||
| const JwksStoreConfigMapName = "jwks-store" | ||
|
|
||
| type JwksStoreConfigMapsController struct { | ||
| apiClient apiclient.Client | ||
| cmClient kclient.Client[*corev1.ConfigMap] | ||
| eventQueue controllers.Queue | ||
| jwksUpdates chan map[string]string | ||
| jwksStore *jwks.JwksStore | ||
| deploymentNamespace string | ||
| waitForSync []cache.InformerSynced | ||
| } | ||
|
|
||
| var ( | ||
| rateLimiter = workqueue.NewTypedMaxOfRateLimiter( | ||
| workqueue.NewTypedItemExponentialFailureRateLimiter[any](500*time.Millisecond, 10*time.Second), | ||
| // 10 qps, 100 bucket size. This is only for retry speed and its only the overall factor (not per item) | ||
| &workqueue.TypedBucketRateLimiter[any]{Limiter: rate.NewLimiter(rate.Limit(10), 100)}, | ||
| ) | ||
| ) | ||
|
|
||
| func NewJWKSStoreConfigMapsController(apiClient apiclient.Client, deploymentNamespace string, jwksStore *jwks.JwksStore) *JwksStoreConfigMapsController { | ||
| cmLogger.Info("creating jwks store ConfigMap controller") | ||
| return &JwksStoreConfigMapsController{ | ||
| apiClient: apiClient, | ||
| deploymentNamespace: deploymentNamespace, | ||
| jwksStore: jwksStore, | ||
| } | ||
| } | ||
|
|
||
| func (jcm *JwksStoreConfigMapsController) Init(ctx context.Context) { | ||
| jcm.cmClient = kclient.NewFiltered[*corev1.ConfigMap](jcm.apiClient, | ||
| kclient.Filter{ | ||
| ObjectFilter: jcm.apiClient.ObjectFilter(), | ||
| Namespace: jcm.deploymentNamespace, | ||
| LabelSelector: jwks.JwksStoreLabelString}) | ||
|
|
||
| jcm.waitForSync = []cache.InformerSynced{ | ||
| jcm.cmClient.HasSynced, | ||
| } | ||
|
|
||
| jcm.jwksUpdates = jcm.jwksStore.SubscribeToUpdates() | ||
| jcm.eventQueue = controllers.NewQueue("JwksStoreController", controllers.WithReconciler(jcm.Reconcile), controllers.WithMaxAttempts(math.MaxInt), controllers.WithRateLimiter(rateLimiter)) | ||
dmitri-d marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| func (jcm *JwksStoreConfigMapsController) Start(ctx context.Context) error { | ||
| cmLogger.Info("waiting for cache to sync") | ||
| jcm.apiClient.Core().WaitForCacheSync( | ||
| "kube jwks store ConfigMap syncer", | ||
| ctx.Done(), | ||
| jcm.waitForSync..., | ||
| ) | ||
|
|
||
| cmLogger.Info("starting jwks store ConfigMap controller") | ||
| jcm.cmClient.AddEventHandler( | ||
| controllers.FromEventHandler( | ||
| func(o controllers.Event) { | ||
| jcm.eventQueue.AddObject(o.Latest()) | ||
| })) | ||
|
|
||
| go func() { | ||
| for { | ||
| select { | ||
| case u := <-jcm.jwksUpdates: | ||
| for uri := range u { | ||
| jcm.eventQueue.AddObject(jcm.newJwksStoreConfigMap(jwks.JwksConfigMapName(uri))) | ||
| } | ||
| case <-ctx.Done(): | ||
| return | ||
| } | ||
| } | ||
| }() | ||
| go jcm.eventQueue.Run(ctx.Done()) | ||
|
|
||
| <-ctx.Done() | ||
| return nil | ||
| } | ||
|
|
||
| func (jcm *JwksStoreConfigMapsController) Reconcile(req types.NamespacedName) error { | ||
| cmLogger.Debug("syncing jwks store to ConfigMap(s)") | ||
| ctx := context.Background() | ||
|
|
||
| uri, storedJwks, ok := jcm.jwksStore.JwksByConfigMapName(req.Name) | ||
| if !ok { | ||
| cmLogger.Debug("deleting ConfigMap", "name", req.Name) | ||
| return client.IgnoreNotFound(jcm.apiClient.Kube().CoreV1().ConfigMaps(req.Namespace).Delete(ctx, req.Name, metav1.DeleteOptions{})) | ||
| } | ||
|
|
||
| existingCm := jcm.cmClient.Get(req.Name, req.Namespace) | ||
| if existingCm == nil { | ||
| newCm := jcm.newJwksStoreConfigMap(jwks.JwksConfigMapName(uri)) | ||
| if err := jwks.SetJwksInConfigMap(newCm, uri, storedJwks); err != nil { | ||
| cmLogger.Error("error updating ConfigMap", "error", err) | ||
| return err // no retries? | ||
| } | ||
|
|
||
| _, err := jcm.apiClient.Kube().CoreV1().ConfigMaps(req.Namespace).Create(ctx, newCm, metav1.CreateOptions{}) | ||
| if err != nil { | ||
| cmLogger.Error("error creating ConfigMap", "error", err) | ||
| return err | ||
| } | ||
| } else { | ||
| if err := jwks.SetJwksInConfigMap(existingCm, uri, storedJwks); err != nil { | ||
| cmLogger.Error("error updating ConfigMap", "error", err) | ||
| return err // no retries? | ||
| } | ||
| _, err := jcm.apiClient.Kube().CoreV1().ConfigMaps(req.Namespace).Update(ctx, existingCm, metav1.UpdateOptions{}) | ||
| if err != nil { | ||
| cmLogger.Error("error updating jwks ConfigMap", "error", err) | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // runs on the leader only | ||
| func (jcm *JwksStoreConfigMapsController) NeedLeaderElection() bool { | ||
| return true | ||
| } | ||
|
|
||
| func (jcm *JwksStoreConfigMapsController) newJwksStoreConfigMap(name string) *corev1.ConfigMap { | ||
| return &corev1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: name, | ||
| Namespace: jcm.deploymentNamespace, | ||
| Labels: jwks.JwksStoreLabelMap, | ||
| }, | ||
| Data: make(map[string]string), | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.