upstreamfilter

package
v0.53.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package upstreamfilter provides UpstreamFilter implementations for the embedded authorization server. Filters narrow the multi-upstream authorization chain based on the first upstream's resolved identity, so users only walk the upstream providers they are entitled to.

This package implements the handlers.UpstreamFilter contract defined in pkg/authserver/server/handlers. See that interface's documentation for the runtime lifecycle: single invocation per authorization on the first leg's callback, principal is read-only, fail-closed on nil/absent claims.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GroupBasedFilter

type GroupBasedFilter struct {
	// contains filtered or unexported fields
}

GroupBasedFilter implements handlers.UpstreamFilter by matching the principal's group claim against configured rules and returning the union of the matching rules' upstream provider sets. See package documentation and GroupBasedFilterConfig for semantics.

func NewGroupBasedFilter

func NewGroupBasedFilter(cfg GroupBasedFilterConfig, configuredUpstreams []string) (*GroupBasedFilter, error)

NewGroupBasedFilter constructs and validates a GroupBasedFilter.

configuredUpstreams is the full ordered list of upstream provider names declared on the auth server, including the mandatory first upstream at index 0. It is required at construction time to validate that every referenced provider exists and that no rule or default references the mandatory first upstream (which is always included and cannot be filtered).

It returns an error for any of: fewer than two configured upstreams; no rules; empty or duplicate group values within a rule; empty or duplicate upstream references within a rule; unknown upstream references; references to the mandatory first upstream; unknown or first-upstream references in DefaultUpstreams.

func (*GroupBasedFilter) FilterUpstreams

func (f *GroupBasedFilter) FilterUpstreams(
	_ context.Context,
	principal auth.PrincipalInfo,
	_ []string,
) ([]string, error)

FilterUpstreams implements handlers.UpstreamFilter.

It reads principal.Claims[filter.claim], decodes it as a []string via the shared claims helper, and returns the union of every matching rule's UpstreamProviders. The claim MUST be present and MUST be a JSON string array — a missing, nil, non-array, or mixed-type claim value fails the authorization per the filter contract's fail-closed guarantee for security-relevant filters.

A valid empty array or a valid array with no matching rule falls back to the configured DefaultUpstreams. Duplicate names across matching rules and defaults are deduplicated in the returned slice; the handler layer preserves configured order and drops any name that is not a non-first configured upstream.

principal (including its Claims map) is treated as read-only. Claim values are not logged.

The configured argument is unused: the constructor validated every rule and default reference against the full configured upstream list, so runtime reconciliation of the returned set against the non-first upstreams is redundant with the handler layer's own drop-unknown behavior.

type GroupBasedFilterConfig

type GroupBasedFilterConfig struct {
	// Claim is the exact, top-level JWT/OIDC claim name to read group
	// membership from. Defaults to "groups" when empty. The claim value MUST be
	// a JSON array of strings; other shapes (missing, non-array, mixed types)
	// fail the authorization. Nested claims (e.g. Keycloak's realm_access.roles)
	// must be flattened by the identity provider — nested paths are not
	// supported in this implementation.
	//
	// The value is read from upstream.Identity.Claims as the first upstream
	// resolves it: an OIDC upstream fills that map from the validated ID
	// token, a pure OAuth2 upstream from the userinfo response. The
	// identityFromToken and synthesized-identity paths leave it empty, and
	// groups carried only in an access token never reach it. A missing claim
	// fails the authorization — DefaultUpstreams covers a valid-but-empty
	// claim and unmatched groups, not an absent one.
	Claim string `json:"claim,omitempty" yaml:"claim,omitempty"`

	// Rules assigns groups to upstream provider subsets. A principal matches a
	// rule if any of the principal's group values appears in the rule's Groups
	// list (any-of / OR semantics). Multiple matching rules are combined by
	// union: the effective upstream chain contains every UpstreamProviders
	// value from every matching rule, deduplicated.
	Rules []GroupRule `json:"rules" yaml:"rules"`

	// DefaultUpstreams is used when the claim is a valid empty array or when no
	// rule matches. When empty or omitted, no optional upstreams are added —
	// the mandatory first upstream remains but the authorization walks no
	// further.
	DefaultUpstreams []string `json:"defaultUpstreams,omitempty" yaml:"defaultUpstreams,omitempty"`
}

GroupBasedFilterConfig is the serializable configuration for the group-based upstream filter. It is stored in RunConfig and delivered to the vMCP pod via the auth-server config ConfigMap.

The nested keys are camelCase where RunConfig's own fields are snake_case. They match the v1beta1 CRD spelling (spec.authServerConfig.upstreamProviders), which keeps a rule spelled the same in the CR and in the generated YAML. Renaming them would also change the published OpenAPI model and Go SDK.

type GroupRule

type GroupRule struct {
	// Groups is the set of principal group names this rule matches. Matching
	// is case-sensitive and exact. Empty and duplicate values are rejected at
	// configuration validation time.
	Groups []string `json:"groups" yaml:"groups"`

	// UpstreamProviders lists the non-first upstream provider names to include
	// in the chain when this rule matches. All names must reference a
	// configured non-first upstream. Empty and duplicate values, references to
	// the mandatory first upstream, and references to undeclared upstreams are
	// rejected at configuration validation time.
	UpstreamProviders []string `json:"upstreamProviders" yaml:"upstreamProviders"`
}

GroupRule pairs a set of principal group names with the set of upstream provider names matching principals are entitled to walk.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL