artifacts

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 27 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 artifacts orchestrates the ocfp-artifacts VM (RustFS S3 blobstore). The VM runs RustFS on a ZFS dataset and serves the BOSH director plus all Cloud Foundry blobstore buckets for the bloc. Opt-in via Artifacts.Enabled.

Index

Constants

View Source
const ResourceType = "artifacts"

ResourceType is the state.Resource Type for the artifacts VM.

Variables

View Source
var (
	// ErrDisabled is returned when CreateArtifacts is called but the feature is opted-out.
	// Callers use this to short-circuit cleanly without surfacing an error to the user.
	ErrDisabled = errors.New("artifacts feature disabled")

	// ErrProviderUnsupported is returned when a non-PVE provider is in use.
	ErrProviderUnsupported = errors.New("artifacts requires the pve provider in v1")

	// ErrBlocNameRequired is returned when the bloc name is empty.
	ErrBlocNameRequired = errors.New("bloc name is required")

	// ErrSubnetRequired is returned when no usable subnet is configured.
	ErrSubnetRequired = errors.New("bloc subnet is required for artifacts IP allocation")

	// ErrReadinessTimeout is returned when the RustFS S3 endpoint does not respond
	// within the configured wait window after VM boot.
	ErrReadinessTimeout = errors.New("artifacts RustFS endpoint readiness probe timed out")

	// ErrSecretRotationRequiresReset is returned by RotateCredentials when
	// the --reset-all flag is not provided. RustFS issue #2852 invalidates
	// previously issued keys on secret rotation, so the operator must
	// acknowledge the blast radius explicitly.
	ErrSecretRotationRequiresReset = errors.New("rotating RustFS credentials invalidates all keys; pass --reset-all to confirm")

	// ErrCABlocNameRequired is returned when GenerateInternalCA is called with
	// an empty bloc name.
	ErrCABlocNameRequired = errors.New("bloc name required for CA generation")

	// ErrCAMaterialIncomplete is returned when IssueLeafCert is called with
	// a CAMaterial that is missing the cert or key PEM.
	ErrCAMaterialIncomplete = errors.New("CA material missing cert or key")

	// ErrCACertPEMInvalid is returned when the CA cert PEM cannot be decoded
	// as a CERTIFICATE block.
	ErrCACertPEMInvalid = errors.New("CA cert PEM is not a CERTIFICATE block")

	// ErrCAKeyPEMInvalid is returned when the CA key PEM cannot be decoded.
	ErrCAKeyPEMInvalid = errors.New("CA key PEM not decodable")

	// ErrCACertNoPEM is returned by newS3Client when the supplied CA cert
	// PEM contains no parseable certificates.
	ErrCACertNoPEM = errors.New("artifacts CA cert: no certificates parsed")
)

Sentinel errors for the artifacts package.

View Source
var ErrArtifactsCAMissing = errors.New("artifacts CA missing from state/vault")

ErrArtifactsCAMissing is returned by EndpointForLookup when an https artifacts endpoint is configured for tls.mode=internal-ca but no CA certificate is available from state or vault. Trust decisions never fall back to skipping verification in this case — the caller must recover or re-mint the bloc CA first.

View Source
var ErrArtifactsEndpointInvalid = errors.New("artifacts endpoint URL must start with http:// or https://")

ErrArtifactsEndpointInvalid is returned by EndpointForLookup when the endpoint URL is empty or does not start with http:// or https://.

View Source
var ErrArtifactsInsecureOptInRequired = errors.New("artifacts endpoint has no CA cert; explicit insecure opt-in required")

ErrArtifactsInsecureOptInRequired is returned by EndpointForLookup when an https self-signed artifacts endpoint has no CA cert to pin to and the caller has not explicitly opted into skipping TLS verification.

Functions

func ArtifactsLeafSANIPs

func ArtifactsLeafSANIPs(vmIP net.IP) []net.IP

ArtifactsLeafSANIPs builds the canonical IP SAN set for an artifacts VM leaf certificate (self-signed or internal-ca): the VM's private IP (when resolvable) plus the loopback addresses 127.0.0.1 and ::1. Without the loopback entries, clients running ON the artifacts VM itself (the provisioning script, `curl https://127.0.0.1:9000` health checks, RustFS's own bucket-creation step) can never pass certificate verification against anything but the VM's SDN IP, forcing SkipTLSVerify on-box even when the operator wants full verification everywhere else.

vmIP may be nil (e.g. the caller could not parse a recorded IP); the loopback addresses are still returned so on-VM verification keeps working.

func CanonicalBucketNames

func CanonicalBucketNames(blocName string) []string

CanonicalBucketNames enumerates the bucket names to create on a bloc's artifacts S3 endpoint, in a stable order. This is the single source of truth for the roster: one bucket per BOSH director (mgmt and ocf/env), four buckets for the CF cloud-controller blobstore (droplets, packages, buildpacks, resource-pool), and one SHIELD archive bucket per tier (the mgmt SHIELD core stores mgmt-tier backups in -mgmt-shield and ocf-tier backups in -ocf-shield). Both the bootstrap create path (internal/bootstrap) and the `artifacts provision` command (internal/commands) must call this instead of maintaining their own lists, so the two provisioning paths never drift out of sync with each other.

func DescribeVaultAddrAttempt

func DescribeVaultAddrAttempt() string

DescribeVaultAddrAttempt reports, for diagnostic error text, the vault address a plain env-driven vault client (vault.NewManagerFromEnv / vault.NewClientFromEnv) would attempt to reach: VAULT_ADDR when set, otherwise the documented fallback chain (~/.saferc target, then https://127.0.0.1:8200). This does not replicate the ~/.saferc parsing itself — it only describes the fallback so operators know what to check without duplicating that (unexported) logic across packages.

func EnsureBuckets

func EnsureBuckets(ctx context.Context, ep Endpoint, creds Credentials, buckets []BucketSpec) error

EnsureBuckets is idempotent: each bucket is created if absent, ignored if already owned by the caller. Returns the first non-recoverable error.

The S3 client is built per-call so this helper has no shared state. Suitable for both the bootstrap step and the readiness probe path.

func InternalCAVaultError

func InternalCAVaultError(blocName string, cause error) error

InternalCAVaultError builds an actionable error for the case where tls.mode=internal-ca needs vault access (to read/mint the bloc CA at secret/ocfp/{bloc}/ca) but vault is unreachable or unauthenticated. The message names, in order: (1) the fix to start the inception vault, (2) the env/`safe target` fallback already attempted, and (3) the self-signed escape hatch — plus the bloc name and the vault address that was tried, so operators are not left guessing which vault failed or why.

func NewS3Client

func NewS3Client(ep Endpoint, creds Credentials) (*s3.Client, error)

NewS3Client builds an AWS SDK v2 S3 client for the artifacts RustFS endpoint, applying the same path-style + CA/SkipTLSVerify TLS matrix used internally for bucket creation. Exported so other packages (e.g. precompile) can reuse the exact RustFS-compatible client without duplicating the TLS logic.

func Probe

func Probe(ctx context.Context, ep Endpoint, creds Credentials) error

Probe verifies the endpoint is responding by issuing a ListBuckets call. Used as the readiness gate after VM creation.

Types

type BucketSpec

type BucketSpec struct {
	Name string
}

BucketSpec names a bucket to create on the artifacts S3 endpoint.

func CanonicalBuckets

func CanonicalBuckets(blocName string) []BucketSpec

CanonicalBuckets wraps CanonicalBucketNames as []BucketSpec for callers (EnsureBuckets) that need the spec shape rather than plain strings.

type CAMaterial

type CAMaterial struct {
	CertPEM     string
	KeyPEM      string
	Fingerprint string // sha256, lowercase hex, colon-free
}

CAMaterial is a CA certificate, its private key, and a stable SHA-256 fingerprint of the DER-encoded certificate. The fingerprint identifies the bloc CA for verification by operators and downstream genesis kits.

func GenerateInternalCA

func GenerateInternalCA(blocName string) (CAMaterial, error)

GenerateInternalCA mints a fresh per-bloc CA certificate and key pair. The CA is ECDSA P-256 with 10-year validity, CN "ocfp-{bloc}-internal-ca", and key usage CertSign|CRLSign. IsCA is true and BasicConstraints are marked critical so downstream verifiers honor the constraint.

type Credentials

type Credentials struct {
	AccessKey string
	SecretKey string
}

Credentials hold the RustFS root access/secret pair. The pair is also the effective S3 credential for BOSH + CF buckets in v1 (RustFS lacks an admin CLI for per-user keys at beta).

func GenerateCredentials

func GenerateCredentials() (Credentials, error)

GenerateCredentials produces a fresh random RustFS credential pair using crypto/rand. The hex encoding is S3-compatible and tolerates being written verbatim into systemd EnvironmentFile values (no quoting needed).

func ResolveCredentials

func ResolveCredentials(provided Credentials) (Credentials, error)

ResolveCredentials returns the provided credentials when both fields are non-empty, otherwise generates a fresh pair. Mixed states (one provided, one empty) are treated as "regenerate both" to avoid orphaning a key.

type Endpoint

type Endpoint struct {
	URL           string
	Host          string
	Port          int
	Region        string
	PathStyle     bool
	CACert        string // empty when TLS is disabled
	SkipTLSVerify bool   `json:"skip_tls_verify" yaml:"skip_tls_verify"` // operators using self-signed certs must set this explicitly
}

Endpoint is the resolved RustFS S3 endpoint for the artifacts VM. URL is the full https://host:port (or http:// when TLS is disabled). PathStyle is always true for RustFS. Region is "us-east-1" (SigV4 needs a value; unused by RustFS).

func EndpointForLookup

func EndpointForLookup(blocName, endpointURL, tlsMode, caCert string, allowInsecure bool) (Endpoint, error)

EndpointForLookup derives the S3 Endpoint (base URL plus TLS trust material) an artifacts client should use, from the raw fields a caller has resolved out of state and/or vault: the endpoint URL, the configured tls.mode, and any CA certificate PEM already recovered. It is the single place the mode × cert-presence × scheme trust decision is made, so callers (precompile, the PVE vault provider, future providers) do not each reimplement — or diverge on — when it is safe to skip TLS verification.

blocName is used only to make returned errors actionable; it does not affect the trust decision.

Decision table:

  • endpointURL empty, or missing an http(s):// scheme → ErrArtifactsEndpointInvalid.
  • caCert non-empty → always CA-pool pinning, regardless of tlsMode. A recovered CA is trust material; use it.
  • scheme is http (not https) → no TLS material is meaningful; returns a plain Endpoint with no error. Matches tls.mode "disabled" and any endpoint that genuinely has TLS turned off.
  • scheme is https, caCert empty, tlsMode is "internal-ca" → the CA is mandatory for this mode and none was found: ErrArtifactsCAMissing. Never silently downgrades to skip-verify.
  • scheme is https, caCert empty, tlsMode is "self-signed" → the operator may explicitly opt into skipping verification via allowInsecure; without that opt-in, ErrArtifactsInsecureOptInRequired.
  • scheme is https, caCert empty, tlsMode is "disabled", "", or anything else unrecognized → the endpoint scheme contradicts the configured mode (or the mode is unknown); this is a state inconsistency, so it errors rather than guessing.

type LookupResult

type LookupResult struct {
	VMID         string
	Name         string
	PrivateIP    string
	Endpoint     string
	AccessKey    string
	SecretKey    string
	TLSMode      string
	ZFSDataset   string
	DataVolumeID string
	CACert       string

	// TLSFingerprintSHA256 and TLSLeafNotAfter mirror the state resource's
	// tls_fingerprint_sha256 / tls_leaf_not_after properties (see
	// internal/bootstrap.recordArtifactsState) — operator/status metadata
	// only, per vault.ArtifactsWriter's doc comment; never a trust decision
	// input. Empty when state never recorded them (pre-6.2 state, or no
	// TLSMaterial was ever resolved for this VM).
	TLSFingerprintSHA256 string
	TLSLeafNotAfter      string
}

LookupResult bundles the artifacts VM identity for CLI commands and other callers that need to operate on the existing VM.

func Lookup

func Lookup(ctx context.Context, sm *state.Manager, provider cpi.Provider, blocName string) (*LookupResult, error)

Lookup resolves the artifacts VM by checking state first, then falling back to a provider tag query for a VM that carries the bloc's artifacts tags. It errors when more than one distinct VM matches. Returns nil + nil error when no artifacts VM exists.

type ReadinessProbe

type ReadinessProbe interface {
	Probe(ctx context.Context, ep Endpoint, creds Credentials, caPEM string) error
}

ReadinessProbe verifies the RustFS S3 endpoint is responding to ListBuckets. Production implementation hits the endpoint via the same AWS SDK v2 client used for bucket creation; tests substitute a stub.

type TLSMaterial

type TLSMaterial struct {
	CertPEM     string
	KeyPEM      string
	Fingerprint string // sha256, lowercase hex, colon-free
	NotAfter    string // RFC3339; the leaf's expiry (task 6.2, leaf-expiry visibility)
}

TLSMaterial is the cert/key pair plus a stable SHA-256 fingerprint of the DER-encoded certificate. The fingerprint is recorded in state so operators can verify they are talking to the expected RustFS instance.

func GenerateSelfSignedTLS

func GenerateSelfSignedTLS(commonName string, dnsNames []string, ipAddrs []net.IP) (TLSMaterial, error)

GenerateSelfSignedTLS issues an ECDSA P-256 self-signed certificate suitable for RustFS native TLS. SAN list includes the provided DNS names and IPs so `aws s3 --endpoint-url` works against either the FQDN or the static IP.

func IssueLeafCert

func IssueLeafCert(ca CAMaterial, leafCN string, dnsNames []string, ips []net.IP) (TLSMaterial, error)

IssueLeafCert signs a 1-year leaf certificate for `leafCN` using the supplied CA. SAN list includes `dnsNames` and `ips`. The returned TLSMaterial carries the leaf cert and its private key — the caller is responsible for trusting the CA (the leaf's CertPEM is NOT a trust anchor).

type VaultWriter

type VaultWriter interface {
	WriteArtifacts(ctx context.Context, blocName string, ep Endpoint, creds Credentials, tls *TLSMaterial) error
}

VaultWriter persists artifacts blobstore credentials and metadata to vault. Implemented by internal/vault. Decoupled here so the artifacts package has no direct dependency on the vault client (avoids import cycles + simplifies tests).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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