Documentation
¶
Overview ¶
Package useridentity persists credentials on the cluster-scoped UserIdentity CRD and its master credential Secrets, and holds the naming helpers every component derives those names with.
Index ¶
- Constants
- func Attestation(sec *corev1.Secret) (providerID, subjectID string, ok bool)
- func IdPIdentitySecretName(subject string) string
- func MasterSecretName(userIdentityName, credentialName string) string
- func MigrateRedemptionMaterial(ctx context.Context, c client.Client, namespace, masterName string) (bool, error)
- func NameForSubject(subject identity.Subject) string
- func PutOAuthToken(ctx context.Context, c client.Client, req PutOAuthTokenRequest) error
- func PutToken(ctx context.Context, c client.Client, req PutTokenRequest) error
- func SetAttestation(sec *corev1.Secret, providerID, subjectID string)
- func UpsertCredential(creds []spiceboxv1alpha1.AgentCredential, c spiceboxv1alpha1.AgentCredential) []spiceboxv1alpha1.AgentCredential
- type PutOAuthTokenRequest
- type PutTokenRequest
Constants ¶
const AttestedProviderAnnotation = "useridentity.agentprimitives.authzed.com/attested-provider"
AttestedProviderAnnotation holds the provider id the attestation came from, so a reader never has to infer which namespace the subject belongs to.
const AttestedSubjectAnnotation = "useridentity.agentprimitives.authzed.com/attested-subject"
AttestedSubjectAnnotation holds the provider's STABLE id for the account the credential authenticated as (for GitHub, the numeric user id as a string — never the login, which is mutable and reclaimable).
const RotationFingerprintAnnotation = "useridentity.agentprimitives.authzed.com/rotation-fingerprint"
RotationFingerprintAnnotation carries a fingerprint of the most recently linked credential's (name, value) pair. PutToken and PutOAuthToken restamp it on every link so a same-name re-link with a DIFFERENT value changes the UserIdentity object: the credential Spec entry references the master Secret by deterministic name only, never by value, so without this a value-only rotation is a no-op Update that never fires the AgentSession UserIdentity watch. With it, the changed annotation is a real write, the watch re-enqueues the subject's non-terminal sessions, and the passthrough reconcile re-projects and emits a per-session credential invalidation.
Variables ¶
This section is empty.
Functions ¶
func Attestation ¶
Attestation reads back what SetAttestation wrote. ok is false unless both halves are present, so a partially-written pair is treated as absent rather than as a claim about an unknown provider.
func IdPIdentitySecretName ¶
IdPIdentitySecretName returns the deterministic name of the Secret holding the user's captured IdP refresh token (the federation subject-token source), in IdentitiesNamespace. Derived from the same subject hash as the UserIdentity, so any component can locate it.
func MasterSecretName ¶
MasterSecretName returns the name of the Secret holding one credential's material, in the agentprimitives-identities namespace.
func MigrateRedemptionMaterial ¶
func MigrateRedemptionMaterial(ctx context.Context, c client.Client, namespace, masterName string) (bool, error)
MigrateRedemptionMaterial moves a master Secret's CO-LOCATED redemption material into its labeled sibling and strips it from the master, reporting whether it moved anything. Idempotent: a master carrying none of the keys is left untouched and reports false.
The two-Secret split only buys anything if existing credentials get split too. PutOAuthToken strips the co-located copy on a re-link, but nothing re-links a WORKING credential — so without this pass a co-located master keeps handing every userPassthrough runner (granted `get` on it by name, and a Kubernetes read returns every key) a self-contained, offline-usable refresh grant for the user's upstream account. See refresh.MaterialSecretName.
ORDER IS THE POINT. The sibling is written FIRST and the master stripped only after that write returns, so every interruption leaves the material readable somewhere: crash before the sibling write and nothing changed, crash between and both copies exist (the sibling wins at redemption, the master is stripped next pass). Stripping first would destroy the only durable copy of a DCR-minted client, leaving an unrefreshable credential recoverable only by a manual re-link.
Failures are returned, never swallowed: a caller that cannot finish must leave the credential in its working co-located shape rather than half-migrated. A Secret at the sibling's derived name that is NOT this credential's refresh material surfaces as an error, and the master keeps its keys.
A missing master is not an error (reports false): the Secret may not exist yet, which the validity reconciler reports as Valid=False/SecretMissing.
func NameForSubject ¶
NameForSubject returns the deterministic, DNS-safe metadata.name for the UserIdentity of the given canonical SpiceDB subject. The operator and identityd both compute it, so either can Get the UserIdentity by name without a list/filter. A canonical subject can exceed the 63-char DNS-label limit and is not lowercase, so the name is a hash rather than the subject itself; the full subject is stored in spec.subject.
func PutOAuthToken ¶
PutOAuthToken upserts a master Secret in the multi-key OAuth shape that pkg/controllers/useridentity/refresh_controller.go reads, then upserts the UserIdentity catalog entry as a type=oauth credential. Mirrors PutToken's semantics for PAT credentials.
The credential is written as TWO Secrets, because Kubernetes RBAC cannot scope a grant to individual keys:
- the MASTER (MasterSecretName) holds what a consumer of the credential needs — access_token (always), token_type / refresh_token / scope (when non-empty), expires_at (RFC 3339, when ExpiresAt != 0). A userPassthrough session's runner is granted read on this one.
- the REFRESH sibling (refresh.MaterialSecretName) holds the redemption material — token_endpoint / client_id / client_secret, each when non-empty — which only a refresher ever needs. Nothing grants the runner this Secret, so a compromised runner reads a refresh token it has no endpoint, client identity or authenticator to redeem.
Idempotent: repeated calls with the same subject + credential replace both Secrets' values and the UserIdentity entry in place.
func PutToken ¶
PutToken upserts a static bearer credential on the UserIdentity for the given subject: it writes the token to the master Secret in IdentitiesNamespace, then upserts the credential entry on the cluster-scoped UserIdentity. Idempotent — a repeat with the same subject + credential just replaces the Secret value. Returns a non-nil error on any sub-step failure; partial-success states are not exposed, and the caller can retry.
`oap user-identity put-token` and identityd's /link/submit handler both go through here, so they produce indistinguishable cluster state. That is also why the link-time attestation is recorded HERE and not at each caller: every route a human links a credential through lands in this function, so a new one gets the attestation without having to remember it.
func SetAttestation ¶
SetAttestation records that sec's credential authenticated as subjectID at providerID.
An empty providerID or subjectID writes nothing and clears nothing: absent and "attested as nothing" are different states, and a verification that could not extract an id must not erase an earlier one that could.
func UpsertCredential ¶
func UpsertCredential(creds []spiceboxv1alpha1.AgentCredential, c spiceboxv1alpha1.AgentCredential) []spiceboxv1alpha1.AgentCredential
UpsertCredential replaces the credential with matching Name in creds, or appends c when no match exists. Exported so the `oap` CLI's local helpers stay aligned with this package's notion of upsert.
Types ¶
type PutOAuthTokenRequest ¶
type PutOAuthTokenRequest struct {
// Subject is the canonical SpiceDB subject ("user:<...>").
// metadata.name of the resulting UserIdentity is NameForSubject(Subject).
Subject identity.Subject
// CredentialName is the credential name as agents declare it (e.g.
// "linear-oauth"). The master Secret is named
// MasterSecretName(uiName, CredentialName).
CredentialName string
// AccessToken is the current OAuth access token. Required.
AccessToken string
// RefreshToken is the long-lived refresh token. May be empty if the
// provider does not issue one; absent from the Secret when empty.
RefreshToken string
// ExpiresAt is the expiry as a Unix epoch seconds value. Zero means
// "unknown / never expires"; the expires_at key is omitted from the
// Secret when zero (RFC 6749 §5.1: expires_in is OPTIONAL).
ExpiresAt int64
// TokenType is typically "Bearer". Written when non-empty.
TokenType string
// Scope is the space-separated granted scopes string. May be empty;
// absent from the Secret when empty.
Scope string
// TokenEndpoint is the provider's RFC 6749 token endpoint, discovered during
// the authorization flow. Required whenever RefreshToken is set: the refresh
// Secret is its only durable home, and pkg/platform/identity/refresh reads it
// from there at every refresh. Absent from that Secret when empty.
TokenEndpoint string
// ClientID is the OAuth client the tokens were issued to — for a
// dynamically-registered client (RFC 7591), the one DCR minted for this link.
// Presented on every subsequent refresh, so it is persisted alongside the
// tokens rather than left in the flow's transient state. Absent when empty.
ClientID string
// ClientSecret is the client's secret, for confidential clients only. Public
// (PKCE-only) clients have none and omit the key entirely; a confidential
// client that omits it gets invalid_client at refresh time. Absent when empty.
ClientSecret string
}
PutOAuthTokenRequest carries everything the OAuth callback handler learned from the provider's token-exchange response.
type PutTokenRequest ¶
type PutTokenRequest struct {
// Subject is the canonical SpiceDB subject ("user:<base64(email)>").
// metadata.name of the resulting UserIdentity is NameForSubject(Subject).
Subject identity.Subject
// CredentialName is the credential name as agents declare it (e.g.
// "github-pat"). The master Secret is named
// MasterSecretName(uiName, CredentialName).
CredentialName string
// Token is the bearer-token bytes to persist as data["token"].
Token string
// DisplayName is an optional human-friendly label written to
// spec.displayName. Empty leaves the existing value untouched.
DisplayName string
// ProviderID and SubjectID are the link-time attestation: which provider
// live-verified this credential, and the provider's STABLE id for the
// account it authenticated as (builtins.VerifyResult.ProviderID /
// .SubjectID). They are recorded on the master Secret for the UserIdentity
// reconciler to turn into an identity edge — see
// pkg/controllers/useridentity/attested_edge.go.
//
// A pair, never one alone: an id is stable only within its provider's
// id-space, so half of it names nothing. Both empty is the ordinary case —
// verification was skipped, the provider declares no subject id field, or
// the check could not conclude — and records nothing rather than guessing.
ProviderID string
SubjectID string
}
PutTokenRequest is the input to PutToken.