{"modulePath":"github.com/openshift/controller-runtime-common","version":"v0.0.0-20261026124434-bdfc411d93cd","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package tls\n\nPackage tls provides utilities for working with OpenShift TLS profiles.\n\n## Constants\n\n```go\nconst (\n\t// APIServerName is the name of the APIServer resource in the cluster.\n\tAPIServerName = \"cluster\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrCustomProfileNil is returned when a custom TLS profile is specified but the Custom field is nil.\n\tErrCustomProfileNil = errors.New(\"custom TLS profile specified but Custom field is nil\")\n\n\t// DefaultTLSCiphers are the default TLS ciphers for API servers.\n\tDefaultTLSCiphers = configv1.TLSProfiles[configv1.TLSProfileIntermediateType].Ciphers //nolint:gochecknoglobals\n\t// DefaultMinTLSVersion is the default minimum TLS version for API servers.\n\tDefaultMinTLSVersion = configv1.TLSProfiles[configv1.TLSProfileIntermediateType].MinTLSVersion //nolint:gochecknoglobals\n\n\t// HTTP2NextProtos are the ALPN protocols advertised when HTTP/2 is enabled,\n\t// with HTTP/1.1 fallback.\n\tHTTP2NextProtos = []string{\"h2\", \"http/1.1\"} //nolint:gochecknoglobals\n\n\t// HTTP1NextProtos are the ALPN protocols advertised when HTTP/2 is disabled,\n\t// restricting negotiation to HTTP/1.1 only. This provides defense-in-depth\n\t// against HTTP/2 Rapid Reset (CVE-2023-44487, CVE-2023-39325) alongside\n\t// the primary fixes in Go 1.21.3+ and golang.org/x/net v0.17.0+.\n\tHTTP1NextProtos = []string{\"http/1.1\"} //nolint:gochecknoglobals\n)\n```\n\n## Functions\n\n```go\nfunc FetchAPIServerTLSAdherencePolicy(ctx context.Context, k8sClient client.Client) (configv1.TLSAdherencePolicy, error)\n```\nFetchAPIServerTLSAdherencePolicy fetches the TLS adherence policy configured in APIServer. If no policy is configured, the default policy is returned.\n\n```go\nfunc FetchAPIServerTLSProfile(ctx context.Context, k8sClient client.Client) (configv1.TLSProfileSpec, error)\n```\nFetchAPIServerTLSProfile fetches the TLS profile spec configured in APIServer. If no profile is configured, the default profile is returned.\n\n```go\nfunc GetTLSProfileSpec(profile *configv1.TLSSecurityProfile) (configv1.TLSProfileSpec, error)\n```\nGetTLSProfileSpec returns TLSProfileSpec for the given profile. If no profile is configured, the default profile is returned.\n\n```go\nfunc NewTLSConfigFromProfile(profile configv1.TLSProfileSpec) (tlsConfig func(*tls.Config), unsupported []string, err error)\n```\nNewTLSConfigFromProfile returns a function that configures a tls.Config based on the provided TLSProfileSpec, along with any cipher names from the profile that are not supported by the library-go crypto package. It returns an error when the minimum TLS version is invalid. The returned function is intended to be used with controller-runtime's TLSOpts.\n\nNote: CipherSuites are only set when MinVersion is below TLS 1.3, as Go's TLS 1.3 implementation does not allow configuring cipher suites - all TLS 1.3 ciphers are always enabled. See: [https://github.com/golang/go/issues/29349](https://github.com/golang/go/issues/29349)\n\n```go\nfunc SetNextProtos(protos ...string) func(*tls.Config)\n```\nSetNextProtos returns a TLS configuration function that sets the ALPN protocol negotiation list on a tls.Config. Empty strings are silently ignored, which allows conditional protocol inclusion. The returned function is intended to be used with controller-runtime's TLSOpts.\n\nExample:\n\n\t// Disable HTTP/2:\n\topenshifttls.SetNextProtos(\"http/1.1\")\n\n\t// Enable HTTP/2 with fallback:\n\topenshifttls.SetNextProtos(\"h2\", \"http/1.1\")\n\n\t// Using the well-known protocol lists:\n\topenshifttls.SetNextProtos(openshifttls.HTTP1NextProtos...)\n\topenshifttls.SetNextProtos(openshifttls.HTTP2NextProtos...)\n\n## Types\n\n```go\ntype SecurityProfileWatcher struct {\n\tclient.Client\n\n\t// InitialTLSProfileSpec is the TLS profile spec that was configured when the operator started.\n\tInitialTLSProfileSpec configv1.TLSProfileSpec\n\n\t// InitialTLSAdherencePolicy is the TLS adherence policy that was configured when the operator started.\n\tInitialTLSAdherencePolicy configv1.TLSAdherencePolicy\n\n\t// OnProfileChange is a function that will be called when the TLS profile changes.\n\t// It receives the reconcile context, old and new TLS profile specs.\n\t// This allows the caller to make decisions based on the actual profile changes.\n\t//\n\t// The most common use case for this callback is\n\t// to trigger a graceful shutdown of the operator\n\t// to make it pick up the new configuration.\n\t//\n\t// Example:\n\t//\n\t// \t// Create a context that can be cancelled when there is a need to shut down the manager.\n\t//  ctx, cancel := context.WithCancel(ctrl.SetupSignalHandler())\n\t//  defer cancel()\n\t//\n\t//  watcher := \u0026SecurityProfileWatcher{\n\t// \t  OnProfileChange: func(ctx context.Context, old, new configv1.TLSProfileSpec) {\n\t//      logger.Infof(\"TLS profile has changed, initiating a shutdown to reload it. %q: %+v, %q: %+v\",\n\t//        \"old profile\", old,\n\t//        \"new profile\", new,\n\t//      )\n\t//      // Cancel the outer context to trigger a graceful shutdown of the manager.\n\t//      cancel()\n\t//    },\n\t//  }\n\tOnProfileChange func(ctx context.Context, oldTLSProfileSpec, newTLSProfileSpec configv1.TLSProfileSpec)\n\n\t// OnAdherencePolicyChange is a function that will be called when the TLS adherence policy changes.\n\tOnAdherencePolicyChange func(ctx context.Context, oldTLSAdherencePolicy, newTLSAdherencePolicy configv1.TLSAdherencePolicy)\n}\n```\nSecurityProfileWatcher watches the APIServer object for TLS profile changes and triggers a graceful shutdown when the profile changes.\n\n```go\nfunc (r *SecurityProfileWatcher) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)\n```\nReconcile watches for changes to the APIServer TLS profile and triggers a shutdown when the profile changes from the initial configuration.\n\n```go\nfunc (r *SecurityProfileWatcher) SetupWithManager(mgr ctrl.Manager) error\n```\nSetupWithManager sets up the controller with the Manager.\n\n","path":"github.com/openshift/controller-runtime-common/pkg/tls","name":"tls","synopsis":"Package tls provides utilities for working with OpenShift TLS profiles.","isRedistributable":true}
