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 ¶
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 ¶
ReloginError is the actionable error for sessions whose token cannot authenticate at the apiserver (missing audience, or rejected outright).
func TokenFromContext ¶
TokenFromContext returns the session's dex id_token carried on the request context by the OAuth middleware, or "" for unauthenticated transports.
func TokenMissingAudience ¶
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 ¶
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.