Documentation ¶
Index ¶
- Constants
- Variables
- type SecretDefinition
- type SecretMapper
- type SecretsClient
- type SecretsClientOption
- func WithEnvVarBackend() SecretsClientOption
- func WithFileTreeBackend(rootPath string) SecretsClientOption
- func WithJSONFileBackend(path string) SecretsClientOption
- func WithMapping(mapping string) SecretsClientOption
- func WithVaultAuthRetries(retries uint) SecretsClientOption
- func WithVaultAuthRetryDelay(secs uint) SecretsClientOption
- func WithVaultBackend(auth VaultAuthentication, host string) SecretsClientOption
- func WithVaultK8sAuth(jwt, role string) SecretsClientOption
- func WithVaultK8sAuthPath(path string) SecretsClientOption
- func WithVaultRoleID(roleid string) SecretsClientOption
- func WithVaultToken(token string) SecretsClientOption
- func WithVaultValueKey(key string) SecretsClientOption
- type VaultAuthentication
Constants ¶
const ( DefaultFileTreeMapping = "{{ .ID }}" DefaultFileTreeRootPath = "/vault/secrets" )
Default mapping for this backend
const (
DefaultEnvVarMapping = "SECRET_{{ .ID }}" // DefaultEnvVarMapping is uppercased after interpolation for convenience
)
Default mapping for this backend
const (
DefaultJSONFileMapping = "{{ .ID }}"
)
Default mapping for this backend
const (
DefaultVaultMapping = "secret/{{ .ID }}"
)
Default mapping for this backend
Variables ¶
var DefaultVaultValueKey = "value"
var MaxFileTreeFileSizeBytes int64 = 2_000_000 // 2 MB
MaxFileTreeSizeBytes indicates the maximum file size we will read
var SecretStructTag = "secret"
SecretStructTag is the default struct tag name
Functions ¶
This section is empty.
Types ¶
type SecretDefinition ¶
type SecretDefinition struct { ID string // arbitrary identifier for this secret VaultPath string // path in Vault (no leading slash, eg "secret/foo/bar") EnvVarName string // environment variable name JSONKey string // key in JSON object }
SecretDefinition defines a secret and how it can be accessed via the various backends
type SecretMapper ¶
SecretMapper maps secrets
type SecretsClient ¶
type SecretsClient struct {
// contains filtered or unexported fields
}
SecretsClient is the client that retrieves secret values
func NewSecretsClient ¶
func NewSecretsClient(ops ...SecretsClientOption) (*SecretsClient, error)
NewSecretsClient returns a SecretsClient configured according to the SecretsClientOptions supplied. Exactly one backend must be enabled. Weird things will happen if you mix options with incompatible backends.
func (*SecretsClient) Fill ¶
func (sc *SecretsClient) Fill(s interface{}) error
Fill takes a pointer to any struct type and fills any fields annotated with SecretStructTag secret ids. Annotated fields must *only* be string or []byte, any other type will cause this method to return an error. Note that Fill doesn't check the secret type; if the field value is a string, the byte slice returned by the backend for that secret will be converted to a string.
type SecretsClientOption ¶
type SecretsClientOption func(*secretsClientConfig)
SecretsClientOption defines options when creating a SecretsClient
func WithEnvVarBackend ¶
func WithEnvVarBackend() SecretsClientOption
WithEnvVarBackend enables the environment variable backend. Any characters in the secret ID that are not alphanumeric ASCII or underscores (legal env var characters) will be replaced by underscores after mapping.
func WithFileTreeBackend ¶
func WithFileTreeBackend(rootPath string) SecretsClientOption
WithFileTree enables the FileTreeBackend. With this backend, PVC reads one individual file per secret ID. Sub-paths under the root should be implemented with directory separators in the secret ID. The path that results from the root path + secret ID mapping will be read as the secret. This must be an absolute filesystem path.
func WithJSONFileBackend ¶
func WithJSONFileBackend(path string) SecretsClientOption
WithJSONFileBackend enables the JSON file backend. The file should contain a single JSON object associating a name with a value: { "mysecret": "pa55w0rd"}. Path is required and must be a valid path to the JSON file.
func WithMapping ¶
func WithMapping(mapping string) SecretsClientOption
WithMapping sets the template string mapping to determine the location for each secret in the backend. The secret ID will be interpolated as ".ID". Example (Vault Backend): "secret/foo/bar/{{ .ID }}". Example (Env Var Backend): "MYAPP_SECRET_{{ .ID }}" Example (JSON Backend): "{{ .ID }}"
func WithVaultAuthRetries ¶
func WithVaultAuthRetries(retries uint) SecretsClientOption
WithVaultAuthRetries sets the number of retries if authentication fails (default: 0)
func WithVaultAuthRetryDelay ¶
func WithVaultAuthRetryDelay(secs uint) SecretsClientOption
WithVaultAuthRetryDelay sets the delay in seconds between authentication attempts (default: 0)
func WithVaultBackend ¶
func WithVaultBackend(auth VaultAuthentication, host string) SecretsClientOption
WithVaultBackend enables the Vault backend with the requested authentication type and host (ex: https//my.vault.com:8300)
func WithVaultK8sAuth ¶
func WithVaultK8sAuth(jwt, role string) SecretsClientOption
WithVaultK8sAuth sets the Kubernetes JWT and role to use for authentication
func WithVaultK8sAuthPath ¶
func WithVaultK8sAuthPath(path string) SecretsClientOption
WithVaultK8sAuthPath sets the path for the k8s Vault auth backend (defaults to "kubernetes" otherwise)
func WithVaultRoleID ¶
func WithVaultRoleID(roleid string) SecretsClientOption
WithVaultRoleID sets the RoleID when using AppRole authentication
func WithVaultToken ¶
func WithVaultToken(token string) SecretsClientOption
WithVaultToken sets the token to use when using token auth
func WithVaultValueKey ¶
func WithVaultValueKey(key string) SecretsClientOption
type VaultAuthentication ¶
type VaultAuthentication int
VaultAuthentication enumerates the supported Vault authentication methods
const ( UnknownVaultAuth VaultAuthentication = iota // Unknown/unset TokenVaultAuth // Token authentication AppRoleVaultAuth // AppRole K8sVaultAuth // Kubernetes )
Supported Vault authentication methods