secrets

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: GPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package secrets manages the credential files a stack reads at runtime.

The pattern it formalises was arrived at by hand three times: a value is generated on the machine that will use it, written beside the stack at 0600, and referenced from the compose file rather than embedded in it. Compose files are reviewed, committed and shared; the things they need to authenticate with must not be.

Index

Constants

View Source
const (
	MarkerWritten = "hlab:secret-written"
	MarkerMissing = "hlab:secret-missing"
)

Markers the scripts print.

View Source
const DefaultLength = 32

DefaultLength is how many characters a generated secret gets.

32 of this alphabet is a little under 190 bits, which is far past anything that matters here and still short enough to retype off a screen if something has gone badly wrong.

View Source
const ListScript = `` /* 720-byte string literal not displayed */

ListScript reports the secrets a machine holds, and never their values.

The whole walk runs under sudo: stack directories are 0750 and root-owned, so an unprivileged shell cannot expand a glob inside them and would report a machine full of credentials as having none.

What counts as a secret is deliberately narrow. Listing every file beside a stack drowns the answer — Technitium alone keeps hundreds of blocklist and statistics files there. A file qualifies if its mode says somebody restricted it, or if its name says what it holds. The two together catch a credential that was *meant* to be private but is not, which is the case worth shouting about.

View Source
const StackDir = "/opt/hlab/stacks"

StackDir is where a stack's files live on a managed machine.

View Source
const StageCommand = "sh -c 'cat > /tmp/hlab-secret-value'"

StageCommand receives the secret's value on stdin, and nothing else.

The value must not share a stream with the script that stores it. Feeding both to `sudo -n sh -s` does not work and does not fail loudly: sudo hands the entire stream to the shell, which reads the appended value as another line of *script* and tries to execute it. The secret is silently empty and the credential has been passed to a shell as a command. Staging it through its own invocation is the only way the two stay separate.

Variables

This section is empty.

Functions

func BuildGenerateScript

func BuildGenerateScript(o Options) (string, error)

BuildGenerateScript renders the script that creates a secret on the machine.

func BuildSetScript

func BuildSetScript(o Options) (string, error)

BuildSetScript renders the script that stores a value read from stdin.

func BuildShowScript

func BuildShowScript(stack, file string) (string, error)

BuildShowScript renders the script that prints one secret's value.

func ValidateFile

func ValidateFile(name string) error

ValidateFile rejects anything that would write outside the stack directory.

The name becomes a path in a script running as root, so this is a security control rather than tidiness. One level of "config/" is allowed because that is where several images expect to read from.

func ValidateKey

func ValidateKey(key string) error

ValidateKey rejects env keys that are not env keys.

func ValidateName

func ValidateName(name string) error

ValidateName rejects a stack name that would escape the stack directory.

Types

type Options

type Options struct {
	// Stack is the stack directory the secret belongs to.
	Stack string
	// File is the file's name inside that directory.
	File string
	// Key, when set, makes this one entry in an env file rather than a file
	// whose whole content is the secret.
	Key string
	// Length is how many characters to generate.
	Length int
	// Force replaces an existing secret.
	Force bool
}

Options describe one secret.

Jump to

Keyboard shortcuts

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