Documentation
¶
Index ¶
- Constants
- func ExactSecretName(username string) (string, bool)
- func OwnsSecret(sec *corev1.Secret, username string) bool
- func SecretName(username string) string
- func SessionSecretNames(username string) []string
- func Store(ctx context.Context, rc *rest.Config, ns string, ep Endpoint) error
- type Endpoint
- type Written
Constants ¶
const ClientConfigSuffix = "-clientconfig"
ClientConfigSuffix ends the name of every Secret holding a user's session credential.
const MaxExactUsernameLength = validation.DNS1123SubdomainMaxLength - len(StepUpSuffix)
MaxExactUsernameLength is the longest username whose session and step-up Secrets can both be named after it exactly: a Secret's name is a DNS-1123 subdomain of at most 253 characters, and the step-up suffix is the longer.
const StepUpSuffix = ClientConfigSuffix + "-stepup"
StepUpSuffix ends the name of a user's step-up credential Secret, after ClientConfigSuffix: <name>-clientconfig-stepup. No session Secret's name ends in it, since those all end in ClientConfigSuffix.
const UsernameAnnotation = "authn.krateo.io/username"
UsernameAnnotation records, on a session Secret, the exact username it holds the credential of (authn#140). A reader proves a Secret is the requester's with it (OwnsSecret) before using it, so a name two usernames share can never hand one of them the other's credential.
Variables ¶
This section is empty.
Functions ¶
func ExactSecretName ¶ added in v1.58.0
ExactSecretName names username's session Secret after the username exactly, <username>-clientconfig, and reports whether it can: the username must be a DNS-1123 subdomain (lowercase a-z, 0-9, '-' and '.', each '.'-separated part starting and ending alphanumeric) of at most MaxExactUsernameLength, so that its step-up Secret is a valid name too. Dots are kept: alice.smith's Secret is alice.smith-clientconfig, not SecretName's alicesmith-clientconfig, which may be another user's (authn#140).
It is the successor of SecretName, which stays as it is through the migration: readers try SessionSecretNames, and prove ownership with OwnsSecret.
func OwnsSecret ¶ added in v1.58.0
OwnsSecret reports whether sec holds username's credential. A Secret written since authn#140 says so in UsernameAnnotation, which must equal username exactly, and when it holds a client certificate, that certificate's CommonName must be username too: a certificate that can't be read, or names someone else, fails it. One written before, without the annotation, is username's when its client certificate's CommonName is username: authn issues the certificate to the username. Anything else is not username's, however it was found: alice.smith and alicesmith share the legacy name alicesmith-clientconfig, and a reader must never use one's credential for the other.
func SecretName ¶ added in v1.32.0
SecretName names the Secret holding username's session credential, as authn writes it and every consumer reads it: the username made DNS-1123 compatible, plus ClientConfigSuffix. It is the one definition of that name; compute it here rather than rebuilding it, since a near-miss names a Secret that doesn't exist.
func SessionSecretNames ¶ added in v1.58.0
SessionSecretNames is the names username's session Secret may have, in the order a reader tries them: the exact name, when there is one, then the legacy one (SecretName), when it differs. A Secret found under either is used only once OwnsSecret proves it is username's.
Types ¶
type Endpoint ¶
type Endpoint struct {
ServerURL string `json:"serverURL"`
ProxyURL string `json:"proxyURL,omitempty"`
CertificateAuthorityData string `json:"caData,omitempty"`
ClientCertificateData string `json:"-"`
ClientKeyData string `json:"-"`
Token string `json:"token,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Debug bool `json:"debug"`
Insecure bool `json:"insecure"`
// PassCredentialsOnRedirect lets a credential follow a redirect to a DIFFERENT host:port
// (core-provider#307). Default false, which refuses.
//
// NAMED FOR THE HOP, not for the destination, deliberately. helm's equivalent is
// PassCredentialsAll, and an operator reads "all" as a statement about which destinations are
// allowed rather than about every hop of a chain they never see. The installer session made
// exactly that point about an allowAnyHost flag elsewhere: the people who set such a flag are
// by definition debugging something, and they are the least likely to be thinking about
// redirects.
//
// IT REMOVES THE WHOLE GUARD, not part of it. With this set, a credential will follow a 302
// anywhere the endpoint sends it - including a subdomain, a different port, or an unrelated
// host. There is no partial setting and that is on purpose: a half-guard would be harder to
// reason about than none.
//
// It exists because the strict default has a legitimate casualty: an endpoint configured
// without a port that redirects to one - an on-prem GHES, or a corporate proxy - is a real
// deployment, and helm's own chart getter has carried PassCredentialsAll for that reason since
// long before this. Measured on krateo-057: 0 of 3 external targets issue any 3xx, so nothing
// there needs it; the field is for the deployment that does.
PassCredentialsOnRedirect bool `json:"passCredentialsOnRedirect,omitempty"`
// AWS garbage fields for their proprietary authentication header
AwsAccessKey string `json:"awsAccessKey"`
AwsSecretKey string `json:"awsSecretKey"`
AwsRegion string `json:"awsRegion"`
AwsService string `json:"awsService"`
// AWS time field, testing only
AwsTime string `json:"awsTime"`
}
func FromSecret ¶
func (*Endpoint) HasAwsAuth ¶
HasAwsAuth returns whether the configuration has AWS authentication or not.
ALL FOUR SigV4 INPUTS, and the fourth term used to be a DUPLICATE of AwsSecretKey rather than AwsService — so this reported "has AWS auth" for a configuration that cannot produce a valid signature. `A && A` is `A`, so the typo was invisible until go 1.26's vet made "redundant and" an error and the package stopped building.
Why AwsService is the missing term and not a guess: ComputeAwsSignature uses it twice, in the credential scope and in the signing-key derivation (http/request/util.go:146, :158). With it empty, the scope reads ".../<region>//aws4_request" and the key is derived over an empty service, so AWS answers SignatureDoesNotMatch. Returning true for that is a false positive about the one thing the predicate exists to decide.
THE BEHAVIOUR CHANGE, stated rather than buried — three call sites, all in http/request:
access+secret+region+service signs, works unchanged
access+secret+region, NO service signed with an EMPTY service -> now unsigned,
and rejected by AWS failing visibly
the same, PLUS a bearer token countTrue==2, so client.go -> countTrue==1,
REFUSES the request outright the token is used
No configuration that works today stops working. The third row is the one worth noticing: an endpoint whose bearer token is complete is refused today because incomplete AWS fields sit beside it, and that request starts succeeding.
func (*Endpoint) HasBasicAuth ¶
HasBasicAuth returns whether the configuration has basic authentication or not.
func (*Endpoint) HasCA ¶
HasCA returns whether the configuration has a certificate authority or not.
func (*Endpoint) HasCertAuth ¶
HasCertAuth returns whether the configuration has certificate authentication or not.
func (*Endpoint) HasTokenAuth ¶
HasTokenAuth returns whether the configuration has token authentication or not.
type Written ¶ added in v1.43.0
type Written struct {
Namespace string
Name string
// UID and ResourceVersion are the stored Secret's; empty when nothing was
// stored, or when the apiserver's answer to a successful write couldn't be
// decoded.
UID string
ResourceVersion string
// Verb is "create" or "update": the request that stored the Secret, or the
// one that failed.
Verb string
// StatusCode is the apiserver's HTTP status for that request, 0 when no
// response arrived.
StatusCode int
}
Written is what Store wrote: the Secret, the verb of the request that stored it, and the apiserver's answer to that request. An audit record names the object written and the verb sent (AUDIT-4), and neither can be inferred afterwards: Store's create is answered 409 when the Secret exists, and the update that follows is the write. Names only, never data.