Skip to content

Commit ecd5df4

Browse files
committed
fix usage of host and user CA bundle in the agent ignition
This patch ensures to generate a smaller user-ca-bundle configmap when the mirror config is provided, along with the additionalTrustBundle content
1 parent b70e65b commit ecd5df4

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

data/data/agent/systemd/units/agent-import-cluster.service.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ EnvironmentFile=/usr/local/share/assisted-service/assisted-service.env
1414
EnvironmentFile=/etc/assisted/add-nodes.env
1515
ExecStartPre=/bin/rm -f %t/%n.ctr-id
1616
ExecStartPre=/usr/local/bin/wait-for-assisted-service.sh
17-
ExecStart=podman run --net host --cidfile=%t/%n.ctr-id --cgroups=no-conmon --log-driver=journald --rm --pod-id-file=%t/assisted-service-pod.pod-id --replace --name=agent-import-cluster -v /etc/assisted/manifests:/manifests -v /etc/assisted/extra-manifests:/extra-manifests -v /etc/pki/ca-trust:/etc/pki/ca-trust:z {{ if .HaveMirrorConfig }}-v /etc/containers:/etc/containers{{ end }} --env SERVICE_BASE_URL --env OPENSHIFT_INSTALL_RELEASE_IMAGE_MIRROR --env CLUSTER_ID --env CLUSTER_NAME --env CLUSTER_API_VIP_DNS_NAME $SERVICE_IMAGE /usr/local/bin/agent-installer-client importCluster
17+
ExecStart=podman run --net host --cidfile=%t/%n.ctr-id --cgroups=no-conmon --log-driver=journald --rm --pod-id-file=%t/assisted-service-pod.pod-id --replace --name=agent-import-cluster -v /etc/assisted/manifests:/manifests -v /etc/assisted/extra-manifests:/extra-manifests {{ if .HaveMirrorConfig }}-v /etc/containers:/etc/containers{{ end }} {{.CaBundleMount}} --env SERVICE_BASE_URL --env OPENSHIFT_INSTALL_RELEASE_IMAGE_MIRROR --env CLUSTER_ID --env CLUSTER_NAME --env CLUSTER_API_VIP_DNS_NAME $SERVICE_IMAGE /usr/local/bin/agent-installer-client importCluster
1818
ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
1919
ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id
2020

data/data/agent/systemd/units/agent-register-cluster.service.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ EnvironmentFile=/usr/local/share/assisted-service/agent-images.env
1313
EnvironmentFile=/usr/local/share/assisted-service/assisted-service.env
1414
ExecStartPre=/bin/rm -f %t/%n.ctr-id
1515
ExecStartPre=/usr/local/bin/wait-for-assisted-service.sh
16-
ExecStart=podman run --net host --cidfile=%t/%n.ctr-id --cgroups=no-conmon --log-driver=journald --rm --pod-id-file=%t/assisted-service-pod.pod-id --replace --name=agent-register-cluster -v /etc/assisted/manifests:/manifests -v /etc/assisted/extra-manifests:/extra-manifests -v /etc/pki/ca-trust:/etc/pki/ca-trust:z {{ if .HaveMirrorConfig }}-v /etc/containers:/etc/containers{{ end }} --env SERVICE_BASE_URL --env OPENSHIFT_INSTALL_RELEASE_IMAGE_MIRROR $SERVICE_IMAGE /usr/local/bin/agent-installer-client registerCluster
16+
ExecStart=podman run --net host --cidfile=%t/%n.ctr-id --cgroups=no-conmon --log-driver=journald --rm --pod-id-file=%t/assisted-service-pod.pod-id --replace --name=agent-register-cluster -v /etc/assisted/manifests:/manifests -v /etc/assisted/extra-manifests:/extra-manifests {{ if .HaveMirrorConfig }}-v /etc/containers:/etc/containers{{ end }} {{.CaBundleMount}} --env SERVICE_BASE_URL --env OPENSHIFT_INSTALL_RELEASE_IMAGE_MIRROR $SERVICE_IMAGE /usr/local/bin/agent-installer-client registerCluster
1717
ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
1818
ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id
1919

data/data/agent/systemd/units/assisted-service.service.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Restart=on-failure
1313
TimeoutStartSec=500
1414
TimeoutStopSec=300
1515
ExecStartPre=/bin/rm -f %t/%n.ctr-id
16-
ExecStart=/usr/bin/podman run --net host --cidfile=%t/%n.ctr-id --cgroups=no-conmon --log-driver=journald --rm --pod-id-file=%t/assisted-service-pod.pod-id --sdnotify=conmon --replace -d --name=service -v /opt/agent/tls:/opt/agent/tls:z {{ if .HaveMirrorConfig }}-v /etc/containers:/etc/containers{{ end }} -v /etc/pki/ca-trust:/etc/pki/ca-trust --env-file=/etc/assisted/rendezvous-host.env --env-file=/usr/local/share/assisted-service/assisted-service.env --env-file=/usr/local/share/assisted-service/images.env --env-file=/etc/assisted/node0 --env-file=/usr/local/share/assisted-service/agent-images.env $SERVICE_IMAGE
16+
ExecStart=/usr/bin/podman run --net host --cidfile=%t/%n.ctr-id --cgroups=no-conmon --log-driver=journald --rm --pod-id-file=%t/assisted-service-pod.pod-id --sdnotify=conmon --replace -d --name=service -v /opt/agent/tls:/opt/agent/tls:z {{ if .HaveMirrorConfig }}-v /etc/containers:/etc/containers{{ end }} {{.CaBundleMount}} --env-file=/etc/assisted/rendezvous-host.env --env-file=/usr/local/share/assisted-service/assisted-service.env --env-file=/usr/local/share/assisted-service/images.env --env-file=/etc/assisted/node0 --env-file=/usr/local/share/assisted-service/agent-images.env $SERVICE_IMAGE
1717
ExecStop=/usr/bin/podman stop --ignore --cidfile=%t/%n.ctr-id
1818
ExecStopPost=/usr/bin/podman rm -f --ignore --cidfile=%t/%n.ctr-id
1919
Type=notify

pkg/asset/agent/image/ignition.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type agentTemplateData struct {
7575
PublicKeyPEM string
7676
PrivateKeyPEM string
7777
WorkflowType workflow.AgentWorkflowType
78+
CaBundleMount string
7879
}
7980

8081
// Name returns the human-friendly name of the asset.
@@ -238,6 +239,8 @@ func (a *Ignition) Generate(dependencies asset.Parents) error {
238239
}
239240
a.CPUArch = *osImage.CPUArchitecture
240241

242+
caBundleMount := defineCABundleMount(registriesConfig, registryCABundle)
243+
241244
agentTemplateData := getTemplateData(
242245
clusterName,
243246
agentManifests.GetPullSecretData(),
@@ -253,7 +256,8 @@ func (a *Ignition) Generate(dependencies asset.Parents) error {
253256
imageTypeISO,
254257
keyPairAsset.PrivateKey,
255258
keyPairAsset.PublicKey,
256-
agentWorkflow.Workflow)
259+
agentWorkflow.Workflow,
260+
caBundleMount)
257261

258262
err = bootstrap.AddStorageFiles(&config, "/", "agent/files", agentTemplateData)
259263
if err != nil {
@@ -368,7 +372,8 @@ func getTemplateData(name, pullSecret, releaseImageList, releaseImage,
368372
proxy *v1beta1.Proxy,
369373
imageTypeISO,
370374
privateKey, publicKey string,
371-
workflow workflow.AgentWorkflowType) *agentTemplateData {
375+
workflow workflow.AgentWorkflowType,
376+
caBundleMount string) *agentTemplateData {
372377
return &agentTemplateData{
373378
ServiceProtocol: "http",
374379
PullSecret: pullSecret,
@@ -387,6 +392,7 @@ func getTemplateData(name, pullSecret, releaseImageList, releaseImage,
387392
PrivateKeyPEM: privateKey,
388393
PublicKeyPEM: publicKey,
389394
WorkflowType: workflow,
395+
CaBundleMount: caBundleMount,
390396
}
391397
}
392398

@@ -480,6 +486,19 @@ func addMirrorData(config *igntypes.Config, registriesConfig *mirror.RegistriesC
480486
}
481487
}
482488

489+
func defineCABundleMount(registriesConfig *mirror.RegistriesConf, registryCABundle *mirror.CaBundle) string {
490+
// By default, the current host CA bundle is used (it will also contain eventually a user CA bundle, if
491+
// defined in the AdditionalTrustBundle field of install-config.yaml).
492+
hostSourceCABundle := "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem"
493+
494+
// If mirror registry is configured and the user provided a bundle, then let's mount just the user one.
495+
if len(registriesConfig.MirrorConfig) > 0 && registryCABundle.File != nil && len(registryCABundle.File.Data) > 0 {
496+
hostSourceCABundle = registryCABundlePath
497+
}
498+
499+
return fmt.Sprintf("-v %s:/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem:z", hostSourceCABundle)
500+
}
501+
483502
// Creates a file named with a host's MAC address. The desired hostname
484503
// is the file's content. The files are read by a systemd service that
485504
// sets the hostname using "hostnamectl set-hostname" when the ISO boots.

pkg/asset/agent/image/ignition_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestIgnition_getTemplateData(t *testing.T) {
9292
privateKey := "-----BEGIN EC PUBLIC KEY-----\nMFkwEwYHKoAiDHV4tg==\n-----END EC PUBLIC KEY-----\n"
9393
publicKey := "-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIOSCfDNmx0qe6dncV4tg==\n-----END EC PRIVATE KEY-----\n"
9494

95-
templateData := getTemplateData(clusterName, pullSecret, releaseImageList, releaseImage, releaseImageMirror, haveMirrorConfig, publicContainerRegistries, agentClusterInstall.Spec.ProvisionRequirements.ControlPlaneAgents, agentClusterInstall.Spec.ProvisionRequirements.WorkerAgents, infraEnvID, osImage, proxy, "minimal-iso", privateKey, publicKey, workflow.AgentWorkflowTypeInstall)
95+
templateData := getTemplateData(clusterName, pullSecret, releaseImageList, releaseImage, releaseImageMirror, haveMirrorConfig, publicContainerRegistries, agentClusterInstall.Spec.ProvisionRequirements.ControlPlaneAgents, agentClusterInstall.Spec.ProvisionRequirements.WorkerAgents, infraEnvID, osImage, proxy, "minimal-iso", privateKey, publicKey, workflow.AgentWorkflowTypeInstall, "")
9696
assert.Equal(t, clusterName, templateData.ClusterName)
9797
assert.Equal(t, "http", templateData.ServiceProtocol)
9898
assert.Equal(t, pullSecret, templateData.PullSecret)

0 commit comments

Comments
 (0)