Skip to content

feat: Allow route based TARGET_AUDIENCE configuration #69

Closed

Description

@usize

Problem Statement *

Right now, only a single target audience mapping is possible via a config that looks like this, which is baked into the authbridge at startup.

  apiVersion: v1
  kind: Secret
  metadata:
    name: auth-proxy-config
  stringData:
    TARGET_AUDIENCE: "auth-target"    # <-- This is the target audience
    TARGET_SCOPES: "openid auth-target-aud"
    TOKEN_URL: "http://keycloak.keycloak.svc.cluster.local/realms/demo/protocol/openid-connect/token"

We should allow for route based configuration, to support token exchange across varying services.

This approach is still limited in that it cannot support downscoping. But it does give us more surface area to build prototypes with for now.

This should also support a passthough option, so that users can disable token exchange.

Proposed Solution *

Configuration via ConfigMap, e.g.,

kind: ConfigMap
metadata:
  name: authbridge-routes
data:
  routes.yaml: |
    - host: "github.mcp.local"
      target_audience: "https://api.github.com"
      token_scopes: ...
      token_url: ....
    - host: "slack.mcp.local"  
      target_audience: "https://slack.com/api"
      token_scopes: ....
      token_url: ....
    - host: "*.internal.svc.cluster.local"
      passthrough: true

Alternatives Considered

Header based configuration. Where headers carry dynamic config information. This may still be a good followup to allow for overrides and testing. It does break the 'transparent' nature of the AuthBridge however, so is not a priority.

Additional Context

In the future, integration with a service capable of downscoping tokens as described in RFC 8693 will remain an ideal longterm outcome. However, this approach could remain indefinitely as a fallback for simplified architectures.

Priority

None

Contribution

  • I am willing to submit a pull request for this feature

Activity

  1. usize commented on Jan 14, 2026

    @usize
    ContributorAuthor

    Open questions:

    • What is our behavior when no route matches?
    • What is our match behavior: longest wins?
    • Do we match based on the Host field in the header?
  2. huang195 commented on Jan 21, 2026

    @huang195
    Member

    @usize this is a crucial limitation that we currently have, and there isn't any specific solution that seems to be better than others. Ultimately, we want to minimize user inputs to improve user experience while guaranteeing fine-grained security. Will continue on this issue once we have some concrete proposals.

    To answer your questions above:

    What is our behavior when no route matches?

    According to Envoy's default behavior, it returns 404. However, we can add a "catch-all" route, so the request gets routed so the app can log that error.

    What is our match behavior: longest wins?

    Route order matters to Envoy, and the first one that matches win.

    Do we match based on the Host field in the header?

    Using Hostname field in the HTTP header is definitely a possible solution.

  3. self-assigned this
    on Jan 22, 2026
  4. huang195 commented on Jan 23, 2026

    @huang195
    Member

    One alternative to using configmap to hold the mapping information is to store this information in the IDP itself. Since we need to do token exchange to get the proper access token for the next hop, information about audience and scope should be stored in some form somewhere. In the case of IDP being Keycloak, we can use audience mapper to find the appropriate audience from a Host. There should also be similar ways to map Host to scopes.

    If we assume something/someone is configuring IDP appropriately to assign identities and set authn/authz, we should be able to find this information without having to maintain a separate configmap and having to keep things in sync in case there are changes in the environment.

  5. usize commented on Jan 24, 2026

    @usize
    ContributorAuthor

    I experimented with having a mapping on the AuthBridge side. It's true that right away it runs into issues of config sprawl between AuthBridge and Keycloak. experiment branch

    I could imagine us using attributes to store information about host -> client mappings.

          clients:
            - clientId: auth-target
              attributes:
                hostname: "auth-target-service.authbridge.svc.cluster.local"
                token_scopes: "openid auth-target-aud"
    

    The downside is that this requires admin credentials to do the attribute lookup at runtime. It would ensure that our mapping is always in sync with the KC configuration, but it's also pretty clunky and introduces additional round trips per request / requires us to add some sort of cache.

    --

    Configuring the mapping based on a resource parameter

    Would be the ideal solution.

    There is support for this being discussed and worked on:

    keycloak/keycloak#36870

    keycloak/keycloak#35711

    It seems we really just need an interim solution.

    My proposal:

    We wrap the mapping logic up in a AudienceResolver abstraction.

    For now, keep the mapping local and use a simple python script to handle syncing, similar to how we setup keycloak for the demo.

    Then we can use the resolver to pivot to a different solution, or to easily cleanup once we have real resource parameter support.

    This also has the advantage of letting us experiment with other IDPs that have different levels of support for RFC 8693.

    For the scopes I think we can derive them from the subject's roles/permissions?

    What do you think?

  6. huang195 commented on Jan 26, 2026

    @huang195
    Member

    Sounds good to me. Let's have an interim solution based on local mapping, and then iterate on creating better solutions once upstream Keycloak capabilities are available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions