-
Notifications
You must be signed in to change notification settings - Fork 1.5k
CNTRLPLANE-2012: Add PKI config types, validation, and CR manifest generation #10593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-bot
merged 1 commit into
openshift:main
from
hasbro17:pki-1-types-and-manifest
Jun 29, 2026
+1,086
−1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package manifests | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "path" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "sigs.k8s.io/yaml" | ||
|
|
||
| configv1alpha1 "github.com/openshift/api/config/v1alpha1" | ||
| features "github.com/openshift/api/features" | ||
| "github.com/openshift/installer/pkg/asset" | ||
| "github.com/openshift/installer/pkg/asset/installconfig" | ||
| "github.com/openshift/installer/pkg/types" | ||
| pkidefaults "github.com/openshift/installer/pkg/types/pki" | ||
| ) | ||
|
|
||
| var pkiCfgFilename = path.Join(manifestDir, "cluster-pki-02-config.yaml") | ||
|
|
||
| // PKIConfiguration generates the PKI custom resource manifest. | ||
| type PKIConfiguration struct { | ||
| FileList []*asset.File | ||
| } | ||
|
|
||
| var _ asset.WritableAsset = (*PKIConfiguration)(nil) | ||
|
|
||
| // Name returns a human friendly name for the asset. | ||
| func (*PKIConfiguration) Name() string { | ||
| return "PKI Config" | ||
| } | ||
|
|
||
| // Dependencies returns all of the dependencies directly needed to generate | ||
| // the asset. | ||
| func (*PKIConfiguration) Dependencies() []asset.Asset { | ||
| return []asset.Asset{ | ||
| &installconfig.InstallConfig{}, | ||
| } | ||
| } | ||
|
|
||
| // Generate generates the PKI custom resource manifest. | ||
| // The manifest is only generated when the ConfigurablePKI feature gate is enabled. | ||
| func (p *PKIConfiguration) Generate(_ context.Context, dependencies asset.Parents) error { | ||
| installConfig := &installconfig.InstallConfig{} | ||
| dependencies.Get(installConfig) | ||
|
|
||
| if !installConfig.Config.Enabled(features.FeatureGateConfigurablePKI) { | ||
| return nil | ||
| } | ||
|
|
||
| certMgmt := configv1alpha1.PKICertificateManagement{ | ||
| Mode: configv1alpha1.PKICertificateManagementModeDefault, | ||
| } | ||
|
|
||
| if installConfig.Config.PKI != nil { | ||
| profile := pkidefaults.DefaultPKIProfile() | ||
| profile.SignerCertificates = convertToAPICertConfig(installConfig.Config.PKI.SignerCertificates) | ||
|
|
||
| certMgmt = configv1alpha1.PKICertificateManagement{ | ||
| Mode: configv1alpha1.PKICertificateManagementModeCustom, | ||
| Custom: configv1alpha1.CustomPKIPolicy{ | ||
| PKIProfile: profile, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| config := &configv1alpha1.PKI{ | ||
| TypeMeta: metav1.TypeMeta{ | ||
| APIVersion: configv1alpha1.SchemeGroupVersion.String(), | ||
| Kind: "PKI", | ||
| }, | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "cluster", | ||
| }, | ||
| Spec: configv1alpha1.PKISpec{ | ||
| CertificateManagement: certMgmt, | ||
| }, | ||
| } | ||
|
|
||
| configData, err := yaml.Marshal(config) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal PKI config: %w", err) | ||
| } | ||
|
|
||
| p.FileList = []*asset.File{ | ||
| { | ||
| Filename: pkiCfgFilename, | ||
| Data: configData, | ||
| }, | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Files returns the files generated by the asset. | ||
| func (p *PKIConfiguration) Files() []*asset.File { | ||
| return p.FileList | ||
| } | ||
|
|
||
| // Load returns false since this asset is not written to disk by the installer. | ||
| func (p *PKIConfiguration) Load(f asset.FileFetcher) (bool, error) { | ||
| return false, nil | ||
| } | ||
|
|
||
| // convertToAPICertConfig converts the installer CertificateConfig | ||
| // to the openshift/api configv1alpha1.CertificateConfig for use in the PKI CR manifest. | ||
| func convertToAPICertConfig(certConf types.CertificateConfig) configv1alpha1.CertificateConfig { | ||
| out := configv1alpha1.CertificateConfig{ | ||
| Key: configv1alpha1.KeyConfig{ | ||
| Algorithm: configv1alpha1.KeyAlgorithm(certConf.Key.Algorithm), | ||
| }, | ||
| } | ||
| if certConf.Key.RSA != nil { | ||
| out.Key.RSA = configv1alpha1.RSAKeyConfig{KeySize: certConf.Key.RSA.KeySize} | ||
| } | ||
| if certConf.Key.ECDSA != nil { | ||
| out.Key.ECDSA = configv1alpha1.ECDSAKeyConfig{Curve: configv1alpha1.ECDSACurve(certConf.Key.ECDSA.Curve)} | ||
| } | ||
| return out | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| package manifests | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "sigs.k8s.io/yaml" | ||
|
|
||
| configv1 "github.com/openshift/api/config/v1" | ||
| configv1alpha1 "github.com/openshift/api/config/v1alpha1" | ||
| "github.com/openshift/installer/pkg/asset" | ||
| "github.com/openshift/installer/pkg/asset/installconfig" | ||
| "github.com/openshift/installer/pkg/types" | ||
| ) | ||
|
|
||
| func TestPKIConfigurationGenerate(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| installConfig *types.InstallConfig | ||
| expectEmpty bool | ||
| expectMode configv1alpha1.PKICertificateManagementMode | ||
| expectSignerAlgo configv1alpha1.KeyAlgorithm | ||
| expectSignerRSA int32 | ||
| expectSignerCurve configv1alpha1.ECDSACurve | ||
| expectDefaultsAlgo configv1alpha1.KeyAlgorithm | ||
| expectDefaultsRSA int32 | ||
| expectDefaultsCurve configv1alpha1.ECDSACurve | ||
| }{ | ||
| { | ||
| name: "feature gate disabled - no manifest generated", | ||
| installConfig: &types.InstallConfig{ | ||
| FeatureSet: configv1.Default, | ||
| }, | ||
| expectEmpty: true, | ||
| }, | ||
| { | ||
| name: "feature gate enabled, pki nil - mode Default", | ||
| installConfig: &types.InstallConfig{ | ||
| FeatureSet: configv1.TechPreviewNoUpgrade, | ||
| }, | ||
| expectEmpty: false, | ||
| expectMode: configv1alpha1.PKICertificateManagementModeDefault, | ||
| }, | ||
| { | ||
| name: "feature gate enabled, pki RSA-4096", | ||
| installConfig: &types.InstallConfig{ | ||
| FeatureSet: configv1.TechPreviewNoUpgrade, | ||
| PKI: &types.PKIConfig{ | ||
| SignerCertificates: types.CertificateConfig{ | ||
| Key: types.KeyConfig{ | ||
| Algorithm: types.KeyAlgorithmRSA, | ||
| RSA: &types.RSAKeyConfig{KeySize: 4096}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expectEmpty: false, | ||
| expectMode: configv1alpha1.PKICertificateManagementModeCustom, | ||
| expectSignerAlgo: configv1alpha1.KeyAlgorithmRSA, | ||
| expectSignerRSA: 4096, | ||
| expectDefaultsAlgo: configv1alpha1.KeyAlgorithmRSA, | ||
| expectDefaultsRSA: 4096, | ||
| }, | ||
| { | ||
| name: "feature gate enabled, pki ECDSA P-384", | ||
| installConfig: &types.InstallConfig{ | ||
| FeatureSet: configv1.TechPreviewNoUpgrade, | ||
| PKI: &types.PKIConfig{ | ||
| SignerCertificates: types.CertificateConfig{ | ||
| Key: types.KeyConfig{ | ||
| Algorithm: types.KeyAlgorithmECDSA, | ||
| ECDSA: &types.ECDSAKeyConfig{Curve: types.ECDSACurveP384}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expectEmpty: false, | ||
| expectMode: configv1alpha1.PKICertificateManagementModeCustom, | ||
| expectSignerAlgo: configv1alpha1.KeyAlgorithmECDSA, | ||
| expectSignerCurve: configv1alpha1.ECDSACurveP384, | ||
| expectDefaultsAlgo: configv1alpha1.KeyAlgorithmRSA, | ||
| expectDefaultsRSA: 4096, | ||
| }, | ||
| { | ||
| name: "feature gate enabled, pki RSA-2048 explicit", | ||
| installConfig: &types.InstallConfig{ | ||
| FeatureSet: configv1.TechPreviewNoUpgrade, | ||
| PKI: &types.PKIConfig{ | ||
| SignerCertificates: types.CertificateConfig{ | ||
| Key: types.KeyConfig{ | ||
| Algorithm: types.KeyAlgorithmRSA, | ||
| RSA: &types.RSAKeyConfig{KeySize: 2048}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| expectEmpty: false, | ||
| expectMode: configv1alpha1.PKICertificateManagementModeCustom, | ||
| expectSignerAlgo: configv1alpha1.KeyAlgorithmRSA, | ||
| expectSignerRSA: 2048, | ||
| expectDefaultsAlgo: configv1alpha1.KeyAlgorithmRSA, | ||
| expectDefaultsRSA: 4096, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| parents := asset.Parents{} | ||
| parents.Add(installconfig.MakeAsset(tc.installConfig)) | ||
|
|
||
| pkiAsset := &PKIConfiguration{} | ||
| err := pkiAsset.Generate(context.Background(), parents) | ||
| if !assert.NoError(t, err) { | ||
| return | ||
| } | ||
|
|
||
| if tc.expectEmpty { | ||
| assert.Empty(t, pkiAsset.Files()) | ||
| return | ||
| } | ||
|
|
||
| if !assert.Len(t, pkiAsset.Files(), 1) { | ||
| return | ||
| } | ||
| assert.Equal(t, "manifests/cluster-pki-02-config.yaml", pkiAsset.Files()[0].Filename) | ||
|
|
||
| // Unmarshal and verify the CR structure | ||
| var pkiCR configv1alpha1.PKI | ||
| err = yaml.Unmarshal(pkiAsset.Files()[0].Data, &pkiCR) | ||
| if !assert.NoError(t, err) { | ||
| return | ||
| } | ||
|
|
||
| assert.Equal(t, "config.openshift.io/v1alpha1", pkiCR.APIVersion) | ||
| assert.Equal(t, "PKI", pkiCR.Kind) | ||
| assert.Equal(t, "cluster", pkiCR.Name) | ||
| assert.Equal(t, tc.expectMode, pkiCR.Spec.CertificateManagement.Mode) | ||
|
|
||
| if tc.expectMode != configv1alpha1.PKICertificateManagementModeCustom { | ||
| return | ||
| } | ||
|
|
||
| profile := pkiCR.Spec.CertificateManagement.Custom.PKIProfile | ||
|
|
||
| // Verify defaults | ||
| assert.Equal(t, tc.expectDefaultsAlgo, profile.Defaults.Key.Algorithm) | ||
| if tc.expectDefaultsAlgo == configv1alpha1.KeyAlgorithmRSA { | ||
| assert.Equal(t, tc.expectDefaultsRSA, profile.Defaults.Key.RSA.KeySize) | ||
| } | ||
| if tc.expectDefaultsAlgo == configv1alpha1.KeyAlgorithmECDSA { | ||
| assert.Equal(t, tc.expectDefaultsCurve, profile.Defaults.Key.ECDSA.Curve) | ||
| } | ||
|
|
||
| // Verify signerCertificates | ||
| assert.Equal(t, tc.expectSignerAlgo, profile.SignerCertificates.Key.Algorithm) | ||
| if tc.expectSignerAlgo == configv1alpha1.KeyAlgorithmRSA { | ||
| assert.Equal(t, tc.expectSignerRSA, profile.SignerCertificates.Key.RSA.KeySize) | ||
| } | ||
| if tc.expectSignerAlgo == configv1alpha1.KeyAlgorithmECDSA { | ||
| assert.Equal(t, tc.expectSignerCurve, profile.SignerCertificates.Key.ECDSA.Curve) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.