Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/imageutils/sys_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ func (b *SysContextBuilder) hasCerts() bool {
return b.controllerConfig != nil &&
(len(b.controllerConfig.Spec.ImageRegistryBundleData) > 0 ||
len(b.controllerConfig.Spec.ImageRegistryBundleUserData) > 0 ||
len(b.controllerConfig.Spec.AdditionalTrustBundle) > 0)
len(b.controllerConfig.Spec.AdditionalTrustBundle) > 0 ||
len(b.controllerConfig.Spec.RootCAData) > 0)
}

// buildAuth configures authentication by writing the Docker secret as authfile.json
Expand Down Expand Up @@ -210,7 +211,7 @@ func (b *SysContextBuilder) buildCerts(sysContext *SysContext) error {
// a common CA bundle is given by AdditionalTrustBundle we need to create a temporal bundle
// that concatenates all the bundles into a single file and pass that to the lib.
// We loose the ability to isolate CAs per registry till the fix in the library lands
if len(b.controllerConfig.Spec.AdditionalTrustBundle) > 0 {
if len(b.controllerConfig.Spec.AdditionalTrustBundle) > 0 || len(b.controllerConfig.Spec.RootCAData) > 0 {
var certBundle bytes.Buffer

for _, irb := range b.controllerConfig.Spec.ImageRegistryBundleData {
Expand All @@ -228,6 +229,12 @@ func (b *SysContextBuilder) buildCerts(sysContext *SysContext) error {
certBundle.WriteString("\n")
}

// Append RootCA data. This is required to access the InternalReleaseImage registry
if len(b.controllerConfig.Spec.RootCAData) > 0 {
certBundle.Write(b.controllerConfig.Spec.RootCAData)
certBundle.WriteString("\n")
}

// Write merged bundle to file
bundlePath := filepath.Join(certsDir, "ca-bundle.crt")
if err := os.WriteFile(bundlePath, certBundle.Bytes(), 0o644); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/imageutils/sys_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuOSW8w==
expectTempDir: false, // Proxy doesn't need temp dir
expectProxy: true,
},
{
name: "WithControllerConfig only - just rootCA",
controllerConfig: &mcfgv1.ControllerConfig{
Spec: mcfgv1.ControllerConfigSpec{
RootCAData: []byte(`-----BEGIN CERTIFICATE-----
MIICljCCAX4CCQCKz8Vz4VR5+jANBgkqhkiG9w0BAQsFADANMQswCQYDVQQGEwJV
UzAeFw0yMDAxMDEwMDAwMDBaFw0zMDAxMDEwMDAwMDBaMA0xCzAJBgNVBAYTAlVT
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuOSW8w==
-----END CERTIFICATE-----`),
},
},
expectTempDir: true,
expectCerts: true,
},
{
name: "Both WithSecret and WithControllerConfig",
secret: &corev1.Secret{
Expand Down