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
- func ControlPlaneSecretNames(controlPlane *coderv1alpha1.CoderControlPlane) []string
- func EncodedForms(data []byte) []string
- func OperatorTokenSecretName(controlPlane *coderv1alpha1.CoderControlPlane) string
- func Origin(u *url.URL) (string, error)
- func ParseDestinations(raw string) (map[string]struct{}, error)
- func ParseURL(raw string) (*url.URL, error)
- func Redact(s string, values ...Value) string
- func WatchPredicate() predicate.Predicate
- type ChangeToken
- type Error
- type Value
Constants ¶
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 )
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 ¶
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 ¶
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 ¶
ParseDestinations parses the destinations annotation into a set of origins. Each entry must be an origin: no user info, path, query or fragment.
func Redact ¶
Redact replaces each value, and its base64 and URL-encoded forms, in s with "[REDACTED]".
func WatchPredicate ¶
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 ¶
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.
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
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) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Value) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package credentialsecrettest holds test helpers for the credential Secret contract.
|
Package credentialsecrettest holds test helpers for the credential Secret contract. |