Documentation
¶
Overview ¶
Package credprovider makes muster a credential provider of Substrate's egress gateway, so a workspace Session's git and gh act as the person who started it without the person's token ever reaching the sandbox.
Two surfaces:
- Session bindings, on muster's authenticated HTTP port: agent-manager calls PUT /session-bindings as the person (their forwarded ID token) with the Session's sandbox actor SPIFFE id and the providers the Session may use, and DELETE /session-bindings?actor=<id> when the Session goes. A binding belongs to the person who made it; nobody else can replace or remove it. It lives for the Session idle TTL, restarted by every bind and every answered fetch, in Valkey when muster runs on Valkey.
- CredentialProvider.FetchSecret, on a gRPC listener of its own that requires the egress gateway's pod certificate (mutual TLS, one SPIFFE id). For ate-secret://<authority>/<provider>/<git|api> and the actor the gateway verified, it answers the bound person's current access token of the provider's grant -- base64 of x-access-token:<token> for git (the gateway adds "Basic "), the token itself for the API (it adds "Bearer ") -- when the actor is bound, the provider is in the binding and on the configured releasable list. The refresh token never leaves muster. Every answer and every refusal is logged.
The grant itself is muster's OAuth proxy grant (grantScope: subject), looked up and refreshed through the GrantSource the aggregator wires in.
Index ¶
- Constants
- Variables
- func IsActorSession(sessionID string) bool
- type ActorBearer
- type ActorBearerOptions
- type ActorCaller
- type ActorTokenVerifier
- type BindRequest
- type Binding
- type GrantSource
- type MemoryStore
- func (s *MemoryStore) Delete(_ context.Context, actor, subject string) error
- func (s *MemoryStore) Get(_ context.Context, actor string) (*Binding, error)
- func (s *MemoryStore) Put(_ context.Context, actor string, b Binding, ttl time.Duration) error
- func (s *MemoryStore) Touch(_ context.Context, actor string, ttl time.Duration) error
- type OIDCVerifierOptions
- type Options
- type Provider
- func (p *Provider) BindingTTL() time.Duration
- func (p *Provider) FetchSecret(ctx context.Context, req *credproviderpb.FetchSecretRequest) (*credproviderpb.FetchSecretResponse, error)
- func (p *Provider) GatewayIdentity() string
- func (p *Provider) HandleBind(w http.ResponseWriter, r *http.Request)
- func (p *Provider) HandleUnbind(w http.ResponseWriter, r *http.Request)
- func (p *Provider) Store() Store
- type Server
- type Store
- type TLSFiles
- type ValkeyStore
- func (s *ValkeyStore) Delete(ctx context.Context, actor, subject string) error
- func (s *ValkeyStore) Get(ctx context.Context, actor string) (*Binding, error)
- func (s *ValkeyStore) Put(ctx context.Context, actor string, b Binding, ttl time.Duration) error
- func (s *ValkeyStore) Touch(ctx context.Context, actor string, ttl time.Duration) error
Constants ¶
const ( // MusterProvider is the reserved provider instance a binding lists to let // its actor call muster itself as the bound person with Substrate's actor // JWT. FetchSecret never releases it. MusterProvider = "muster" // ActorJWKSPath is where Substrate serves its actor-JWT key set, // relative to the issuer. ActorJWKSPath = "/openid/v1/jwks" )
const ( // DefaultAuthority is the credential URI authority muster answers. DefaultAuthority = "muster.giantswarm.io" // DefaultBindingTTL is the platform's default Session idle TTL. DefaultBindingTTL = 14 * 24 * time.Hour // DefaultGitUser is the user name GitHub takes with a token as password, // answered for a provider without a GitUsers entry. DefaultGitUser = "x-access-token" )
const BindingsPath = "/session-bindings"
BindingsPath is the HTTP path of the Session binding endpoints.
const DefaultListenAddress = ":50051"
DefaultListenAddress is the FetchSecret listener's default address.
Variables ¶
var ( // ErrInvalidActorToken is a bearer that is no valid actor JWT for muster. ErrInvalidActorToken = errors.New("invalid actor token") // ErrActorNotAllowed is a valid actor JWT whose actor is unbound or whose // binding does not list MusterProvider. ErrActorNotAllowed = errors.New("actor may not call muster") ErrBindingsUnavailable = errors.New("binding store unavailable") )
var ErrBoundToAnother = errors.New("the actor is bound to another person")
ErrBoundToAnother is returned when a bind or unbind names an actor that is bound to a different person.
Functions ¶
func IsActorSession ¶ added in v5.46.0
IsActorSession reports whether a muster session ID is an actor-JWT caller's (ActorCaller.SessionID), which has no login of its own.
Types ¶
type ActorBearer ¶ added in v5.45.0
type ActorBearer struct {
// contains filtered or unexported fields
}
ActorBearer authenticates Substrate actor JWTs as the person the actor is bound to.
func NewActorBearer ¶ added in v5.45.0
func NewActorBearer(o ActorBearerOptions) (*ActorBearer, error)
NewActorBearer returns an ActorBearer, or an error for an incomplete configuration.
func (*ActorBearer) Authenticate ¶ added in v5.45.0
func (a *ActorBearer) Authenticate(ctx context.Context, bearer string) (*ActorCaller, error)
Authenticate verifies bearer and returns the person its actor is bound to. It fails with ErrInvalidActorToken, ErrActorNotAllowed or ErrBindingsUnavailable.
func (*ActorBearer) Claims ¶ added in v5.45.0
func (a *ActorBearer) Claims(bearer string) bool
Claims reports whether bearer is a JWT naming the actor-JWT issuer. It reads the payload unverified and only routes the request: Authenticate verifies.
type ActorBearerOptions ¶ added in v5.45.0
type ActorBearerOptions struct {
// Issuer is the actor JWTs' iss. Required.
Issuer string
// Verify checks a JWT of Issuer. Required.
Verify ActorTokenVerifier
// Store holds the Session bindings. Required.
Store Store
// BindingTTL restarts a binding on each accepted request
// (DefaultBindingTTL if 0).
BindingTTL time.Duration
}
ActorBearerOptions configure an ActorBearer.
type ActorCaller ¶ added in v5.45.0
type ActorCaller struct {
// Actor is the actor's SPIFFE id.
Actor string
// Subject is the bound person.
Subject string
// Session is the bound Session, for the audit log.
Session string
// SessionID is the muster session of the actor under its binding:
// stable across its turns.
SessionID string
// Expiry is the actor JWT's exp.
Expiry time.Time
// Toolset is the bound toolset, the selectors every request of the actor
// resolves within; nil when the binding carries none.
Toolset []string
}
ActorCaller is the person an actor-JWT bearer acts as.
type ActorTokenVerifier ¶ added in v5.45.0
type ActorTokenVerifier func(ctx context.Context, token string) (subject string, expiry time.Time, err error)
ActorTokenVerifier verifies an actor JWT's signature, issuer, audience and lifetime, and returns its sub and expiry.
func NewOIDCActorTokenVerifier ¶ added in v5.45.0
func NewOIDCActorTokenVerifier(o OIDCVerifierOptions) (ActorTokenVerifier, error)
NewOIDCActorTokenVerifier verifies actor JWTs against the issuer's key set: an asymmetric signature by a published key, exp (required), nbf and iat with clock-skew leeway, the issuer and the audience.
type BindRequest ¶
type BindRequest struct {
// Actor is the Session's sandbox actor SPIFFE id.
Actor string `json:"actor"`
// Session names the Session (<namespace>/<name>), for the audit log.
Session string `json:"session"`
// Providers are the provider instances the Session may use.
Providers []string `json:"providers"`
// Toolset is the agent's toolset, the inline selectors that bound every
// request the actor makes to muster (X-Muster-Toolset grammar). Absent
// binds none: the actor's requests are unscoped unless they send the
// header.
Toolset []string `json:"toolset,omitempty"`
}
BindRequest is the body of PUT /session-bindings.
type Binding ¶
type Binding struct {
// Subject is the person's identity provider subject, the key their
// grants are filed under.
Subject string `json:"sub"`
// Session names the Session, for the audit log.
Session string `json:"session"`
// Providers are the provider instances (credential URI first segment)
// the Session may use.
Providers []string `json:"providers"`
// Toolset is the agent's toolset at the Session's start: the inline
// selectors that bound every request the actor makes to muster. nil binds
// none (implicit full access); a binding stored before toolsets were bound
// reads as nil.
Toolset []string `json:"toolset,omitempty"`
// BoundAt is when the binding was last written.
BoundAt time.Time `json:"boundAt"`
}
Binding ties a Session's sandbox actor to the person who started it and the providers whose grants the Session may use.
type GrantSource ¶
type GrantSource func(ctx context.Context, subject, issuer string) *api.OAuthToken
GrantSource returns the person's current grant from the issuer, refreshed when due, or nil when they hold none.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is the in-process Store for a muster that runs without Valkey.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore returns an empty MemoryStore.
func (*MemoryStore) Delete ¶
func (s *MemoryStore) Delete(_ context.Context, actor, subject string) error
Delete implements Store.
type OIDCVerifierOptions ¶ added in v5.45.0
type OIDCVerifierOptions struct {
// Issuer is the expected iss. Required.
Issuer string
// JwksURL is the key set (Issuer + ActorJWKSPath if empty).
JwksURL string
// Audience is the expected aud. Required.
Audience string
// RootCAs verifies the key set endpoint (system roots if nil).
RootCAs *x509.CertPool
// AllowPrivateIPHosts may resolve to a private address.
AllowPrivateIPHosts []string
}
OIDCVerifierOptions configure NewOIDCActorTokenVerifier.
type Options ¶
type Options struct {
// Authority is the credential URI authority (DefaultAuthority if empty).
Authority string
// GatewayIdentity is the only caller SPIFFE id answered.
GatewayIdentity string
// Releasable maps provider instance to grant issuer.
Releasable map[string]string
// GitUsers maps a releasable provider instance to the user name sent
// with its token for git (DefaultGitUser without an entry). GitLab
// takes an OAuth access token only as oauth2.
GitUsers map[string]string
// MusterBearer lets a binding list MusterProvider, for an actor that
// calls muster itself with its actor JWT (ActorBearer).
MusterBearer bool
// BindingTTL is the binding lifetime without use (DefaultBindingTTL if 0).
BindingTTL time.Duration
Store Store
Grants GrantSource
}
Options configure a Provider.
type Provider ¶
type Provider struct {
credproviderpb.UnimplementedCredentialProviderServer
// contains filtered or unexported fields
}
Provider answers FetchSecret from the Session bindings.
func NewProvider ¶
NewProvider returns a Provider, or an error for an incomplete configuration.
func (*Provider) BindingTTL ¶ added in v5.45.0
BindingTTL is the binding lifetime without use.
func (*Provider) FetchSecret ¶
func (p *Provider) FetchSecret(ctx context.Context, req *credproviderpb.FetchSecretRequest) (*credproviderpb.FetchSecretResponse, error)
FetchSecret implements credproviderpb.CredentialProviderServer.
func (*Provider) GatewayIdentity ¶
GatewayIdentity is the caller SPIFFE id the listener requires.
func (*Provider) HandleBind ¶
func (p *Provider) HandleBind(w http.ResponseWriter, r *http.Request)
HandleBind is PUT /session-bindings: binds the actor to the calling person. The caller must be authenticated (api.GetSubjectFromContext non-empty).
func (*Provider) HandleUnbind ¶
func (p *Provider) HandleUnbind(w http.ResponseWriter, r *http.Request)
HandleUnbind is DELETE /session-bindings?actor=<id>: removes the calling person's binding of the actor. Unbinding an unbound actor succeeds.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server owns the FetchSecret gRPC listener.
func Listen ¶
Listen binds addr and serves the provider over mutual TLS: the caller's certificate must chain to files.ClientCAFile and carry the provider's gateway identity as a URI SAN. Both files are re-read when they change, so rotated pod certificates and trust bundles are picked up.
func Serve ¶
func Serve(lis net.Listener, creds credentials.TransportCredentials, p *Provider) *Server
Serve serves the provider on lis with creds until Stop.
type Store ¶
type Store interface {
// Put writes the binding for the actor unless the actor is bound to
// another subject (ErrBoundToAnother).
Put(ctx context.Context, actor string, b Binding, ttl time.Duration) error
// Get returns the live binding for the actor, or nil.
Get(ctx context.Context, actor string) (*Binding, error)
// Touch restarts the actor's binding TTL; a missing binding is no error.
Touch(ctx context.Context, actor string, ttl time.Duration) error
// Delete removes the actor's binding when it belongs to subject
// (ErrBoundToAnother otherwise); a missing binding is no error.
Delete(ctx context.Context, actor, subject string) error
}
Store keeps bindings keyed by actor SPIFFE id, each expiring ttl after its last Put or Touch.
type TLSFiles ¶
type TLSFiles struct {
// ServerCredBundle holds the serving key and certificate chain.
ServerCredBundle string
// ClientCAFile holds the CAs a caller's certificate must chain to.
ClientCAFile string
}
TLSFiles names the PEM files the listener serves with.
type ValkeyStore ¶
type ValkeyStore struct {
// contains filtered or unexported fields
}
ValkeyStore keeps bindings in Valkey, shared by every muster replica.
Data model:
Key: {keyPrefix}credprovider:binding:{sha256(actor)}
Value: [encrypted] JSON(Binding)
TTL: the binding TTL, restarted by Put and Touch
Put and Delete check the owner and write in one Lua script, so two replicas cannot race a bind past another person's binding.
func NewValkeyStore ¶
func NewValkeyStore(client valkey.Client, keyPrefix string, encryptor *security.Encryptor) *ValkeyStore
NewValkeyStore returns a Store on the shared Valkey client. encryptor, when enabled, seals each value with AES-256-GCM like muster's token store.
func (*ValkeyStore) Delete ¶
func (s *ValkeyStore) Delete(ctx context.Context, actor, subject string) error
Delete implements Store.