credentialsecret

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 16 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 credentialsecret implements the credential Secret contract: the rules a Kubernetes Secret must meet before a controller sends its value to a remote service or puts it into a pod.

A Secret is usable only when all of these are true:

  • It has type Opaque.
  • The operator did not generate it: it has no owner in the coder.com API group, and it does not carry app.kubernetes.io/managed-by=coder-k8s.
  • No CoderControlPlane in the namespace uses it: its operator token Secret, and every Secret that its spec references (see ControlPlaneSecretNames).
  • It carries the label coder.com/credential=true.
  • Its annotation coder.com/credential-destinations lists the origin of the destination that the caller sends the value to.
  • The key exists, and the value is non-empty, at most 8 KiB, and has no leading or trailing whitespace.

Errors from Read carry a condition reason and a message. Messages name Secrets, keys and origins only. They never hold Secret data.

Index

Constants

View Source
const (
	// LabelKey is the opt-in label. Its value must be LabelValue.
	LabelKey = "coder.com/credential"
	// LabelValue is the only label value that opts a Secret in.
	LabelValue = "true"
	// DestinationsAnnotation lists the origins (scheme://host[:port]) that may
	// receive the Secret's values. Entries are separated by commas or whitespace.
	DestinationsAnnotation = "coder.com/credential-destinations"
	// MaxValueBytes is the largest value that Read accepts.
	MaxValueBytes = 8 * 1024
)
View Source
const (
	ReasonSecretNotFound        = "CredentialSecretNotFound"
	ReasonKeyMissing            = "CredentialKeyMissing"
	ReasonRefused               = "CredentialRefused"
	ReasonNotOptedIn            = "CredentialNotOptedIn"
	ReasonDestinationNotAllowed = "CredentialDestinationNotAllowed"
	ReasonMalformed             = "CredentialMalformed"
)

Shared condition reasons for credential failures.

Variables

This section is empty.

Functions

func ControlPlaneSecretNames added in v0.1.4

func ControlPlaneSecretNames(controlPlane *coderv1alpha1.CoderControlPlane) []string

ControlPlaneSecretNames returns the names of the Secrets that Read refuses because of controlPlane: its operator token Secret (the configured or default name, and the name in status) and every Secret that its spec references: spec.licenseSecretRef, spec.database.connectionSecretRef, spec.extraEnv secretKeyRefs, spec.envFrom secretRefs, spec.imagePullSecrets, spec.tls.secretNames, spec.expose.ingress.tls, spec.certs.secrets, and the Secret sources of spec.volumes. The names are sorted and unique. Controllers re-queue the resources that reference these names when a control plane changes.

func EncodedForms

func EncodedForms(data []byte) []string

EncodedForms returns the encoded forms of data that Redact removes, longest first so that a longer form is replaced before a form it contains.

func OperatorTokenSecretName

func OperatorTokenSecretName(controlPlane *coderv1alpha1.CoderControlPlane) string

OperatorTokenSecretName returns the name of the Secret that holds the operator token of controlPlane. The CoderControlPlane controller uses it to name that Secret, and Read uses it to refuse that Secret.

func Origin

func Origin(u *url.URL) (string, error)

Origin returns the normalized origin of u: lowercase scheme and host, and the port only when it is not the default port of the scheme. Only http and https URLs have an origin here.

func ParseDestinations

func ParseDestinations(raw string) (map[string]struct{}, error)

ParseDestinations parses the destinations annotation into a set of origins. Each entry must be an origin: no user info, path, query or fragment.

func ParseURL

func ParseURL(raw string) (*url.URL, error)

ParseURL parses raw as an http or https URL that has a host.

func Redact

func Redact(s string, values ...Value) string

Redact replaces each value, and its base64 and URL-encoded forms, in s with "[REDACTED]".

func WatchPredicate

func WatchPredicate() predicate.Predicate

WatchPredicate passes the Secret events that can change a Read result: creates and updates where the old or the new Secret carries the opt-in label, and every delete. Events for unlabeled Secrets cannot turn a failed Read into a pass, so they are dropped.

Types

type ChangeToken

type ChangeToken struct {
	SecretName      string
	SecretKey       string
	SecretUID       types.UID
	ResourceVersion string
}

ChangeToken identifies the Secret state that a Value came from. It holds no secret data.

type Error

type Error struct {
	Reason  string
	Message string
}

Error is a contract failure. Reason is a condition reason. Message is safe to put into status, events and logs: it never holds Secret data.

func (*Error) Error

func (e *Error) Error() string

type Value

type Value struct {
	Token ChangeToken
	// contains filtered or unexported fields
}

Value holds credential bytes. All formatting, logging and JSON encoding print "[REDACTED]". Use Reveal to get the bytes for the one call that needs them. Limit: fmt cannot call these methods on a Value inside an unexported struct field, and then prints the raw bytes. Keep a Value in a local variable or an exported field.

func NewValue added in v0.1.4

func NewValue(data []byte) Value

NewValue wraps credential bytes that did not come from a Secret, for example a key that a remote service returned, so they print as "[REDACTED]" too. It copies data. The ChangeToken stays empty.

func Read

func Read(ctx context.Context, c client.Reader, namespace string, ref coderv1alpha1.SecretKeySelector, destination *url.URL) (Value, error)

Read gets the Secret ref.Name in namespace, applies the contract, and checks that the origin of destination is listed in the Secret's destinations. ref.Key must be set: callers apply their defaults first.

func (Value) Format

func (v Value) Format(f fmt.State, _ rune)

Format implements fmt.Formatter, so every verb prints "[REDACTED]".

func (Value) GoString

func (v Value) GoString() string

GoString implements fmt.GoStringer.

func (Value) MarshalJSON

func (v Value) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Value) MarshalLog

func (v Value) MarshalLog() any

MarshalLog implements logr.Marshaler.

func (Value) MarshalText

func (v Value) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Value) Reveal

func (v Value) Reveal() string

Reveal returns the credential as a string.

func (Value) String

func (v Value) String() string

String implements fmt.Stringer.

Directories

Path Synopsis
Package credentialsecrettest holds test helpers for the credential Secret contract.
Package credentialsecrettest holds test helpers for the credential Secret contract.

Jump to

Keyboard shortcuts

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