Repository navigation
feat: Allow users to supply a mapping of hosts to varying audience and scope values. - #79
Conversation
|
@usize thanks for the PR. Will take a look. We need to coordinate this work with a blog that we're currently writing to make sure it doesn't break anything. |
|
Understandable! I updated the test description in the PR description above to reflect a few small quality of life improvements to the setup of the multi-target demo and to include logs from authbridge showing the host matching executing. I'll move this out of draft mode later today. |
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
|
|
||
| "github.com/huang195/auth-proxy/go-processor/internal/resolver" |
There was a problem hiding this comment.
I would prefer this to become "github.com/kagenti/kagenti-extensions/AuthBridge/AuthProxy/go-processor/internal/resolver". This project was copied over from my personal repo, and there were some leftover things that weren't fixed. This means we need to modify go.mod to have module github.com/kagenti/kagenti-extensions/AuthBridge/AuthProxy
|
|
||
| Expected output: | ||
| ``` | ||
| [Routes] Host "target-alpha-service" matched pattern "target-alpha-service" |
There was a problem hiding this comment.
Do you mean [Resolver] instead of [Routes] here?
There was a problem hiding this comment.
Another leftover from an earlier implementation.
| current = mapper.get("config", {}).get("included.custom.audience", "<none>") | ||
| print(f" [WARN] Mapper points to '{current}', expected '{audience}'") | ||
| if self._prompt(f" Update mapper to '{audience}'?"): | ||
| self._update_mapper_audience(scope["id"], mapper["id"], audience) |
There was a problem hiding this comment.
the function _update_mapper_audience doesn't seem to be implemented concretely. why do we need this here?
There was a problem hiding this comment.
It's a leftover from a prior implementation that I removed. Will get rid of it.
| target_audience: "target-gamma" | ||
| token_scopes: "openid target-gamma-aud" | ||
|
|
||
| # Also match short service names (within cluster) |
There was a problem hiding this comment.
is there any reason to define short name in addition to the FQDN declared above?
There was a problem hiding this comment.
It doesn't have to be so. I think this was just a case of my code assistant getting overzealous with comments based on our discussion.
| route: | ||
| cluster: original_destination | ||
| http_filters: | ||
| # Lua filter to inject token exchange credentials as headers |
There was a problem hiding this comment.
we recently removed the lua code to inject environment vars into request headers because both envoy and ext proc run in the same process namespace, so ext proc could get to the same environment vars.
There was a problem hiding this comment.
@usize this lua filter is still present here. this should be removed
| route: | ||
| cluster: original_destination | ||
| http_filters: | ||
| # Lua filter to inject token exchange credentials as headers |
There was a problem hiding this comment.
@usize this lua filter is still present here. this should be removed
| route: | ||
| cluster: original_destination | ||
| http_filters: | ||
| # Lua filter to inject token exchange credentials as headers |
There was a problem hiding this comment.
Same as above to remove the lua filter.
| # Order matters - first match wins. | ||
|
|
||
| # Target Alpha | ||
| - host: "target-alpha-service.authbridge.svc.cluster.local" |
There was a problem hiding this comment.
run-demo-commands.sh calls targets by short name:
curl -s -H "Authorization: Bearer $TOKEN" http://target-alpha-service:8081/test. If you're defining these without wildcard, would they still match?
In routes.yaml, you are using - host: "target-alpha-service*", which would work.
| # Order matters - first match wins. | ||
|
|
||
| # Target Alpha | ||
| - host: "target-alpha-service.authbridge.svc.cluster.local" |
There was a problem hiding this comment.
Same comment as above about FQDN.
| authorized | ||
|
|
||
| === AuthBridge Token Exchange Logs === | ||
| [Routes] Host "target-alpha-service" matched pattern "target-alpha-service*" |
|
Sorry about the dangling issues. Thanks for catching them. I the multi-target and single-target demos are both fixed up and working. And I cleaned up the cruft that was leftover from when I had Claude clean up the merge conflicts. |
There was a problem hiding this comment.
Pull request overview
Adds route/host-based token exchange configuration so AuthBridge can exchange tokens with different audiences/scopes depending on the destination service, plus tooling and demos to support Keycloak reconciliation.
Changes:
- Introduces a Go
TargetResolver+ YAML-backedStaticResolverto resolve per-host token exchange settings in the ext-proc. - Adds
keycloak_sync.pyto reconcileroutes.yamltargets (clients/scopes/audience mappers) with Keycloak. - Expands demos/manifests/docs for single-target, multi-target, and webhook-based setups.
Reviewed changes
Copilot reviewed 20 out of 25 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| AuthBridge/requirements.txt | Adds PyYAML dependency for YAML route parsing in tooling. |
| AuthBridge/keycloak_sync.py | New script to reconcile routes config with Keycloak (clients/scopes/mappers). |
| AuthBridge/demos/single-target/setup_keycloak.py | Fixes demo apply paths to new directory structure. |
| AuthBridge/demos/single-target/k8s/configmaps-webhook.yaml | Adds webhook demo ConfigMaps (env + envoy + spiffe-helper). |
| AuthBridge/demos/single-target/k8s/authbridge-deployment.yaml | Adds routes ConfigMap mount + env for route-based config (SPIFFE). |
| AuthBridge/demos/single-target/k8s/authbridge-deployment-no-spiffe.yaml | Adds routes ConfigMap mount + env for route-based config (no SPIFFE). |
| AuthBridge/demos/single-target/k8s/auth-target-deployment-webhook.yaml | Adds target deployment/service for webhook demo. |
| AuthBridge/demos/single-target/k8s/agent-deployment-webhook.yaml | Adds agent deployment/service for webhook demo (SPIFFE enabled). |
| AuthBridge/demos/single-target/k8s/agent-deployment-webhook-no-spiffe.yaml | Adds agent deployment/service for webhook demo (SPIFFE disabled). |
| AuthBridge/demos/single-target/demo.md | Updates demo commands to correct manifest paths. |
| AuthBridge/demos/multi-target/teardown-demo.sh | Adds teardown script for demo k8s resources + optional realm deletion. |
| AuthBridge/demos/multi-target/run-demo-commands.sh | Adds script to run multi-target demo commands and inspect logs. |
| AuthBridge/demos/multi-target/routes.yaml | Adds demo routes mapping hosts to audiences/scopes. |
| AuthBridge/demos/multi-target/k8s/targets.yaml | Adds 3 target services (alpha/beta/gamma) validating different audiences. |
| AuthBridge/demos/multi-target/k8s/authbridge-deployment.yaml | Adds full multi-target demo deployment with routes ConfigMap (SPIFFE). |
| AuthBridge/demos/multi-target/k8s/authbridge-deployment-no-spiffe.yaml | Adds full multi-target demo deployment with routes ConfigMap (no SPIFFE). |
| AuthBridge/demos/multi-target/demo.md | New multi-target demo guide and workflow. |
| AuthBridge/README.md | Updates top-level docs to point to both demos + route-based config + sync tool. |
| AuthBridge/AuthProxy/go.sum | Adds dependency checksums for new resolver deps. |
| AuthBridge/AuthProxy/go.mod | Updates module path and adds resolver dependencies (glob + yaml). |
| AuthBridge/AuthProxy/go-processor/main.go | Integrates resolver into outbound flow + loads routes config at startup. |
| AuthBridge/AuthProxy/go-processor/internal/resolver/static_test.go | Adds unit tests for YAML-backed resolver behavior (glob/ordering/ports/IPv6). |
| AuthBridge/AuthProxy/go-processor/internal/resolver/static.go | Implements StaticResolver with glob host matching + YAML parsing. |
| AuthBridge/AuthProxy/go-processor/internal/resolver/resolver.go | Defines TargetResolver and TargetConfig primitives. |
| AuthBridge/AuthProxy/Makefile | Adds unit-test target for Go resolver tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if self._prompt(f" Add audience mapper for '{audience}'?"): | ||
| self._add_audience_mapper(scope["id"], scope_name, audience) | ||
| else: | ||
| print(f" [OK] Audience mapper correctly configured") |
There was a problem hiding this comment.
_find_audience_mapper only checks that an oidc-audience-mapper exists, but it does not verify that it is configured for the expected audience. This can incorrectly report "Audience mapper correctly configured" when the mapper targets a different audience; consider validating mapper config (e.g., included.custom.audience) against the audience being reconciled and treating mismatches as needing update.
| print(f" [OK] Audience mapper correctly configured") | |
| # Verify that the existing mapper targets the expected audience | |
| mapper_config = mapper.get("config", {}) or {} | |
| mapper_audience = mapper_config.get("included.custom.audience") | |
| if mapper_audience == audience: | |
| print(f" [OK] Audience mapper correctly configured") | |
| else: | |
| print( | |
| f" [WARN] Audience mapper for scope '{scope_name}' is configured " | |
| f"for audience '{mapper_audience}', expected '{audience}'" | |
| ) | |
| if self._prompt(f" Update audience mapper to '{audience}'?"): | |
| self._add_audience_mapper(scope["id"], scope_name, audience) | |
| else: | |
| print(" --> Skipped") | |
| self.result.scopes_skipped += 1 |
| if not route.get("target_audience"): | ||
| continue # Skip routes without audience (e.g., passthrough-only) | ||
|
|
||
| scopes = route.get("token_scopes", "").split() | ||
| targets.append(RouteTarget( | ||
| host=route.get("host", ""), | ||
| audience=route["target_audience"], | ||
| scopes=scopes, | ||
| passthrough=route.get("passthrough", False), |
There was a problem hiding this comment.
load_routes() skips any route without target_audience, which means passthrough-only entries (host + passthrough: true) are ignored entirely. At the same time, RouteTarget/reconcile() has a passthrough branch, which becomes effectively dead code; consider either including passthrough-only routes (and keying display on host) or removing passthrough handling from this script to avoid confusion.
| if not route.get("target_audience"): | |
| continue # Skip routes without audience (e.g., passthrough-only) | |
| scopes = route.get("token_scopes", "").split() | |
| targets.append(RouteTarget( | |
| host=route.get("host", ""), | |
| audience=route["target_audience"], | |
| scopes=scopes, | |
| passthrough=route.get("passthrough", False), | |
| audience = route.get("target_audience") | |
| passthrough = route.get("passthrough", False) | |
| # Include routes with an audience as normal, and also include | |
| # passthrough-only routes (no audience but passthrough enabled). | |
| if not audience and not passthrough: | |
| continue # Skip routes that are neither targeted nor passthrough | |
| scopes = route.get("token_scopes", "").split() if audience else [] | |
| targets.append(RouteTarget( | |
| host=route.get("host", ""), | |
| audience=audience or "", | |
| scopes=scopes, | |
| passthrough=passthrough, |
There was a problem hiding this comment.
The right tac here is to look at removing passthrough altogether. I'll revisit it.
| secret = self.kc.get_client_secrets(uuid).get("value") | ||
| if secret: | ||
| print(f" --> Client secret: {secret}") | ||
| except Exception: |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
| except Exception: | |
| except Exception: | |
| # Best-effort retrieval: failure to fetch the client secret | |
| # is non-fatal and should not block client creation. |
| for mapper in mappers: | ||
| if mapper.get("protocolMapper") == "oidc-audience-mapper": | ||
| return mapper | ||
| except Exception: |
There was a problem hiding this comment.
'except' clause does nothing but pass and there is no explanatory comment.
There was a problem hiding this comment.
Should log the exception in the handler.
Routes are determined via the host header. Globs are supported e.g., *.foo.com Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
…d another time. Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
…the multi-target demo required it to be run prior to other manifests or it would fail. Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
…ployment issues due to missing keycloak realms. Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
These are superfluous and only add noise to the example. Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
- Remove Lua filter from envoy config (ext-proc shares process namespace) - Change [Routes] to [Resolver] in demo.md expected output - Use wildcard patterns for route matching (target-alpha-service*) Co-Authored-By: Claude Opus 4.5 <[email protected]> Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Signed-off-by: usize <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Morgan Foster <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Morgan Foster <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Morgan Foster <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Morgan Foster <[email protected]>
Co-authored-by: Copilot <[email protected]> Signed-off-by: Morgan Foster <[email protected]>
…ffe.yaml Co-authored-by: Copilot <[email protected]> Signed-off-by: Morgan Foster <[email protected]>
- Fix demo.md: glob patterns in examples and expected output used single `*` but actual routes.yaml uses `**` (double glob for multi-level match) - Fix run-demo-commands.sh: move shebang to line 1 so the OS recognizes the script as bash when executed directly Signed-off-by: Mariusz Sabath <[email protected]>
Description
Because a given client may communicate with a number of services (targets) it is necessary for token exchange to be configured such that scopes and audiences are returned matching the target in question. The best way to achieve this is by mapping hosts (indicative of particular targets) to audiences and scopes.
Here we introduce two new primitives:
TargetResolverandTargetConfigwhich achieve this.In particular, we achieve it by supplying a YAML config file which may be loaded by the authbridge at startup.
In order to keep IDPs, like KeyCloak, in sync with this configured mapping we have supplied a script which locates any
client ids,scopesandaudience mappingsmissing from the supplied authbridge config, and offers to create them.This is not a perfect solution, however, work on solving this problem at the IDP level is underway in KeyCloak via keycloak/keycloak#36870
RFC 8693 specifies an optional
resourceparameter which abstractly serves the purpose of signaling a relationship between a URI and audience.However, for the time being, this config based approach will be the most durable across providers.
Fixes: #69
Type of Change
How Has This Been Tested?
Test Configuration:
Checklist