Skip to content

Add a group-aware UpstreamFilter implementation for the embedded auth server #6675

Closed

Description

@hellouz818

Problem

In a multi-upstream VirtualMCPServer, without a custom UpstreamFilter, users walk the full upstream authorization chain regardless of their identity or group membership.

A user who does not have an account on one of the upstream providers is prompted for OAuth login, which fails and blocks the entire authorization flow — even though they only need credentials from a subset of upstream providers for the backends they are entitled to use.

This is not just a UX issue but an authentication failure: a single upstream that is unavailable to a particular principal can prevent the user from accessing other backends they are authorized to use.

Background

#5724 / #5725 added the UpstreamFilter interface and the callback handler hook that consults it after the first upstream resolves.

The integration is complete — computeChain calls FilterUpstreams when a filter is present — but no concrete implementation ships with ToolHive and no CRD surface exposes the configuration.

Proposal

Provide a built-in UpstreamFilter implementation that narrows the upstream chain based on claims from the first-leg principal, initially supporting group membership.

Operators could configure a mapping from identity groups to upstream subsets, so that users in different groups walk different authorization chains.

This would also require a CRD field on VirtualMCPServer (e.g. authServerConfig.upstreamFilter) to configure the filter without requiring a custom Go build.

The exact configuration shape is open for discussion.

This proposal is intentionally limited to authentication-chain selection. It does not replace backend or tool authorization; backend-scoped Cedar authorization remains responsible for determining which backend capabilities the principal may access.

Given the OSS / Enterprise boundary described in #5383, I’d also like to confirm whether a group-aware UpstreamFilter exposed through the VirtualMCPServer CRD would fall under the Connector Gateway / Enterprise boundary as well.

Related

Activity

  1. added
    needs-triage
    on Sep 17, 2026
  2. hellouz818 commented on Sep 17, 2026

    @hellouz818
    ContributorAuthor

    I'd be happy to work on this if the approach makes sense. Happy to adjust the implementation based on maintainer feedback.

  3. removed
    needs-triage
    on Sep 22, 2026
  4. self-assigned this
    on Sep 22, 2026
  5. jhrozek commented on Sep 22, 2026

    @jhrozek
    Contributor

    I apologize for the late reply. I think the request makes sense. I'll post a high-level plan that I produced in an AI co-design session - let me know if this tracks with what you were thinking. Also let us know if this is something you'd like to work on or if you'd like some help/co-develop this feature with us.

  6. jhrozek commented on Sep 22, 2026

    @jhrozek
    Contributor

    Proposed implementation direction

    The existing UpstreamFilter hook already provides the runtime enforcement we need. The missing work is a built-in group-aware implementation plus a VirtualMCPServer API that can configure it without custom Go code.

    The implementation should remain split into two layers:

    ToolHive auth-server capability
            ↓
    VirtualMCPServer Kubernetes API
    

    The auth-server implementation should not know about Kubernetes. The operator should translate a vMCP-only CRD field into serializable auth-server configuration.

    Proposed API

    Keep the new field on VirtualMCPServerSpec, beside authServerConfig. EmbeddedAuthServerConfig is shared by other CRDs, while multi-upstream filtering is specific to vMCP.

    spec:
      authServerConfig:
        upstreamProviders:
          - name: corporate
            # ...
          - name: github
            # ...
          - name: gitlab
            # ...
    
      authServerUpstreamFilter:
        claim: groups
        rules:
          - groups: [github-users]
            upstreamProviders: [github]
          - groups: [gitlab-users]
            upstreamProviders: [gitlab]
          - groups: [platform-admins]
            upstreamProviders: [github, gitlab]
        defaultUpstreams: []

    Proposed semantics:

    • claim is an exact top-level claim name, defaulting to groups.
    • The claim must be a JSON array containing only strings.
    • Matching is exact and case-sensitive.
    • Multiple matching rules are combined using union semantics.
    • defaultUpstreams is used for a valid empty claim or when no rule matches.
    • Omitting defaultUpstreams means no optional upstreams; the mandatory first provider remains.
    • Missing, unavailable, or malformed claims fail the authorization transaction.
    • The filter can only narrow the chain. It cannot remove the first provider, add unknown providers, or reorder providers.
    • This controls which credentials ToolHive acquires. It does not authorize access to backends or tools; Cedar or another authorization mechanism remains responsible for that.

    The configurable claim name supports mappings such as groups, roles, cognito:groups, and URI-shaped custom claims. Provider-native nested claims should be mapped by the identity provider into a top-level string array for the initial implementation.

    Implementation steps

    1. Extract reusable string-array claim decoding

    ToolHive already handles []string and JSON-decoded []any claims in the Cedar authorizer. Extract the low-level decoding into a neutral helper rather than duplicating it.

    The helper should:

    • accept []string and []any containing only strings;
    • clone caller-owned slices;
    • distinguish an unsupported type from a recognized empty array;
    • report non-string array elements.

    Cedar should adopt the helper without changing its existing behavior. The new upstream filter should use it strictly and reject malformed arrays.

    Deliverables:

    • shared claim-array helper;
    • table-driven tests covering both Go representations, empty and mixed arrays, unsupported types, and input immutability;
    • Cedar refactor with regression tests proving no authorization behavior changed.

    2. Implement the built-in group filter

    Add a focused package such as pkg/authserver/upstreamfilter.

    The constructor should validate:

    • the claim name and rules;
    • empty or duplicate group/provider values;
    • unknown provider references;
    • references to the mandatory first provider;
    • default provider references;
    • the requirement for at least two configured upstreams.

    At runtime, the filter should:

    1. Read the exact configured claim.
    2. Decode it using the shared helper.
    3. Union upstreams from matching rules.
    4. Use defaultUpstreams for a valid empty or unmatched claim.
    5. Return errors for missing or malformed claims.
    6. Avoid mutating or logging claim values.

    The existing callback, chain persistence, and computeChain logic should remain unchanged.

    Deliverables:

    • concrete implementation of handlers.UpstreamFilter;
    • compile-time interface assertion;
    • unit tests for matching, unions, defaults, invalid claims, validation, ordering, and immutability.

    3. Add serializable auth-server configuration

    Add an optional group-filter field to authserver.RunConfig.

    RunConfig.Validate() must enforce the same static invariants so direct auth-server consumers also fail at startup on invalid configuration.

    Update the embedded-auth runner to construct the filter and assign it to authserver.Config.UpstreamFilter. When the field is absent, UpstreamFilter remains nil and the current full-chain behavior is preserved.

    Deliverables:

    • serializable run-config types;
    • startup validation;
    • runner construction and wiring;
    • JSON/YAML round-trip tests;
    • integration coverage proving the configured filter reaches a real callback flow.

    4. Add the VirtualMCPServer API and conversion

    Add vMCP-only API types to VirtualMCPServerSpec.

    Use OpenAPI markers for structural constraints and CEL for cross-field validation:

    • the filter requires authServerConfig;
    • at least two upstream providers are required;
    • every referenced provider must exist;
    • the first provider cannot be referenced.

    Repeat security-critical checks during reconciliation because older stored resources and fake clients can bypass admission.

    Invalid configuration should set AuthServerConfigValidated=False with ObservedGeneration, return no retryable error, and recover to True after the spec is corrected.

    Extend the vMCP converter after the shared BuildAuthServerRunConfig call, keeping that shared converter free of vMCP-only CRD concerns.

    Deliverables:

    • CRD types and validation;
    • CRD-to-RunConfig conversion;
    • terminal condition handling and recovery;
    • generated deepcopy and CRD artifacts;
    • API, converter, reconciliation, and admission tests.

    5. Prove the user-visible behavior and document it

    Add one functional end-to-end flow:

    corporate IdP returns github-users
    → GitHub upstream is visited
    → GitLab upstream is skipped
    → authorization completes
    

    Document:

    • the configuration and matching semantics;
    • examples for common identity-provider claim names;
    • the requirement to map nested or provider-specific claims into a top-level string array;
    • behavior when a provider omits the claim because of token limits or configuration;
    • the distinction between upstream selection and backend authorization.

    Deliverables:

    • functional operator E2E coverage;
    • complete vMCP YAML example;
    • updates to the vMCP architecture and operator API documentation;
    • regenerated manifests and CRD reference documentation.

    Compatibility

    This adds a new implementation of the existing UpstreamFilter interface. It should not change the interface, its nil behavior, or the existing handler semantics.

    When the new configuration is absent, ToolHive continues walking the complete upstream chain exactly as it does today.

    The implementation should not introduce generic filter composition or precedence rules. The auth-server configuration selects at most one built-in upstream filter.

    Suggested delivery split

    1. Shared claim decoding — helper extraction and Cedar regression protection.
    2. Core group filter — filter, RunConfig, validation, runner wiring, and auth-server tests.
    3. VirtualMCPServer API — CRD, conversion, operator validation, E2E, generated artifacts, and documentation.

    This keeps the auth-server capability independent of Kubernetes while giving vMCP operators the requested declarative configuration.

  7. Sanskarzz commented on Sep 27, 2026

    @Sanskarzz
    Collaborator

    Thanks for the detailed direction, @jhrozek. The separation makes sense to me:

    • The upstream filter decides which provider credentials are acquired after the first identity provider resolves;
    • Cedar remains responsible for deciding which backend tools the principal may access.

    This also fits the model in #6487, where BackendID is trusted authorization metadata rather than something inferred from provider selection.

    One smaller semantics question: for a rule with multiple values such as groups: [engineering, production], should matching use any-group or all-groups semantics?

    @hellouz818, since you already offered to work on this, I don’t want to step on ownership. I’d be happy to help review, create a sub-issue, or test the shared claim-decoding/Cedar regression portion and the interaction with backend-scoped authorization from #6487.

  8. hellouz818 commented on Sep 28, 2026

    @hellouz818
    ContributorAuthor

    Thanks @jhrozek and @Sanskarzz — the proposed API direction and separation make sense to me.

    I’d like to take the lead on implementing this issue, starting with the auth-server filter and then following through the RunConfig and VirtualMCPServer CRD integration. @jhrozek, if that works for you, could you assign the issue to me?

    @Sanskarzz, thanks for offering to help. I’m happy to coordinate on the shared claim-decoding / Cedar regression portion, and later test the interaction with #6487 while keeping backend-scoped authorization separate from provider-selection logic.

    Before I start, I just want to confirm one matching semantic:

    • For a rule like groups: [engineering, production], should a principal match if it has either value (OR), or only if it has both values (AND)?

    One longer-term scope question as well: is the initial implementation intentionally limited to token claims, with external entitlement resolution kept out of scope for v1?

    We have a use case where upstream eligibility is determined outside the token itself, so selecting the effective upstream chain may eventually require an external entitlement lookup after the first identity provider resolves.

    I’m not suggesting adding that to the initial implementation — I just want to make sure the filter/config design leaves room for that kind of extension later without requiring a major redesign.

  9. Sanskarzz commented on Sep 28, 2026

    @Sanskarzz
    Collaborator

    Thanks @hellouz818, that coordination works for me. Once @jhrozek confirms the assignment and delivery split, I’d be happy to take or co-develop the first prerequisite around shared string-array claim decoding and Cedar regression coverage. We can keep that PR independent of the auth-server filter and coordinate its API before the filter work builds on it.

    On the external-entitlement question, my reading is that the proposed v1 is intentionally claim-only. The existing UpstreamFilter Go interface already receives context.Context and PrincipalInfo, so a future implementation could perform an external lookup without changing the handler contract. The declarative RunConfig/CRD shape is where we may eventually need an extension.

    I agree it would be useful for the other maintainers to confirm whether external entitlement resolution is explicitly out of scope for v1, and whether it falls under the Connector Gateway/Enterprise boundary discussed in #5383.

  10. 8 remaining items

  11. hellouz818 commented on Oct 13, 2026

    @hellouz818
    ContributorAuthor

    All three PRs from the suggested delivery split are up: #6738 (shared claim decoder + Cedar) and #6739 (group-based upstream filter) are merged, and #6740 (vMCP CRD surface) is open.

    @jhrozek, could you add me as an assignee on this issue? Happy for you to remain assigned as well if you'd prefer to track it together.

    Thanks for your guidance and reviews throughout!

  12. jhrozek commented on Oct 16, 2026

    @jhrozek
    Contributor

    18. All three PRs from the suggested delivery split are up: #6738 (shared claim decoder + Cedar) and #6739 (group-based upstream filter) are merged, and #6740 (vMCP CRD surface) is open.
    @jhrozek, could you add me as an assignee on this issue? Happy for you to remain assigned as well if you'd prefer to track it together.
    Thanks for your guidance and reviews throughout!

    I'm sorry I completely missed your reply on this PR. I assigned you to the issue.

  13. hellouz818 commented on Nov 2, 2026

    @hellouz818
    ContributorAuthor

    All three PRs (#6738, #6739, #6740) are merged, so I'm closing this. Thanks for the reviews!

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

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions