Documentation
¶
Overview ¶
Package oauth resolves OAuth credentials for the relay's secret layer. The stored secret is an OAuth token blob (access + refresh + expiry, the sdk/oauth.Token wire shape) held as AES-GCM ciphertext in the same secret_values table as KindStored. Resolve returns the access token, transparently refreshing via the refresh token when it has expired and re-persisting the (often rotated) blob.
It is deliberately off the hot path: resolution happens at snapshot load and during KeyAgent heal after an upstream 401, never per request. Concurrent resolves of the same credential single-flight to one refresh.
Layering: imports sdk/oauth (the flow machinery) + pkg/secret (the Ref/Vault contract). It never imports app/ — the provider config is injected as a plain lookup func by the composition root, which reads the live oauth:<provider> settings section.
refresher.go: proactive, cluster-safe renewal of OAuth credentials.
The Refresher keeps subscription tokens fresh ahead of expiry so no request ever pays refresh latency (or a wasted upstream 401) — the KeyAgent reactive heal stays underneath as the safety net. It is fully isolated: everything it touches is injected (which refs exist, a lock, a rotation broadcast), it runs its own ticker goroutine, and the request pipeline knows nothing about it.
Cluster safety: refresh tokens rotate on use, and a concurrent second refresh with the superseded token can trip the provider's reuse detection and revoke the whole grant. Every renewal therefore runs under a per-credential advisory lock (kv WithLock in production), with Renew re-loading the blob inside the critical section — the loser of a lock race sees the fresh blob and no-ops.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPermanent ¶ added in v0.9.10
IsPermanent reports whether a refresh error is unrecoverable without operator re-authorization (the provider rejected the grant itself, e.g. a revoked or reused refresh token), as opposed to a transient network/server failure worth retrying.
Types ¶
type Hooks ¶ added in v0.9.10
type Hooks struct {
// OnRenewed fires after a rotated blob was persisted; expiresAt is the
// fresh token's expiry.
OnRenewed func(ctx context.Context, id string, expiresAt time.Time) error
// OnRevoked fires when the provider rejected the grant itself
// (IsPermanent) — re-authorization is an operator action.
OnRevoked func(ctx context.Context, id string, cause error) error
}
Hooks receive renewal outcomes so the composition root can persist observed credential state (hostkey status) and broadcast rotations. Either hook may be nil.
type Locker ¶ added in v0.9.10
type Locker interface {
WithLock(ctx context.Context, keys []string, fn func(context.Context) error) error
}
Locker serializes a critical section across processes. pkg/kv.Store satisfies it; every key this package passes shares one credential-scoped hash tag per the kv conventions.
type ProviderConfigFunc ¶
type ProviderConfigFunc func(provider string) (sdkoauth.ProviderConfig, bool)
ProviderConfigFunc returns the OAuth config for a provider name (the oauth:<provider> settings section), or ok=false when unconfigured.
type RefSource ¶ added in v0.9.10
RefSource enumerates the OAuth credentials to keep fresh. Injected by the composition root (the hostkey store in practice). It MUST exclude credentials whose stored status is revoked — renewal resumes when the operator re-authorizes (a value update clears the status), and the refresher itself keeps no memory of them.
type Refresher ¶ added in v0.9.10
type Refresher struct {
// contains filtered or unexported fields
}
Refresher periodically renews every sourced OAuth credential whose expiry falls within Lead. Construct with NewRefresher and start with Run.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver implements secret.Resolver for KindOAuth.
func NewResolver ¶
func NewResolver(vault Vault, cfg ProviderConfigFunc) *Resolver
NewResolver builds an OAuth resolver. vault provides the AES-GCM persistence (a *secret.StoredResolver); cfg looks up the provider's flow config.
func (*Resolver) Renew ¶ added in v0.9.10
func (r *Resolver) Renew(ctx context.Context, ref secret.Ref, lead time.Duration) (bool, time.Time, error)
Renew proactively refreshes the credential when its expiry falls within lead, persisting the rotated blob. Reports whether a new blob was persisted and the credential's current expiry. A token with no expiry, or one still comfortably valid, is a no-op. Callers coordinating across processes must hold their own lock — the in-process single-flight only dedupes within this resolver.
type Vault ¶
type Vault interface {
Resolve(ctx context.Context, ref secret.Ref) ([]byte, error)
Create(ctx context.Context, id string, plaintext []byte) (secret.Ref, error)
}
Vault is the encrypt/decrypt persistence the resolver delegates to — the StoredResolver in practice. The OAuth blob round-trips as a KindStored value.