registrytoken

package
v1.5.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const (
	PresetECR              = "ecr"
	PresetArtifactRegistry = "artifact_registry"
	PresetACR              = "acr"
)

Preset names stored in registry_credentials.preset.

Variables

View Source
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

func DefaultMinters(fallbackTTL time.Duration) map[string]Minter

DefaultMinters returns the real minters, keyed by preset. fallbackTTL bounds a token whose expiry cannot be read from the provider response.

func EncodeConfig

func EncodeConfig(cfg Config) (string, error)

EncodeConfig serialises a Config for preset_config.

func ProviderFor

func ProviderFor(preset string) (string, error)

ProviderFor returns the node-provider secret namespace whose stored credential a preset mints from.

func SafeError

func SafeError(err error) string

SafeError flattens an error to one bounded line for storage and alerts.

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.

func (*ACR) Mint

func (a *ACR) Mint(ctx context.Context, cloudSecret string, cfg Config) (Minted, error)

Mint implements Minter.

type ArtifactRegistry

type ArtifactRegistry struct {
	Client *http.Client
}

ArtifactRegistry mints an OAuth access token from the same service account JSON Compute Engine nodes use; the token is the registry password.

func (*ArtifactRegistry) Mint

func (a *ArtifactRegistry) Mint(ctx context.Context, cloudSecret string, cfg Config) (Minted, error)

Mint implements Minter.

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

func ParseConfig(raw string) (Config, error)

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).

func (*ECR) Mint

func (e *ECR) Mint(ctx context.Context, cloudSecret string, cfg Config) (Minted, error)

Mint implements Minter.

type Minted

type Minted struct {
	RegistryHost string
	Username     string
	Password     string
	ExpiresAt    time.Time
}

Minted is one freshly issued registry login.

type Minter

type Minter interface {
	Mint(ctx context.Context, cloudSecret string, cfg Config) (Minted, error)
}

Minter exchanges the stored cloud credential (cloudSecret) for a registry login.

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) Interval

func (r *Refresher) Interval() time.Duration

Interval is how often the loop checks for due credentials.

func (*Refresher) NextRefresh

func (r *Refresher) NextRefresh(now, expires time.Time) time.Time

NextRefresh is when a login expiring at expires should be renewed.

func (*Refresher) Preview

func (r *Refresher) Preview(ctx context.Context, preset string, cfg Config) (Minted, error)

Preview mints a login without storing anything, for the Test button.

func (*Refresher) Refresh

func (r *Refresher) Refresh(ctx context.Context, id string) (store.RegistryCredential, error)

Refresh mints a new login for one credential and stores it. A failure is recorded on the row (so the alert and UI show it) and returned.

func (*Refresher) Tick

func (r *Refresher) Tick(ctx context.Context) error

Tick refreshes every preset credential whose next refresh time has passed.

type SecretStore

type SecretStore interface {
	SetValue(ctx context.Context, serviceName, envKey, plaintext string) error
	Resolve(ctx context.Context, serviceName, envKey string) (string, error)
}

SecretStore is the envelope-encrypted secret surface; *secrets.Manager satisfies it.

type Settings

type Settings struct {
	Lead, Interval, Retry, FallbackTTL time.Duration
}

Settings are the refresher timings.

func SettingsFromEnv

func SettingsFromEnv(lookup func(string) string) Settings

SettingsFromEnv reads timings from lookup; invalid values keep defaults.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL