Documentation
¶
Overview ¶
auth is a package for handling short-lived credentials.
Index ¶
- Constants
- type ArtifactRegistryCredentials
- type ArtifactRegistryCredentialsProvider
- type Credential
- type GitCredentials
- type GitCredentialsProvider
- type JWTCredential
- type ObjectReference
- type Option
- func OptionsFromSpec(authSpec *cryptov1.AuthSpec) []Option
- func WithAWSClusterName(clusterName string) Option
- func WithAWSRegion(stsRegion string) Option
- func WithAWSRoleARN(roleARN string) Option
- func WithAWSSTSEndpoint(stsEndpoint string) Option
- func WithAllowShellOut() Option
- func WithAzureClientID(clientID string) Option
- func WithAzureClusterName(clusterName string) Option
- func WithAzureResourceGroup(resourceGroup string) Option
- func WithAzureSubscriptionID(subscriptionID string) Option
- func WithAzureTenantID(tenantID string) Option
- func WithCAData(caData string) Option
- func WithCache(cache cache.TokenCache) Option
- func WithCacheOperation(operation string) Option
- func WithClient(client client.Client) Option
- func WithClusterAddress(clusterAddress string) Option
- func WithClusterResource(clusterResource string) Option
- func WithCredentialAudiences(audiences ...string) Option
- func WithCredentialExpiration(expiration time.Duration) Option
- func WithCredentialProvider(provider string) Option
- func WithCredentialType(credentialType string) Option
- func WithCredentialUsername(username string) Option
- func WithDockerHubOIDCConnectionID(connectionID string) Option
- func WithGCPServiceAccount(serviceAccount string) Option
- func WithGCPWorkloadIdentityProvider(wip string) Option
- func WithGitURL(gitURL url.URL) Option
- func WithInvolvedObject(group, kind string, obj client.Object) Option
- func WithObject(group, kind string, obj client.Object) Option
- func WithProxyURL(proxyURL url.URL) Option
- func WithSPIFFEBroker(client broker.Interface) Option
- func WithScopes(scopes ...string) Option
- func WithServiceAccountName(name string) Option
- type Options
- type Provider
- type RESTConfig
- type RESTConfigProvider
Constants ¶
const ( // ControllerFlagDefaultServiceAccount defines the flag for the default service account name // to be used when .spec.serviceAccountName is not specified in the object. ControllerFlagDefaultServiceAccount = "default-service-account" // ControllerFlagDefaultKubeConfigServiceAccount defines the flag for the default // service account name to be used when .data.serviceAccountName is not specified // in the ConfigMap referenced by .spec.kubeConfig.configMapRef. ControllerFlagDefaultKubeConfigServiceAccount = "default-kubeconfig-service-account" // ControllerFlagDefaultDecryptionServiceAccount defines the flag for the default // service account name to be used when .spec.decryption.serviceAccountName is // not specified in the object. ControllerFlagDefaultDecryptionServiceAccount = "default-decryption-service-account" )
Controller flags for the default service account names. Controllers register these flags and are responsible for resolving the value relevant to the operation being performed.
const FeatureGateObjectLevelWorkloadIdentity = "ObjectLevelWorkloadIdentity"
FeatureGateObjectLevelWorkloadIdentity is a feature gate that enables the use of object-level workload identity for authentication. Controllers register this feature gate and are responsible for evaluating it.
const FeatureGateObjectLevelWorkloadIdentityRetirementReason = "the feature is now always enabled. " +
"make sure to grant RBAC for the controller to create ServiceAccount tokens if using the feature."
FeatureGateObjectLevelWorkloadIdentityRetirementReason provides the reason why the ObjectLevelWorkloadIdentity feature gate is retired.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArtifactRegistryCredentials ¶
type ArtifactRegistryCredentials struct {
authn.Authenticator
ExpiresAt time.Time
}
ArtifactRegistryCredentials is a particular type implementing the Credential interface for credentials that can be used to authenticate against an artifact registry from a cloud provider.
func GetArtifactRegistryCredentials ¶ added in v0.21.0
func GetArtifactRegistryCredentials(ctx context.Context, provider ArtifactRegistryCredentialsProvider, artifactRepository string, opts ...Option) (*ArtifactRegistryCredentials, error)
GetArtifactRegistryCredentials retrieves the registry credentials for the specified artifact repository and provider.
func (*ArtifactRegistryCredentials) GetDuration ¶
func (a *ArtifactRegistryCredentials) GetDuration() time.Duration
GetDuration implements Credential.
type ArtifactRegistryCredentialsProvider ¶ added in v0.21.0
type ArtifactRegistryCredentialsProvider interface {
Provider
// GetAccessCredentialOptionsForArtifactRepository returns the options that must be
// passed to the provider to retrieve access credentials for an artifact repository.
GetAccessCredentialOptionsForArtifactRepository(artifactRepository string,
opts ...Option) ([]Option, error)
// ParseArtifactRepository parses the artifact repository to verify
// it's a valid repository for the provider. As a result, it returns
// the input required for the provider to issue registry credentials.
// This input is included in the cache key for the issued credentials.
ParseArtifactRepository(artifactRepository string) (string, error)
// NewArtifactRegistryCredentials takes the registry input extracted by
// ParseArtifactRepository() and an access credential and returns
// credentials that can be used to authenticate with the registry.
NewArtifactRegistryCredentials(ctx context.Context, registryInput string,
accessCredential Credential, opts ...Option) (*ArtifactRegistryCredentials, error)
}
ArtifactRegistryCredentialsProvider is an interface that defines methods for retrieving credentials for artifact registries from cloud providers.
type Credential ¶ added in v0.64.0
type Credential interface {
// GetDuration returns the duration for which the credential will still be
// valid relative to approximately time.Now(). This is used to determine
// when the credential should be renewed.
GetDuration() time.Duration
}
Credential is an interface that represents a credential that can be used to authenticate requests for a service provider. The only common method is for getting the duration of the credential, because different providers have different ways of representing the credential. For example, Azure and GCP use a single string, while AWS uses three strings: access key ID, secret access key and token session. Consumers of this interface should know what type to cast it to.
func NewAccessCredential ¶ added in v0.64.0
func NewAccessCredential(ctx context.Context, provider Provider, opts ...Option) (Credential, error)
NewAccessCredential returns an access credential for accessing resources in the given cloud provider.
type GitCredentials ¶ added in v0.42.0
type GitCredentials struct {
BearerToken string
Username string
Password string
ExpiresAt time.Time
}
GitCredentials contains authentication data needed in order to access a Git repository.
func GetGitCredentials ¶ added in v0.42.0
func GetGitCredentials(ctx context.Context, provider GitCredentialsProvider, opts ...Option) (*GitCredentials, error)
GetGitCredentials retrieves the Git credentials for the Git repository URL set via WithGitURL and the specified provider.
func (*GitCredentials) GetDuration ¶ added in v0.42.0
func (g *GitCredentials) GetDuration() time.Duration
GetDuration implements Credential.
type GitCredentialsProvider ¶ added in v0.42.0
type GitCredentialsProvider interface {
Provider
// GetAccessCredentialOptionsForGitRepository returns the options that must be
// passed to the provider to retrieve access credentials for the given Git
// repository URL.
GetAccessCredentialOptionsForGitRepository(gitURL *url.URL) ([]Option, error)
// ParseGitRepository parses the given Git repository URL to verify
// it's a valid repository URL for the provider. As a result it returns
// an opaque per-repository input required for issuing Git credentials.
// This input is included in the cache key for the issued credentials,
// which is critical for providers whose credentials depend on the URL
// (e.g. AWS CodeCommit, whose credentials are a SigV4 signature over
// the request URL).
ParseGitRepository(gitURL *url.URL) (string, error)
// NewGitCredentials takes the input extracted by ParseGitRepository()
// and an access credential and returns credentials that can be used to
// authenticate against the Git repository.
NewGitCredentials(ctx context.Context, gitInput string,
accessCredential Credential, opts ...Option) (*GitCredentials, error)
}
GitCredentialsProvider is an interface that defines methods for retrieving credentials for Git repositories from cloud providers.
type JWTCredential ¶ added in v0.64.0
type JWTCredential struct {
// Provider is the credential provider that minted the JWT, e.g.
// `kubernetes` or `spiffe`.
Provider string
// Token is the serialized JWT.
Token string
// ExpiresAt is the expiration time extracted from the JWT.
ExpiresAt time.Time
}
JWTCredential is a credential represented by a JWT. It is used as the identity passed to providers that exchange JWTs for service provider credentials, and by providers that use the JWT directly as the access credential.
func (*JWTCredential) GetDuration ¶ added in v0.64.0
func (c *JWTCredential) GetDuration() time.Duration
GetDuration implements Credential.
type ObjectReference ¶ added in v0.64.0
ObjectReference identifies the Flux object entitled to the identity. It is used for resolving the ServiceAccount namespace and, later, for SPIFFE.
type Option ¶
type Option func(*Options)
Option is a functional option for the auth package.
func OptionsFromSpec ¶ added in v0.64.0
OptionsFromSpec returns the options derived from a validated authentication configuration produced by github.com/fluxcd/pkg/apis/crypto.
func WithAWSClusterName ¶ added in v0.64.0
WithAWSClusterName sets the AWS EKS cluster name.
func WithAWSRegion ¶ added in v0.64.0
WithAWSRegion sets the region for the AWS STS service.
func WithAWSRoleARN ¶ added in v0.64.0
WithAWSRoleARN sets the AWS IAM Role ARN.
func WithAWSSTSEndpoint ¶ added in v0.64.0
WithAWSSTSEndpoint sets the endpoint for the AWS STS service.
func WithAllowShellOut ¶ added in v0.17.0
func WithAllowShellOut() Option
WithAllowShellOut allows the provider to shell out to binary tools for acquiring controller tokens. MUST be used only by the Flux CLI, i.e. in the github.com/fluxcd/flux2 Git repository.
func WithAzureClientID ¶ added in v0.64.0
WithAzureClientID sets the Microsoft Entra client ID.
func WithAzureClusterName ¶ added in v0.64.0
WithAzureClusterName sets the Azure AKS cluster name.
func WithAzureResourceGroup ¶ added in v0.64.0
WithAzureResourceGroup sets the Azure resource group.
func WithAzureSubscriptionID ¶ added in v0.64.0
WithAzureSubscriptionID sets the Azure subscription ID.
func WithAzureTenantID ¶ added in v0.64.0
WithAzureTenantID sets the Microsoft Entra tenant ID.
func WithCAData ¶ added in v0.21.0
WithCAData sets the CA data for credentials that require a CA, e.g. for Kubernetes REST config.
func WithCacheOperation ¶ added in v0.64.0
WithCacheOperation sets the operation performed on the Flux object, for cache entry purposes.
func WithClient ¶ added in v0.21.0
WithClient sets the controller-runtime client for the provider.
func WithClusterAddress ¶ added in v0.21.0
WithClusterAddress sets the cluster address for creating a REST config. This address is used to select the correct cluster endpoint and CA data when the provider has a list of endpoints to choose from, or to simply validate the address against the cluster resource when the provider returns a single endpoint. This is optional, providers returning a list of endpoints will select the first one if no address is provided.
func WithClusterResource ¶ added in v0.21.0
WithClusterResource sets the cluster resource for creating a REST config. Must be the fully qualified name of the cluster resource in the cloud provider API.
func WithCredentialAudiences ¶ added in v0.64.0
WithCredentialAudiences sets the audiences for the Kubernetes ServiceAccount token.
func WithCredentialExpiration ¶ added in v0.64.0
WithCredentialExpiration sets the requested credential expiration.
func WithCredentialProvider ¶ added in v0.64.0
WithCredentialProvider sets the credential provider, one of `kubernetes` or `spiffe`.
func WithCredentialType ¶ added in v0.64.0
WithCredentialType sets the credential type, one of `jwt` or `x509`.
func WithCredentialUsername ¶ added in v0.64.0
WithCredentialUsername sets the optional username to authenticate with the service.
func WithDockerHubOIDCConnectionID ¶ added in v0.64.0
WithDockerHubOIDCConnectionID sets the Docker Hub OIDC connection ID.
func WithGCPServiceAccount ¶ added in v0.64.0
WithGCPServiceAccount sets the GCP Service Account email.
func WithGCPWorkloadIdentityProvider ¶ added in v0.64.0
WithGCPWorkloadIdentityProvider sets the GCP Workload Identity Provider.
func WithGitURL ¶ added in v0.41.0
WithGitURL sets the Git repository URL used by Git credential providers.
func WithInvolvedObject ¶ added in v0.64.0
WithInvolvedObject sets the reference to the Flux object involved in the operation for cache entry purposes. It is used when the object entitled to the identity is not the one using it, e.g. an ImagePolicy using an ImageRepository's identity. The group and kind are provided explicitly because the object may not carry its TypeMeta.
func WithObject ¶ added in v0.64.0
WithObject sets the reference to the Flux object entitled to the identity. The group and kind are provided explicitly because the object may not carry its TypeMeta, e.g. when it was retrieved from the API server with its concrete type. It also sets the involved object reference, unless overridden by a later call to WithInvolvedObject.
func WithProxyURL ¶
WithProxyURL sets a *url.URL for an HTTP/S proxy for acquiring the token.
func WithSPIFFEBroker ¶ added in v0.64.0
WithSPIFFEBroker sets the client used to fetch JWT-SVIDs for the `spiffe` credential provider.
func WithScopes ¶
WithScopes sets the scopes for the token.
func WithServiceAccountName ¶ added in v0.25.0
WithServiceAccountName sets the ServiceAccount name for the token.
type Options ¶
type Options struct {
Client client.Client
Cache *cache.TokenCache
SPIFFEBroker broker.Interface
// Object entitled to the identity.
ObjectReference ObjectReference
// Object involved in the operation, i.e. the object using the identity.
// It is used for cache entries.
InvolvedObjectReference ObjectReference
CacheOperation string
// ServiceAccount for object-level workload identity.
ServiceAccountName string
// Credential acquisition.
CredentialProvider string
CredentialType string
CredentialExpiration time.Duration
CredentialUsername string
CredentialAudiences []string
// Request configuration.
Scopes []string
ProxyURL *url.URL
GitURL *url.URL
AllowShellOut bool
// Remote Kubernetes cluster connection.
ClusterResource string
ClusterAddress string
CAData string
// AWS.
AWSRoleARN string
AWSRegion string
AWSSTSEndpoint string
AWSClusterName string
// Azure.
AzureTenantID string
AzureClientID string
AzureSubscriptionID string
AzureResourceGroup string
AzureClusterName string
// GCP.
GCPWorkloadIdentityProvider string
GCPServiceAccount string
// Docker Hub.
DockerHubOIDCConnectionID string
}
Options contains options for configuring the behavior of the provider methods. Not all providers/methods support all options.
func (*Options) GetHTTPClient ¶
GetHTTPClient returns a *http.Client with appropriate timeouts and proxy settings. The client includes a 10-second timeout to prevent indefinite hangs during token acquisition.
func (*Options) ServiceAccountRef ¶ added in v0.64.0
func (o *Options) ServiceAccountRef() *kubernetes.ServiceAccountReference
ServiceAccountRef returns the ServiceAccount object for the token. If the object was not set explicitly, it is built from the configured name and namespace.
type Provider ¶
type Provider interface {
// GetName returns the name of the cloud provider.
GetName() string
// NewControllerToken returns a credential that can be used to authenticate
// with the cloud provider retrieved from the default source, i.e. from
// the environment of the controller pod, e.g. files mounted in the pod,
// environment variables, local metadata services, etc.
NewControllerToken(ctx context.Context, opts ...Option) (Credential, error)
// GetAudiences returns the audiences the OIDC tokens issued by the
// credential provider should have. These are usually strings that represent
// the cloud provider's STS service, or some entity in the provider for
// which the OIDC tokens are targeted to. The provider decides whether any
// caller-provided credential audiences are used.
GetAudiences(ctx context.Context, opts ...Option) ([]string, error)
// GetIdentity returns the identity which the ServiceAccount wants to
// impersonate, as configured in the options.
GetIdentity(opts ...Option) (string, error)
// NewAccessCredentialForIdentity takes the identity credential and
// returns a credential that can be used to authenticate with the cloud
// provider. The implementation should exchange this credential for a
// cloud provider access credential through the provider's STS service.
NewAccessCredentialForIdentity(ctx context.Context, identity Credential, opts ...Option) (Credential, error)
}
Provider contains the logic to retrieve security credentials for accessing resources in a cloud provider.
type RESTConfig ¶ added in v0.21.0
RESTConfig is a particular type implementing the Credential interface for Kubernetes REST configurations.
func GetRESTConfig ¶ added in v0.21.0
func GetRESTConfig(ctx context.Context, provider RESTConfigProvider, opts ...Option) (*RESTConfig, error)
GetRESTConfig retrieves the authentication and connection details to a remote Kubernetes cluster for the given provider, cluster resource name and options.
func (*RESTConfig) GetDuration ¶ added in v0.21.0
func (r *RESTConfig) GetDuration() time.Duration
GetDuration implements Credential.
type RESTConfigProvider ¶ added in v0.21.0
type RESTConfigProvider interface {
Provider
// GetAccessCredentialOptionsForCluster returns the options that must be
// passed to the provider to retrieve access credentials for a cluster.
// More than one access credential may be required depending on the
// provider, with different options (e.g. scope). Hence the return
// type is a slice of []Option.
GetAccessCredentialOptionsForCluster(opts ...Option) ([][]Option, error)
// NewRESTConfig returns a new RESTConfig that can be used to authenticate
// with the Kubernetes API server. The access credentials are used for
// looking up connection details like the API server address and CA
// certificate data, and for accessing the cluster API server itself via
// the IAM system of the cloud provider. If it's just a single credential
// or multiple, it depends on the provider.
NewRESTConfig(ctx context.Context, accessCredentials []Credential, opts ...Option) (*RESTConfig, error)
}
RESTConfigProvider is an interface that defines methods for retrieving REST configurations for Kubernetes clusters from cloud providers.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package actionsoidc fetches OIDC ID tokens from the GitHub/Forgejo Actions token endpoint.
|
Package actionsoidc fetches OIDC ID tokens from the GitHub/Forgejo Actions token endpoint. |
|
internal
|
|
|
tokenfile
Package tokenfile provides access to the controller ServiceAccount token file mounted by Kubernetes.
|
Package tokenfile provides access to the controller ServiceAccount token file mounted by Kubernetes. |
|
Package jwt issues self-signed JSON Web Tokens.
|
Package jwt issues self-signed JSON Web Tokens. |
|
Package utils contains small utility functions without much logic wrapping the major APIs of the core auth package for ease of use in the controllers.
|
Package utils contains small utility functions without much logic wrapping the major APIs of the core auth package for ease of use in the controllers. |
|
cijwt
Package cijwt provides an http.RoundTripper that authenticates outbound requests on a per-host basis with a JWT, sourcing the token from a CI/CD platform's OIDC integration or signing it locally.
|
Package cijwt provides an http.RoundTripper that authenticates outbound requests on a per-host basis with a JWT, sourcing the token from a CI/CD platform's OIDC integration or signing it locally. |