bootstrap

package
v1.0.296 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 9 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 bootstrap generates the one-click DP-node deployment artifacts: the shell install script and the docker-compose.yml that the Control Plane serves against a single-use enrollment token. Extracted from package main per ADR-0002 as a pure stdlib leaf: the HTTP handlers (token validation against the cluster store, CP address derivation from cluster state) stay in main; this package owns the templates, the image-reference resolution, and the pure request-derivation helpers — with main's trustForwardedHeaders global passed IN as a parameter.

Index

Constants

View Source
const DefaultImage = "ghcr.io/kidcarmi/culvert"

DefaultImage is the default container image; overridden by registry settings.

Variables

View Source
var ErrUnsafeArtifactValue = errors.New("bootstrap: refusing to render an artifact from an unvalidated value")

ErrUnsafeArtifactValue is returned when a value handed to a renderer is not provably safe to interpolate into a root-executed artifact. It is a refusal, never a request to sanitise and continue: callers must abandon the render.

Functions

func BaseURL

func BaseURL(r *http.Request, trustForwarded bool) (string, bool)

BaseURL derives the CP's external base URL from the incoming request. trustForwarded is main's trustForwardedHeaders setting, passed in so the package stays free of main's globals. It is FAIL-CLOSED: the derived authority must be a plain host[:port] (SafeAuthority). A caller that ignores the second return value and renders the first anyway reintroduces SEC-BOOTSTRAP-HOST-1 — see hostsafety.go.

func EnrollmentAddr

func EnrollmentAddr(r *http.Request, grpcListenAddr string, trustForwarded bool) (string, bool)

EnrollmentAddr derives the gRPC Control Plane address for the enrollment URL. Uses the HTTP request's host (the IP/hostname the admin used to access the UI) combined with the gRPC port from the configured listen address. IPv6-safe: strips brackets before net.JoinHostPort to prevent double-bracketing. It is FAIL-CLOSED for the same reason BaseURL is: the result is interpolated into the compose document a DP node runs (SEC-BOOTSTRAP-HOST-1).

func ExtractToken

func ExtractToken(path, prefix string) string

ExtractToken extracts the token segment from a bootstrap URL path. For /api/cluster/bootstrap/abc123 → "abc123" For /api/cluster/bootstrap/abc123/compose → "abc123"

func Image

func Image(settingsPath, version string) string

Image returns the image reference for DP nodes, checking registry settings first, falling back to the default ghcr.io image with the current version.

func RenderCompose

func RenderCompose(w io.Writer, image, enrollURL string) error

RenderCompose writes the docker-compose.yml for the given image ref and enrollment URL.

FAIL-CLOSED for the same reason RenderScript is (SEC-BOOTSTRAP-HOST-1): the enrollment URL carries a request-derived authority and the compose document is run by the DP node. Both values are re-validated at the sink.

func RenderScript

func RenderScript(w io.Writer, cpHost, cpBase, token string) error

RenderScript writes the install script for the given CP host/base and enrollment token.

FAIL-CLOSED (SEC-BOOTSTRAP-HOST-1): cpHost/cpBase are derived from request headers and token from the URL path, and the output is documented to be piped into `sudo bash`. Every one of them is re-validated HERE, at the sink, even though the handler validated at the source — the renderer is the last place that can still refuse, and it must not depend on a caller having done so. A caller that has not validated gets an error and an unwritten stream, never a partially-rendered script.

func SafeAuthority added in v1.0.247

func SafeAuthority(authority string) (string, bool)

SafeAuthority validates an "host" or "host:port" authority taken from an untrusted request and returns it in canonical form.

It accepts exactly three shapes:

a DNS name          cp.example.com          cp.example.com:9090
an IPv4 literal     10.0.0.7                10.0.0.7:9090
an IPv6 literal     [2001:db8::1]           [2001:db8::1]:9090
…with a zone id     [fe80::1%eth0]          [fe80::1%eth0]:9090

Everything else — an empty host, a shell metacharacter, a space, a port that is not a decimal 1-65535, a bare unbracketed IPv6 address, a userinfo or path fragment — is refused. The second return value is the ONLY signal callers may act on; the string is empty when it is false.

func SafeEnrollURL added in v1.0.247

func SafeEnrollURL(u string) bool

SafeEnrollURL reports whether u is a culvert:// enrollment URL built from values this appliance controls: an authority SafeAuthority accepts, a token SafeToken accepts, and a lowercase-hex SHA-256 CA fingerprint.

It parses the shape rather than scanning a charset, because "no dangerous byte" is a claim that has to be re-argued every time the sink changes, while "this is the URL we build" stays true.

func SafeImageRef added in v1.0.247

func SafeImageRef(ref string) bool

SafeImageRef reports whether ref is a plain OCI image reference: [host[:port]/]path[:tag] over [A-Za-z0-9._:/@-], 1-512 bytes, no whitespace and no shell or YAML metacharacter.

The reference is read from an operator-managed settings file and rendered into the compose document the DP node runs, so it is trusted-but-verified: a value that fails here falls back to the built-in default rather than reaching the artifact.

func SafeToken added in v1.0.247

func SafeToken(tok string) bool

SafeToken reports whether tok is a Culvert enrollment token in the shape this appliance mints: base64url without padding (ClusterStore.GenerateToken), i.e. 1-128 bytes of [A-Za-z0-9-_].

The handler has already proved the token exists in the cluster store before this is reached, so in production this can only fail if the store itself is carrying something it did not mint. It is checked anyway because the token is the second value interpolated into the root-executed script, and a template whose safety rests on "the other end only ever stores well-formed values" is one storage change away from being an injection sink again.

Types

This section is empty.

Jump to

Keyboard shortcuts

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