-
Notifications
You must be signed in to change notification settings - Fork 673
Closed
Labels
umbrella-issueUmbrella issue for tracking progress of a larger effortUmbrella issue for tracking progress of a larger effort
Description
Migrate Flux controllers to use runtime/secrets package
Background
We have successfully consolidated secret handling patterns in the Flux ecosystem by creating a new runtime/secrets
package in fluxcd/pkg. This package provides unified functions for handling Kubernetes secrets across all Flux components.
Key developments:
- Issue fluxcd/pkg#949: Consolidate the handling of secrets
- PR fluxcd/pkg#950: Add runtime/secrets package (merged)
- Issue fluxcd/pkg#953: Add legacy field logging
- PR fluxcd/pkg#955: Add legacy field logging to TLS functions (merged)
- Release:
fluxcd/pkg/runtime v0.62.0
now available for use across Flux
New runtime/secrets Package
The runtime/secrets
package provides:
Core Functions
TLSConfigFromSecret(ctx, client, name, namespace, logger)
- Creates TLS config with legacy field supportProxyURLFromSecret(ctx, client, name, namespace)
- Extracts proxy configurationBasicAuthFromSecret(ctx, client, name, namespace)
- Retrieves basic auth credentialsPullSecretsFromServiceAccount(ctx, client, name, namespace)
- Resolves image pull secrets
Helper Functions
MakeTLSSecret()
,MakeProxySecret()
,MakeBasicAuthSecret()
, etc.
Key Features
- Legacy Field Support: Always supports deprecated field names (
certFile
,keyFile
,caFile
) for backward compatibility - Standard Field Priority: Standard Kubernetes field names (
tls.crt
,tls.key
,ca.crt
) take precedence - Migration Logging: Warns when legacy fields are used to encourage migration
- Consistent API: Same behavior across all Flux components
Migration Goals
- Consistency: Ensure all Flux controllers handle secrets the same way
- Maintainability: Reduce code duplication across repositories
- User Experience: Provide consistent secret field support and clear migration paths
- Future-proofing: Prepare for eventual v2 API transition
Target Repositories
The following repositories contain secret handling functionality that can benefit from migrating to runtime/secrets
:
- source-controller: Repository-type-specific migration with authentication patterns
- HelmRepository controller migration (Migrate HelmRepository to runtime/secrets source-controller#1849)
- OCIRepository controller migration (Migrate OCIRepository controller to runtime/secrets source-controller#1851)
- Bucket controller migration (Migrate Bucket controller to runtime/secrets source-controller#1852)
-
GitRepository controller migration- Migration not required: Git authentication uses the established
pkg/git
module withgit.NewAuthOptions()
, which provides equivalent functionality to runtime/secrets. Thepkg/git
module is specifically designed for Git authentication and is used consistently across the Flux ecosystem (source-controller, image-automation-controller) for Git operations.
- Migration not required: Git authentication uses the established
-
kustomize-controller: TLS certificates for webhook validation, SOPS decryption keys- Migration not required: kustomize-controller only handles secrets for SOPS decryption, which uses file extension-based processing (
.asc
,.agekey
,sops.aws-kms
, etc.) rather than standard Kubernetes secret field names (tls.crt
,tls.key
,ca.crt
,username
,password
). This unique requirement makes the controller incompatible with the runtime/secrets package's field-based approach, as SOPS expects specific file names for different encryption methods rather than standardized secret fields.
- Migration not required: kustomize-controller only handles secrets for SOPS decryption, which uses file extension-based processing (
-
helm-controller: TLS certificates for Helm repositories, authentication secrets- Migration not required: helm-controller delegates all authentication (TLS/BasicAuth/Proxy) to source-controller and only consumes authenticated artifacts. The controller handles KubeConfig secrets and values injection, which are outside the scope of runtime/secrets package.
- notification-controller: Core runtime/secrets migration completed
- ProxySecretRef implementation (Add ProxySecretRef field to Provider API notification-controller#1133)
- mTLS support for postMessage-based notifiers (Add mTLS support for postMessage-based notifiers notification-controller#1137)
- BasicAuth processing unification (Unify BasicAuth processing using pkg/runtime/secrets notification-controller#1139)
-
Proxy URL parsing optimization (planned for Flux v1)- We'll address this in Remove deprecated proxy fields from Provider API notification-controller#1144.
- Git-based notifiers mTLS support (Add mTLS support for git-based notifiers notification-controller#1146)
- Other notifiers (DataDog, Sentry)
-
image-automation-controller: Git authentication secrets- Migration not required: Git authentication already uses the established
pkg/git
module withgit.NewAuthOptions()
, which provides equivalent functionality to runtime/secrets for Git-specific authentication patterns. Thepkg/git
module is specifically designed for Git authentication and is used consistently across the Flux ecosystem for Git operations.
- Migration not required: Git authentication already uses the established
- image-reflector-controller: Registry authentication for image scanning
- Core pkg/runtime/secrets migration (Migrate secrets handling to pkg/runtime/secrets image-reflector-controller#791)
- Migrated TLS certificate handling to
TLSConfigFromSecret()
- Migrated proxy configuration to
ProxyURLFromSecret()
- Migrated TLS certificate handling to
- ServiceAccount ImagePullSecrets migration (Migrate secrets handling to pkg/runtime/secrets image-reflector-controller#791)
- Migrate ServiceAccount ImagePullSecrets handling to
PullSecretsFromServiceAccount()
- Maintain integration with go-containerregistry k8schain
- Complete cleanup of any remaining custom secret handling code
- Migrate ServiceAccount ImagePullSecrets handling to
- Core pkg/runtime/secrets migration (Migrate secrets handling to pkg/runtime/secrets image-reflector-controller#791)
- flux2: CLI utilities for creating and managing secrets
-
Git authentication commands (flux bootstrap
,flux create secret git
)- Migration not required: These commands already use the established
pkg/git
module for Git authentication, providing equivalent functionality to runtime/secrets for Git operations.
- Migration not required: These commands already use the established
- Other secret management utilities (TLS, registry, etc.) (Migrate sourcesecret package to runtime/secrets APIs #5462)
-
mTLS Terminology and Consistency
Based on the implementation in notification-controller PR #1137, we've established important guidelines for mTLS terminology:
Historical Context
-
Before Flux 2.6: The term "mTLS" or "mutual" was not used in documentation
- Example: imagerepositories/#certificate-secret-reference
- Example: ocirepositories/#cert-secret-reference
- Example: buckets/#cert-secret-reference
- Example: helmrepositories/#cert-secret-reference
-
Flux 2.6: First mention of "mutual TLS"
Decision
We will maintain consistency with pkg/runtime/secrets definition of mTLS:
- mTLS configuration:
tls.crt
+tls.key
+ optionalca.crt
- This definition should be used consistently across all controllers when implementing
TLSConfigFromSecret
Metadata
Metadata
Assignees
Labels
umbrella-issueUmbrella issue for tracking progress of a larger effortUmbrella issue for tracking progress of a larger effort