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)
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) (map[string]string, func(context.Context) error, error)
- func RunWrapper(ctx context.Context, args []string) (int, error)
- type Cipher
- type Env
- 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 Version = "v0.3.0"
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) (map[string]string, func(context.Context) error, error)
RunServer starts the Vault Transit Engine compatible API server. 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 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).
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.