Documentation
¶
Overview ¶
Package secretconn manages named secret connections and adapts the Vault resolver and the Doppler, Infisical and 1Password providers to secretsource.Provider. The legacy single Vault row appears as the connection "vault" and legacy providers keep their names.
Index ¶
- Constants
- Variables
- type Config
- type Connection
- type EnvIndex
- type Input
- type PathProber
- type Policy
- type Prober
- type Rows
- type Service
- func (s *Service) CheckResolve(ctx context.Context, conn, envID, path string) error
- func (s *Service) CheckUnvettedRef(ctx context.Context, conn, envID, path string) error
- func (s *Service) Create(ctx context.Context, actor, name string, in Input) (Connection, error)
- func (s *Service) DelegatedRefAllowed(ctx context.Context, conn, envID, path string) bool
- func (s *Service) Delete(ctx context.Context, name string) error
- func (s *Service) Get(ctx context.Context, name string) (Connection, error)
- func (s *Service) List(ctx context.Context) ([]Connection, error)
- func (s *Service) Sync(ctx context.Context) error
- func (s *Service) Test(ctx context.Context, name, path string) (TestResult, error)
- func (s *Service) Update(ctx context.Context, name string, in Input) (Connection, error)
- type TestResult
- type VaultSettings
Constants ¶
const ( TypeVault = "vault" TypeDoppler = secretprovider.TypeDoppler TypeInfisical = secretprovider.TypeInfisical TypeOnePassword = secretprovider.TypeOnePassword )
Connection types.
const LegacyVaultName = "vault"
LegacyVaultName is the implicit connection backed by the single Vault settings row.
const SecretsOwner = "secretconnections" //nolint:gosec // namespace name, not a credential
SecretsOwner is the internal/secrets namespace holding stored connection credentials.
Variables ¶
var ( ErrInvalid = errors.New("secretconn: invalid connection") ErrConflict = errors.New("secretconn: connection name already in use") ErrNotFound = errors.New("secretconn: connection not found") ErrLegacy = errors.New("secretconn: legacy connection is managed through its own settings") )
Errors the API maps to status codes.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Address string `json:"address,omitempty"`
Namespace string `json:"namespace,omitempty"`
Mount string `json:"mount,omitempty"`
AuthMethod string `json:"auth_method,omitempty"`
RoleID string `json:"role_id,omitempty"`
Project string `json:"project,omitempty"`
Environment string `json:"environment,omitempty"`
Path string `json:"path,omitempty"`
BaseURL string `json:"base_url,omitempty"`
}
Config holds the non-secret settings; which fields apply depends on Type.
type Connection ¶
type Connection struct {
Name string
Type string
Legacy bool
Config Config
HasCredential bool
CredentialRef string
Policy Policy
CreatedBy string
CreatedAt time.Time
UpdatedAt time.Time
}
Connection is one named source; it never carries a credential value.
type EnvIndex ¶
type EnvIndex interface {
GetEnvironment(ctx context.Context, id string) (store.Environment, error)
EnvironmentIDsByName(ctx context.Context, name string) ([]string, error)
}
EnvIndex looks environments up by id or name.
type Input ¶
type Input struct {
Type string
Config Config
Credential string
CredentialRef string
// A non nil list replaces that allow list; nil keeps it on update.
AllowedPrefixes *[]string
AllowedEnvs *[]string
}
Input creates or updates a connection. Credential is write-only; empty keeps the stored one on update.
type PathProber ¶
PathProber is the optional read-only check that a credential can reach one path.
type Policy ¶
type Policy struct {
AllowedPrefixes []string `json:"allowed_prefixes,omitempty"`
AllowedEnvs []string `json:"allowed_envs,omitempty"`
AllowedEnvIDs []string `json:"allowed_env_ids,omitempty"`
}
Policy narrows what a connection serves. Prefixes are path prefixes on whole segments; Envs are the names or ids an operator typed, and EnvIDs are what they resolved to at save. Only ids are compared, since names are not unique. Both empty means no restriction.
func NormalizePolicy ¶
NormalizePolicy validates and canonicalizes the lists: trimmed, deduplicated, sorted, prefixes without edge slashes. Invalid entries are rejected rather than repaired.
func (Policy) Delegable ¶
Delegable reports whether the lists are complete enough to let a non root writer use the connection.
func (Policy) EnvAllowed ¶
EnvAllowed matches an environment id against the resolved ids; an unrestricted policy allows any.
func (Policy) PathAllowed ¶
PathAllowed reports whether path equals a prefix or sits below it on a segment boundary, so "team-a" never admits "team-ab". An empty list allows any path.
type Prober ¶
Prober is the optional read-only health check of a provider. It must not read a secret value and must not return one.
type Rows ¶
type Rows interface {
ListSecretConnections(ctx context.Context) ([]store.SecretConnection, error)
GetSecretConnection(ctx context.Context, name string) (store.SecretConnection, error)
CreateSecretConnection(ctx context.Context, c store.SecretConnection) error
UpdateSecretConnection(ctx context.Context, c store.SecretConnection) error
DeleteSecretConnection(ctx context.Context, name string) error
}
Rows is the connection table.
type Service ¶
type Service struct {
Rows Rows
Secrets secretprovider.Secrets
Vault VaultSettings
Sources *secretsource.Resolver
VaultRes *vault.Resolver
ProvRes *secretprovider.Resolver
ProvTun func(context.Context) secretprovider.Tunables
// Envs resolves allowed_envs to environment ids; without it an env list cannot be saved or served.
Envs EnvIndex
Now func() time.Time
// Build overrides adapter construction, for tests only.
Build func(Connection) secretsource.Provider
// contains filtered or unexported fields
}
Service owns the connection set and keeps a secretsource.Resolver in step with it.
func (*Service) CheckResolve ¶
CheckResolve is the resolve-time gate. A connection without a policy is unrestricted; one with a policy serves only listed environments and paths, and any lookup failure denies.
func (*Service) CheckUnvettedRef ¶
CheckUnvettedRef gates a reference no actor vetted: only a delegating connection serves it.
func (*Service) DelegatedRefAllowed ¶
DelegatedRefAllowed is the set-time check for a writer without root: the connection must carry both lists, the environment id must be listed and the path must sit inside a prefix.
func (*Service) Delete ¶
Delete removes a stored connection, its stored credential and its registration.
func (*Service) List ¶
func (s *Service) List(ctx context.Context) ([]Connection, error)
List returns legacy connections first, then stored ones, each group sorted by name.
func (*Service) Sync ¶
Sync makes the secretsource.Resolver match the current connections. Adapters read their config live, so a re-registration is only needed when a name appears or disappears.
type TestResult ¶
TestResult is the outcome of a health probe. Reason is a class, never provider output.
type VaultSettings ¶
type VaultSettings interface {
GetVaultSettings(ctx context.Context) (store.VaultSettings, error)
}
VaultSettings reads the legacy single Vault row.