Documentation
¶
Overview ¶
Package registrytoken mints short-lived container registry passwords from an existing cloud connection (ECR, Artifact Registry, ACR) and keeps the stored registry credential fresh.
Index ¶
- Constants
- Variables
- func DefaultMinters(fallbackTTL time.Duration) map[string]Minter
- func EncodeConfig(cfg Config) (string, error)
- func ProviderFor(preset string) (string, error)
- func SafeError(err error) string
- type ACR
- type ArtifactRegistry
- type Config
- type CredentialStore
- type ECR
- type Minted
- type Minter
- type Refresher
- func (r *Refresher) Interval() time.Duration
- func (r *Refresher) NextRefresh(now, expires time.Time) time.Time
- func (r *Refresher) Preview(ctx context.Context, preset string, cfg Config) (Minted, error)
- func (r *Refresher) Refresh(ctx context.Context, id string) (store.RegistryCredential, error)
- func (r *Refresher) Tick(ctx context.Context) error
- type SecretStore
- type Settings
Constants ¶
const ( EnvLead = "APP_REGISTRY_REFRESH_LEAD" EnvInterval = "APP_REGISTRY_REFRESH_INTERVAL" EnvRetry = "APP_REGISTRY_REFRESH_RETRY" EnvFallbackTTL = "APP_REGISTRY_ACR_FALLBACK_TTL" )
Env names for the refresher; durations use Go syntax such as 30m.
const ( PresetECR = "ecr" PresetArtifactRegistry = "artifact_registry" PresetACR = "acr" )
Preset names stored in registry_credentials.preset.
Variables ¶
var ErrNoCloudConnection = errors.New("registrytoken: no cloud connection for this preset")
ErrNoCloudConnection means the cloud credential a preset needs is not stored.
Functions ¶
func DefaultMinters ¶
DefaultMinters returns the real minters, keyed by preset. fallbackTTL bounds a token whose expiry cannot be read from the provider response.
func EncodeConfig ¶
EncodeConfig serialises a Config for preset_config.
func ProviderFor ¶
ProviderFor returns the node-provider secret namespace whose stored credential a preset mints from.
Types ¶
type ACR ¶
type ACR struct {
Client *http.Client
FallbackTTL time.Duration
// LoginBase and ExchangeBase override the AAD and registry URLs, for tests.
LoginBase string
ExchangeBase string
Now func() time.Time
}
ACR exchanges an Azure AD token, obtained with the stored Azure service principal (secret or federated), for an ACR refresh token.
type ArtifactRegistry ¶
ArtifactRegistry mints an OAuth access token from the same service account JSON Compute Engine nodes use; the token is the registry password.
type Config ¶
type Config struct {
Region string `json:"region,omitempty"`
RegistryHost string `json:"registry_host,omitempty"`
}
Config is the non-secret, per-credential preset setting.
func ParseConfig ¶
ParseConfig decodes a credential's stored preset_config.
type CredentialStore ¶
type CredentialStore interface {
ListRegistryCredentials(ctx context.Context) ([]store.RegistryCredential, error)
GetRegistryCredential(ctx context.Context, id string) (store.RegistryCredential, error)
RecordRegistryCredentialRefresh(ctx context.Context, id, registryHost, username string, expiresAt, refreshedAt, nextAt *time.Time, errMsg string) error
}
CredentialStore is the registry credential store surface the refresher uses.
type ECR ¶
type ECR struct {
Client *http.Client
// Endpoint overrides the regional API URL, for tests.
Endpoint string
Now func() time.Time
}
ECR mints a password with ECR GetAuthorizationToken, signed with the same AWS identity modes EC2 provisioning uses (static key, assumed role, ambient).
type Refresher ¶
type Refresher struct {
Store CredentialStore
Secrets SecretStore
Minters map[string]Minter
Settings Settings
Now func() time.Time
Logger *slog.Logger
// contains filtered or unexported fields
}
Refresher renews preset registry credentials before they expire.
func (*Refresher) NextRefresh ¶
NextRefresh is when a login expiring at expires should be renewed.