Documentation
¶
Index ¶
- func IsForbidden(err error) bool
- func ReadSecondsField(data map[string]any, key string) (int64, bool)
- type Client
- func (c *Client) DeleteKVv2(ctx context.Context, mount, path string) error
- func (c *Client) EnableKVv2(ctx context.Context, path string) error
- func (c *Client) IssueCertificate(ctx context.Context, mount, role, commonName, ttl string) (*IssuedCert, error)
- func (c *Client) ListKVv2(ctx context.Context, mount, path string) ([]string, error)
- func (c *Client) LoginCert(ctx context.Context, mount, role string) error
- func (c *Client) LoginLDAP(ctx context.Context, mount, username, password string) (*LoginResult, error)
- func (c *Client) LookupSelf(ctx context.Context) (*vaultapi.Secret, error)
- func (c *Client) Raw() *vaultapi.Client
- func (c *Client) ReadKVv2(ctx context.Context, mount, path string) (*Secret, error)
- func (c *Client) RenewSelf(ctx context.Context, increment int) (*vaultapi.Secret, error)
- func (c *Client) ServerHealth(ctx context.Context) (*HealthResponse, error)
- func (c *Client) SetToken(token string)
- func (c *Client) SignCSR(ctx context.Context, mount, role, csrPEM, commonName, ttl string) (*IssuedCert, error)
- func (c *Client) SubscribeEvents(ctx context.Context, eventType string) (<-chan Event, <-chan error, error)
- func (c *Client) Token() string
- func (c *Client) ValidateMFA(ctx context.Context, mfaRequestID, methodID, passcode string) (string, error)
- func (c *Client) WriteKVv2(ctx context.Context, mount, path string, data map[string]any) error
- type Config
- type Event
- type HealthResponse
- type IssuedCert
- type LoginResult
- type MFAMethod
- type Secret
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsForbidden ¶
IsForbidden returns true if the error is a Vault 403 response, indicating the token is invalid, revoked, or lacks permissions.
func ReadSecondsField ¶
ReadSecondsField extracts an integer-seconds value from a Vault secret data map, handling the json.Number / float64 / int variants the underlying decoder may produce. Returns (0, false) when the key is missing or the value isn't a parseable number.
Lives in internal/vault because every call site is reading a field off a *vaultapi.Secret's data map. Used by the lifecycle manager for ttl / creation_ttl and by the CLI login-check for the same fields; centralising avoids the duplicated type switch silently diverging (e.g. when a future Vault SDK change introduces a uint64 wire form).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Vault API client.
func (*Client) DeleteKVv2 ¶
DeleteKVv2 deletes all versions of a KVv2 secret (the full metadata record, not just a soft-delete of the latest version). Used by the refresh manager when the upstream credential has been permanently revoked and the local state needs to be wiped so the user can re-enrol.
func (*Client) EnableKVv2 ¶
EnableKVv2 enables a KVv2 secrets engine at the given path. Used for testing. Returns an error if it already exists (non-fatal).
func (*Client) IssueCertificate ¶ added in v0.23.0
func (c *Client) IssueCertificate(ctx context.Context, mount, role, commonName, ttl string) (*IssuedCert, error)
IssueCertificate asks the PKI engine to generate a keypair and certificate. Used only when the PKI role forbids the sign endpoint; the returned PrivateKeyPEM must be handed to the secure store immediately.
func (*Client) LoginCert ¶ added in v0.23.0
LoginCert authenticates via the TLS cert auth method. The client must have been built with a ClientCert so the certificate is presented during the handshake; Vault matches it against the registered CA and the named role's policies. On success the returned token is adopted onto the client.
func (*Client) LoginLDAP ¶
func (c *Client) LoginLDAP(ctx context.Context, mount, username, password string) (*LoginResult, error)
LoginLDAP authenticates via LDAP and detects if MFA is required.
func (*Client) LookupSelf ¶
LookupSelf returns the current token's metadata, or an error if invalid.
func (*Client) ReadKVv2 ¶
ReadKVv2 reads a KVv2 secret at the given mount and path. Returns nil (not error) if the secret doesn't exist.
func (*Client) ServerHealth ¶
func (c *Client) ServerHealth(ctx context.Context) (*HealthResponse, error)
ServerHealth returns the Vault server health status.
func (*Client) SignCSR ¶ added in v0.23.0
func (c *Client) SignCSR(ctx context.Context, mount, role, csrPEM, commonName, ttl string) (*IssuedCert, error)
SignCSR submits a CSR to the PKI engine's sign endpoint and returns the signed certificate. The private key behind the CSR never leaves the host — this is the preferred issuance path for both mtls and mtls+tpm.
func (*Client) SubscribeEvents ¶
func (c *Client) SubscribeEvents(ctx context.Context, eventType string) (<-chan Event, <-chan error, error)
SubscribeEvents connects to the Vault Events API via WebSocket and returns a channel of events and an error channel. The caller should cancel the context to disconnect.
func (*Client) ValidateMFA ¶
func (c *Client) ValidateMFA(ctx context.Context, mfaRequestID, methodID, passcode string) (string, error)
ValidateMFA validates an MFA challenge. For push methods (Duo), pass an empty passcode — the call blocks until the user approves or the context is cancelled. For TOTP, pass the user-provided code. Returns the authenticated client token on success.
type Config ¶
type Config struct {
Address string
Token string
CACert string
TLSSkipVerify bool
// ClientCert, when non-nil, is presented during the TLS handshake. It is
// used by the cert auth method (mtls / mtls+tpm): the certificate's
// private key may be a hardware-backed crypto.Signer, so GetClientCertificate
// invokes it lazily per handshake rather than holding key bytes.
ClientCert *tls.Certificate
}
Config holds Vault connection settings.
type HealthResponse ¶
HealthResponse contains selected fields from the Vault health endpoint.
type IssuedCert ¶ added in v0.23.0
type IssuedCert struct {
// CertPEM is the leaf certificate followed by any CA chain, PEM-encoded.
CertPEM string
// PrivateKeyPEM is populated only by IssueCertificate (Vault generates the
// key). SignCSR leaves it empty because the key never left the host.
PrivateKeyPEM string
// Serial is the certificate serial number, for audit/revocation.
Serial string
}
IssuedCert is the result of a PKI issue or sign operation.
type LoginResult ¶
type LoginResult struct {
Token string
MFARequired bool
MFARequestID string
MFAMethods []MFAMethod
}
LoginResult holds the outcome of an LDAP login attempt.