endpoints

package
v1.77.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const ClientConfigSuffix = "-clientconfig"

ClientConfigSuffix ends the name of every Secret holding a user's session credential.

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.

View Source
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.

View Source
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

func ExactSecretName(username string) (string, bool)

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

func OwnsSecret(sec *corev1.Secret, username string) bool

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

func SecretName(username string) string

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

func SessionSecretNames(username string) []string

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.

func Store

func Store(ctx context.Context, rc *rest.Config, ns string, ep Endpoint) error

Store writes ep as username's credential Secret in ns: a create, or an update when the Secret exists.

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 FromSecret(ctx context.Context, rc *rest.Config, name, namespace string) (Endpoint, error)

func (*Endpoint) HasAwsAuth

func (ep *Endpoint) HasAwsAuth() bool

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

func (ep *Endpoint) HasBasicAuth() bool

HasBasicAuth returns whether the configuration has basic authentication or not.

func (*Endpoint) HasCA

func (ep *Endpoint) HasCA() bool

HasCA returns whether the configuration has a certificate authority or not.

func (*Endpoint) HasCertAuth

func (ep *Endpoint) HasCertAuth() bool

HasCertAuth returns whether the configuration has certificate authentication or not.

func (*Endpoint) HasTokenAuth

func (ep *Endpoint) HasTokenAuth() bool

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.

func StoreWritten added in v1.43.0

func StoreWritten(ctx context.Context, rc *rest.Config, ns string, ep Endpoint) (Written, error)

StoreWritten is Store, reporting what it wrote. On an error, Written still names the Secret and, when a request was sent, its verb and status.

Jump to

Keyboard shortcuts

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