Documentation
¶
Overview ¶
Package secretartifacts plans secret manifests without depending on a secret backend or a GitOps renderer.
Index ¶
- Constants
- func CertManagerCredentialArtifactPath(provider, name string) (string, error)
- func CertManagerCredentialFilename(provider, name string) (string, error)
- func DedicatedSecretFilename(relative string) (dir string, filename string, ok bool)
- func HashBytes(data []byte) string
- func IsCertManagerCredentialFilename(base string) bool
- func RelativeArtifactPath(manifestPath string) string
- func SafeArtifactPath(relative string) bool
- func ValidateCertManagerCredentialName(name string) error
- func ValidateTargets(cfg *v2.Config, artifacts []Artifact) error
- func WriteOwnershipStateAtomic(root string, state OwnershipState) error
- type Artifact
- type Owner
- type OwnershipArtifact
- type OwnershipState
Constants ¶
const ( GrafanaAdminPasswordSecretFilename = "grafana-admin-password.yaml" GrafanaOAuthSecretFilename = "grafana-oauth-secret.yaml" GatewayOIDCSecretFilename = "gateway-oidc-secret.yaml" )
Dedicated secret filenames are Secrets the renderers emit with a filename of their own instead of the generic per-service secret.yaml, because the Helm chart or the Envoy SecurityPolicy references that exact Kubernetes Secret name. They carry credential material, so they are sync-owned: see DedicatedSecretFilename for why the planner has to know them.
const ( OwnershipStateFilename = ".opencenter-secret-artifacts.json" OwnershipStateVersion = 2 )
Variables ¶
This section is empty.
Functions ¶
func CertManagerCredentialArtifactPath ¶
CertManagerCredentialArtifactPath returns the overlay-relative path of the SOPS-encrypted Secret holding one cert-manager DNS credential.
The name is derived here, from the same resolved credential set the renderer iterates, so the materialized Secret and the ClusterIssuer's apiTokenSecretRef / accessKeyIDSecretRef can never disagree: a name computed independently on either side is how a plaintext credential ended up committed while sync encrypted only the legacy generic secret.yaml.
provider must be "aws" or "cloudflare"; name is the credential map key, which validateCertManagerCredentialName already constrains to a DNS-1123 label.
func CertManagerCredentialFilename ¶
CertManagerCredentialFilename returns the Secret filename for one cert-manager DNS credential: opencenter-aws-credentials-secret-<name>.yaml or opencenter-cloudflare-credentials-secret-<name>.yaml.
The name is validated as a DNS-1123 label rather than assumed. The renderer applies the same rule, but sync must not rely on the renderer having run: an unvalidated name would flow straight into an overlay-relative path that the ownership ledger later resolves for hashing and deletion.
func DedicatedSecretFilename ¶
DedicatedSecretFilename reports whether an overlay-relative path is a Secret manifest the renderers emit with a dedicated filename instead of the generic per-service secret.yaml, and returns the directory that owns it.
The renderers and the planner must agree on exactly one set: a name listed here but not rendered produces an orphan that sync prunes, and a rendered name missing from here stays committed as plaintext because sync never claims the path. The renderers consult this function instead of keeping their own copy.
func IsCertManagerCredentialFilename ¶
IsCertManagerCredentialFilename reports whether a basename is one this planner would construct for a credential Secret. It is the ownership-state admission test: the accepted set is derived from the same prefix list and label pattern the builder uses, so the two cannot drift apart.
func RelativeArtifactPath ¶
RelativeArtifactPath converts a materialized manifest path (absolute or relative, OS separators) into the overlay-relative slash form that DedicatedSecretFilename and the ownership ledger key on: the path starting at its "services" or "managed-services" root.
Naming and ownership are both decided by the artifact's position under the overlay, so every caller must resolve names from the same shape. Handing a helper only the basename silently degrades a path-scoped match into a filename match, which is how the dedicated Grafana Secrets both ended up named opencenter-kube-prometheus-stack-secret.
A path with no services root is returned unchanged in slash form, so the caller's own match simply fails rather than guessing an overlay location.
func SafeArtifactPath ¶
SafeArtifactPath reports whether a relative path may hold a sync-owned secret. Three shapes are allowed: the generic per-service manifest services/<service>/secret.yaml, a cert-manager DNS-credential Secret services/cert-manager/<credential-file>.yaml, and a renderer-emitted Secret carrying a dedicated filename (see DedicatedSecretFilename).
Every shape is constrained to a filename the planner itself constructs, so a corrupt or hostile ownership state still cannot name an arbitrary file for sync to write, hash-check, or delete.
func ValidateCertManagerCredentialName ¶
ValidateCertManagerCredentialName enforces the DNS-1123 label rule the credential map keys must satisfy.
A credential name is only ever safe to embed in a path once it is known to be a label, and the ownership ledger later resolves that path to hash and to delete. Exported so the renderer validates through this function instead of keeping a second, drift-prone copy of the contract.
func ValidateTargets ¶
ValidateTargets verifies that materialized non-empty artifacts have a configured, enabled target when service topology is declared.
func WriteOwnershipStateAtomic ¶
func WriteOwnershipStateAtomic(root string, state OwnershipState) error
Types ¶
type Artifact ¶
type Artifact struct {
// LogicalService is retained for compatibility and is the first owner in
// deterministic order. Consumers should use Owners for complete identity.
LogicalService string
TargetService string
Path string
Payload map[string]interface{}
Owners []string
SourcePayloads map[string]map[string]interface{}
}
Artifact describes one materialized secret manifest. Multiple logical owners may share one physical target and are merged deterministically.
func (Artifact) OwnerNames ¶
type OwnershipArtifact ¶
type OwnershipArtifact struct {
Path string `json:"path"`
Owners []string `json:"owners,omitempty"`
Hash string `json:"hash"`
}
OwnershipArtifact records an artifact path, its logical owners, and the hash of the materialized file. It is deliberately kept in this leaf package so GitOps can consume ownership without importing the secrets manager.
type OwnershipState ¶
type OwnershipState struct {
Version int `json:"version"`
Artifacts []OwnershipArtifact `json:"artifacts"`
// Paths is retained only to read pre-phase-4 state files. New files never
// write this field.
Paths []string `json:"paths,omitempty"`
}
func LoadOwnershipState ¶
func LoadOwnershipState(root string) (OwnershipState, bool, error)
func (OwnershipState) ByPath ¶
func (s OwnershipState) ByPath() map[string]OwnershipArtifact