Documentation
¶
Overview ¶
Package ssk provides a Vault Transit Engine compatible API server that enables SOPS to use Sakura Cloud KMS for data key encryption.
Wrapper Mode ¶
The primary use case is as a SOPS wrapper via the command-line tool. See the cmd/sops-sakura-kms package for the CLI entrypoint.
Library Usage ¶
You can also use this package as a Go library to embed Sakura Cloud KMS-based SOPS decryption in your applications. Use RunServer to start the Vault Transit Engine compatible server, then use the SOPS decrypt package to decrypt files.
addEnv, shutdown, err := ssk.RunServer(ctx, "127.0.0.1:8200", keyID) // uses env vars
Or with a pre-configured saclient:
addEnv, shutdown, err := ssk.RunServer(ctx, "127.0.0.1:8200", keyID, ssk.WithClient(client))
if err != nil {
return err
}
defer shutdown(context.Background())
for k, v := range addEnv {
os.Setenv(k, v)
}
plaintext, err := decrypt.File("secrets.enc.yaml", "yaml")
Environment Variables ¶
The following environment variables must be set:
- SAKURACLOUD_ACCESS_TOKEN: Sakura Cloud API access token
- SAKURACLOUD_ACCESS_TOKEN_SECRET: Sakura Cloud API access token secret
For wrapper mode, also set:
- SAKURACLOUD_KMS_KEY_ID: Sakura Cloud KMS resource ID (12-digit number)
Index ¶
- Constants
- Variables
- func DecryptHandlerFunc(cipher Cipher) func(w http.ResponseWriter, r *http.Request)
- func EncryptHandlerFunc(cipher Cipher) func(w http.ResponseWriter, r *http.Request)
- func NewMux(cipher Cipher) *http.ServeMux
- func RunServer(ctx context.Context, addr, keyID string, opts ...Option) (map[string]string, func(context.Context) error, error)
- func RunWrapper(ctx context.Context, args []string) (int, error)
- func ShowVersion(ctx context.Context, w io.Writer) (int, error)
- type Cipher
- type Env
- type Option
- type SakuraKMS
- type VaultDecryptRequest
- type VaultDecryptResponse
- type VaultEncryptRequest
- type VaultEncryptResponse
- type VaultErrorResponse
Constants ¶
const ( VaultPrefix = "vault:v1:" KeyIDPathParam = "key_id" // ExitCodeError is the exit code returned when an error occurs in the application. ExitCodeError = 1 )
Variables ¶
var IsStdinTerminal = func() bool { return isatty.IsTerminal(os.Stdin.Fd()) }
IsStdinTerminal reports whether stdin is a terminal. It is a package variable so tests can substitute their own check; production callers should leave it alone.
var Version = "v0.5.1"
Functions ¶
func DecryptHandlerFunc ¶
func DecryptHandlerFunc(cipher Cipher) func(w http.ResponseWriter, r *http.Request)
DecryptHandlerFunc returns an HTTP handler for Vault Transit Engine decrypt endpoint.
func EncryptHandlerFunc ¶
func EncryptHandlerFunc(cipher Cipher) func(w http.ResponseWriter, r *http.Request)
EncryptHandlerFunc returns an HTTP handler for Vault Transit Engine encrypt endpoint.
func NewMux ¶
NewMux creates a new HTTP ServeMux with Vault Transit Engine compatible API endpoints.
func RunServer ¶ added in v0.3.0
func RunServer(ctx context.Context, addr, keyID string, opts ...Option) (map[string]string, func(context.Context) error, error)
RunServer starts the Vault Transit Engine compatible API server. Without options, it uses Sakura Cloud KMS with credentials from environment variables. Use WithCipher to provide a custom cipher, or WithClient to provide a pre-configured saclient. Returns environment variables to configure SOPS, a shutdown function, and any error that occurred.
func RunWrapper ¶
RunWrapper starts a Vault Transit Engine compatible API server and executes a command. It automatically configures SOPS to use Sakura Cloud KMS via SOPS_VAULT_URIS environment variable. Requires SAKURA_KMS_KEY_ID environment variable to be set. Returns the exit code of the executed command and any error that occurred.
Types ¶
type Cipher ¶
type Cipher interface {
// Encrypt encrypts plaintext using the specified key ID.
// Returns base64-encoded ciphertext string.
Encrypt(ctx context.Context, keyID string, plaintext []byte) (string, error)
// Decrypt decrypts ciphertext using the specified key ID.
// Accepts base64-encoded ciphertext string and returns plaintext bytes.
Decrypt(ctx context.Context, keyID string, ciphertext string) ([]byte, error)
}
Cipher defines the interface for encryption and decryption operations.
type Env ¶ added in v0.0.5
type Option ¶ added in v0.4.1
type Option func(*serverOptions)
Option is a functional option for RunServer.
func WithCipher ¶ added in v0.4.1
WithCipher sets a custom Cipher implementation. Useful for testing.
func WithClient ¶ added in v0.4.1
WithClient sets a saclient.ClientAPI for creating the KMS cipher. This takes precedence over the default environment variable-based client.
type SakuraKMS ¶
type SakuraKMS struct {
// contains filtered or unexported fields
}
SakuraKMS implements Cipher interface using Sakura Cloud KMS.
func NewSakuraKMS ¶
NewSakuraKMS creates a new SakuraKMS instance. It reads credentials from environment variables (SAKURACLOUD_ACCESS_TOKEN, SAKURACLOUD_ACCESS_TOKEN_SECRET).
func NewSakuraKMSWithClient ¶ added in v0.4.1
NewSakuraKMSWithClient creates a new SakuraKMS instance with the given saclient.ClientAPI.
type VaultDecryptRequest ¶
type VaultDecryptRequest struct {
Ciphertext string `json:"ciphertext"`
}
VaultDecryptRequest represents the request body for Vault Transit Engine decrypt API. Ciphertext must include "vault:v1:" prefix.
type VaultDecryptResponse ¶
type VaultDecryptResponse struct {
Plaintext string `json:"plaintext"`
}
VaultDecryptResponse represents the response body for Vault Transit Engine decrypt API. Plaintext is returned as base64-encoded string.
type VaultEncryptRequest ¶
type VaultEncryptRequest struct {
Plaintext string `json:"plaintext"`
}
VaultEncryptRequest represents the request body for Vault Transit Engine encrypt API. Plaintext must be base64-encoded string.
type VaultEncryptResponse ¶
type VaultEncryptResponse struct {
Ciphertext string `json:"ciphertext"`
}
VaultEncryptResponse represents the response body for Vault Transit Engine encrypt API. Ciphertext includes "vault:v1:" prefix followed by the encrypted data.
type VaultErrorResponse ¶ added in v0.0.3
type VaultErrorResponse struct {
Errors []string `json:"errors"`
}
VaultErrorResponse represents the error response body for Vault API. Errors is an array of error message strings.