kmstest

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package kmstest provides in-repo stand-ins for the key-management services pkg/kms speaks to (Task 20433): a Kubernetes KMS v2 plugin served over a real unix socket with the protocol's own generated server stubs, and a Vault Transit server over HTTP on loopback.

They are fakes of the KMS, not of the protocol: a test drives the real client, over the real transport, against a server that encrypts for real (AES-256-GCM under keys it holds and never shows) and can be made slow, unhealthy, unavailable, rotated or refusing. Neither keeps or logs a plaintext it is given, so a test scanning for leaked key material scans a fake that cannot be the leak.

Index

Constants

View Source
const AnnotationKey = "version.kmstest.cloop.dev"

AnnotationKey is the annotation the fake plugin returns with every ciphertext, naming the key version, as real plugins do (the Azure plugin's version.azure.akv.io, say). Decrypt requires it back.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin struct {
	kmsapi.UnimplementedKeyManagementServiceServer
	// contains filtered or unexported fields
}

Plugin is a fake KMS v2 plugin listening on a unix socket.

func NewPlugin

func NewPlugin() (*Plugin, error)

NewPlugin starts a plugin the caller stops with Stop and cleans up after with Cleanup — for a process that runs one beside the hubs it starts.

func StartPlugin

func StartPlugin(t testing.TB) *Plugin

StartPlugin starts a plugin with one key, "key-1", on a socket in a fresh directory only this user can write. It stops when the test ends.

func (*Plugin) Calls

func (p *Plugin) Calls(op string) int

Calls counts the calls of op the plugin has answered or failed.

func (*Plugin) Cleanup

func (p *Plugin) Cleanup()

Cleanup removes the plugin's directory. Stop first.

func (*Plugin) CurrentKeyID

func (p *Plugin) CurrentKeyID() string

CurrentKeyID is the key the plugin encrypts under.

func (*Plugin) Decrypt

Decrypt implements the protocol.

func (*Plugin) Encrypt

Encrypt implements the protocol.

func (*Plugin) Endpoint

func (p *Plugin) Endpoint() string

func (*Plugin) FailWith

func (p *Plugin) FailWith(op string, code codes.Code)

FailWith makes every call of op ("Status", "Encrypt", "Decrypt") fail with code; codes.OK clears it.

func (*Plugin) Restart

func (p *Plugin) Restart() error

Restart serves again on the same socket, with the same keys.

func (*Plugin) Rotate

func (p *Plugin) Rotate() string

Rotate adds a new key version and makes it current; old versions still decrypt, as a KMS's do. It returns the new key id.

func (*Plugin) SetDelay

func (p *Plugin) SetDelay(d time.Duration)

SetDelay makes every call take d before answering.

func (*Plugin) SetHealthz

func (p *Plugin) SetHealthz(s string)

SetHealthz sets what Status reports ("ok" when healthy).

func (*Plugin) Socket

func (p *Plugin) Socket() string

Socket is the plugin's socket path; Endpoint the same as an endpoint URL.

func (*Plugin) Status

Status implements the protocol.

func (*Plugin) Stop

func (p *Plugin) Stop()

Stop closes the socket: every call fails as a plugin that is not running.

type Transit

type Transit struct {
	Server *httptest.Server
	Mount  string
	Key    string
	// Token is the static token the server accepts.
	Token string
	// Role and JWT are what a Kubernetes login must present; the token it
	// issues expires after LeaseSeconds.
	Role         string
	JWT          string
	LeaseSeconds int
	// contains filtered or unexported fields
}

Transit is a fake Vault Transit server on loopback: one mount, one key with versions, token and Kubernetes-login authentication.

func StartTransit

func StartTransit(t testing.TB) *Transit

StartTransit starts the server with key version 1. It stops when the test ends.

func (*Transit) Calls

func (tr *Transit) Calls(op string) int

Calls counts requests by operation: encrypt, decrypt, keys, login.

func (*Transit) RevokeIssued

func (tr *Transit) RevokeIssued()

RevokeIssued invalidates every token a Kubernetes login issued.

func (*Transit) Rotate

func (tr *Transit) Rotate() int

Rotate adds a key version and makes it the latest. It returns its number.

func (*Transit) SetDelay

func (tr *Transit) SetDelay(d time.Duration)

SetDelay delays every answer by d.

func (*Transit) SetStatus

func (tr *Transit) SetStatus(code int)

SetStatus makes every request answer code (503 for a sealed Vault, 403 for a revoked policy); zero restores normal service.

func (*Transit) URL

func (tr *Transit) URL() string

URL is the server's address.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL