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, it does not carry app.kubernetes.io/managed-by=coder-k8s, and no CoderControlPlane in the namespace names it as its operator token Secret.
- 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 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 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 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. |