Documentation
¶
Overview ¶
Package secrets provides generic secret management utilities for authentication. This package contains functions that can be used by any authentication method (OAuth, bearer tokens, etc.) to process secrets and store them in a secrets manager.
Index ¶
- func GenerateUniqueSecretNameWithPrefix(workloadName, prefix string, secretManager secrets.Provider) (string, error)
- func GetSecretsManager() (secrets.Provider, error)
- func GetSystemSecretsProvider() (secrets.Provider, error)
- func GetUserSecretsProvider() (secrets.Provider, error)
- func IsWorkloadOwnedSecretName(workloadName, prefix, name string) bool
- func ProcessSecret(workloadName, secretValue string, tokenType TokenType) (string, error)
- func ProcessSecretWithProvider(workloadName, secretValue string, secretManager secrets.Provider, ...) (string, error)
- func StoreSecretInManagerWithProvider(ctx context.Context, secretName, secretValue string, ...) error
- type TokenType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateUniqueSecretNameWithPrefix ¶
func GenerateUniqueSecretNameWithPrefix(workloadName, prefix string, secretManager secrets.Provider) (string, error)
GenerateUniqueSecretNameWithPrefix generates a unique secret name with a custom prefix This is a generic function that can be used for any secret type
func GetSecretsManager ¶
GetSecretsManager returns the secrets manager instance This is exported so it can be reused by other packages
func GetSystemSecretsProvider ¶ added in v0.22.0
GetSystemSecretsProvider returns a raw (unscoped) secrets provider for advanced/emergency operations on system-managed keys. Unlike GetUserSecretsProvider it does not apply UserProvider filtering, so callers can read and delete __thv_* prefixed keys directly.
func GetUserSecretsProvider ¶ added in v0.15.0
GetUserSecretsProvider returns a secrets provider suitable for user-facing callers (CLI, API, MCP tool server). It filters out system-reserved keys so user commands cannot accidentally read or overwrite internal secrets.
func IsWorkloadOwnedSecretName ¶ added in v0.70.1
IsWorkloadOwnedSecretName reports whether name has one of the two shapes GenerateUniqueSecretNameWithPrefix can emit for workloadName with the given prefix: the exact base "<prefix><workloadName>" or the suffixed "<prefix><workloadName>_<digits>_<8 lowercase hex>" form.
This is a name-shape check, not provenance. It is unambiguous only when no other workload name ends in "_<digits>_<8 hex>": workload names allow '_', so a secret owned by workload "foo_1_ab12cd34" also matches the suffixed shape for workload "foo". Anchoring only rules out the plain-prefix collision ("foo" vs "foo_1"); it cannot distinguish a generated suffix from a base name that happens to look like one. Callers deleting another workload's ref from imported config need provenance recorded alongside the ref, which this predicate does not provide. An empty workload name never proves ownership.
func ProcessSecret ¶
ProcessSecret processes a secret, converting plain text to CLI format if needed. This is a generic function that can be used for any secret type. Parameters:
- workloadName: Name of the workload (used for secret naming)
- secretValue: The secret value (plain text or already in CLI format)
- tokenType: The type of token/secret (determines prefix, target, and error context)
Returns the secret in CLI format: "secret-name,target=target_value"
func ProcessSecretWithProvider ¶
func ProcessSecretWithProvider( workloadName, secretValue string, secretManager secrets.Provider, tokenType TokenType, ) (string, error)
ProcessSecretWithProvider processes a secret using the provided secret manager This version is testable with dependency injection and is used for testing
func StoreSecretInManagerWithProvider ¶
func StoreSecretInManagerWithProvider(ctx context.Context, secretName, secretValue string, secretManager secrets.Provider) error
StoreSecretInManagerWithProvider stores a secret using the provided secret manager This version is testable with dependency injection
Types ¶
type TokenType ¶
type TokenType string
TokenType represents the type of authentication token/secret being processed
const ( // TokenTypeOAuthClientSecret represents an OAuth client secret // #nosec G101 - this is a type identifier, not a credential TokenTypeOAuthClientSecret TokenType = "oauth_client_secret" // TokenTypeBearerToken represents a bearer token TokenTypeBearerToken TokenType = "bearer_token" // TokenTypeOAuthRefreshToken represents a cached OAuth refresh token // #nosec G101 - this is a type identifier, not a credential TokenTypeOAuthRefreshToken TokenType = "oauth_refresh_token" )