callerwrite

package
v5.52.25 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package callerwrite implements the shared caller-identity write gate for session-initiated CR mutations (issues #1056, #1069). In Kubernetes mode, spec mutations triggered by MCP sessions must not go through muster's ServiceAccount: the session's dex id_token becomes the bearer of a per-call client, so the apiserver authenticates the real user, Kubernetes RBAC authorizes the write, and the audit log records the true subject. Each CR-owning adapter (MCPServer, Workflow) wraps the Gate into its own typed write surface.

Index

Constants

View Source
const DefaultKubernetesAudience = "dex-k8s-authenticator"

DefaultKubernetesAudience is the audience the local kube-apiserver trusts on dex id_tokens (the dex-k8s-authenticator cross-client audience). Overridable via writesAsCaller.kubernetesAudience in the muster config.

Variables

This section is empty.

Functions

func DescribeWriteAuthError

func DescribeWriteAuthError(err error, verb, kind, resource, name, namespace, editorRole string) string

DescribeWriteAuthError maps apiserver authn/authz failures on caller-identity writes to actionable messages: 403 names the verb, kind, fully-qualified resource, and namespace, and points at the editor role the chart ships; 401 asks for a re-login. Returns "" for every other error so callers fall through to their existing handling.

func ReloginError

func ReloginError(reason string) string

ReloginError is the actionable error for sessions whose token cannot authenticate at the apiserver (missing audience, or rejected outright).

func TokenFromContext

func TokenFromContext(ctx context.Context) string

TokenFromContext returns the session's dex id_token carried on the request context by the OAuth middleware, or "" for unauthenticated transports.

func TokenMissingAudience

func TokenMissingAudience(token, want string) bool

TokenMissingAudience reports whether token is a JWT whose aud claim verifiably lacks want. The payload is decoded without signature verification — the apiserver is the verifier; this precheck only exists to turn a doomed write into an actionable re-login error. Tokens that don't parse as JWTs (e.g. opaque test tokens) are passed through to the apiserver.

Types

type ClientFactory

type ClientFactory func(bearerToken string) (ctrlclient.Client, error)

ClientFactory builds a Kubernetes client authenticated with the caller's own bearer token. Each session-initiated spec mutation gets a per-call client so the apiserver authenticates the real user and k8s RBAC decides — never muster's ServiceAccount, never impersonation headers (dex-only ruling).

func NewKubernetesClientFactory

func NewKubernetesClientFactory(base *rest.Config) ClientFactory

NewKubernetesClientFactory returns a factory deriving per-call clients from the given base REST config: same apiserver host and CA, all ambient credentials stripped, the caller's bearer as the only authentication.

type Gate

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

Gate resolves the per-call caller-identity client a session-initiated CR mutation must use. The zero value is disabled: adapters keep their SA-backed write path (filesystem mode). The app layer enables it whenever muster runs in Kubernetes mode.

func NewGate

func NewGate(subject string) Gate

NewGate returns a disabled gate whose error messages name subject as the thing being written.

func (*Gate) Enable

func (g *Gate) Enable(factory ClientFactory, audience string)

Enable switches the gate on. factory may be nil when muster has no Kubernetes API access; mutations then fail with an explicit configuration error instead of silently falling back to the SA path. An empty audience selects DefaultKubernetesAudience.

func (*Gate) Enabled

func (g *Gate) Enabled() bool

Enabled reports whether caller-identity writes are on.

func (*Gate) Resolve

func (g *Gate) Resolve(ctx context.Context) (ctrlclient.Client, string)

Resolve returns the caller-identity client for the session carried by ctx, or a ready-to-return user-facing error message when the session cannot produce a usable bearer. Callers must check Enabled() first: resolving a disabled gate is a bug and fails accordingly.

Jump to

Keyboard shortcuts

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