Skip to content

Commit ec49f0b

Browse files
committed
Change way how certificates are mounted into the container
1 parent b03870b commit ec49f0b

6 files changed

Lines changed: 79 additions & 16 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ build-helm: helm
216216
mkdir -p dist
217217
helm package charts/kvm-node-agent -d dist/
218218

219-
upload-helm: build-helm
219+
helm-push: build-helm
220220
helm push dist/kvm-node-agent* ${OCI}
221221

222222
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist

charts/kvm-node-agent/templates/daemonset.yaml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,31 @@ spec:
6969
- mountPath: /etc/os-release
7070
name: os-release
7171
readOnly: true
72-
- mountPath: /pki
73-
name: pki
72+
- mountPath: /pki/CA
73+
name: pki-ca
74+
- mountPath: /pki/libvirt
75+
name: pki-libvirt
76+
- mountPath: /pki/qemu
77+
name: pki-qemu
78+
initContainers:
79+
- command:
80+
- sh
81+
- -c
82+
- cd /host/etc/pki && for i in CA libvirt qemu; do if [ -L ${i} ]; then rm ${i};
83+
fi; done && mkdir -p CA libvirt qemu && chown 42438:42438 CA libvirt qemu && chmod
84+
0755 CA libvirt qemu
85+
env:
86+
- name: KUBERNETES_CLUSTER_DOMAIN
87+
value: {{ quote .Values.kubernetesClusterDomain }}
88+
image: {{ .Values.controllerManager.createPkiDirs.image.repository }}:{{ .Values.controllerManager.createPkiDirs.image.tag
89+
| default .Chart.AppVersion }}
90+
name: create-pki-dirs
91+
resources: {}
92+
securityContext: {{- toYaml .Values.controllerManager.createPkiDirs.containerSecurityContext
93+
| nindent 10 }}
94+
volumeMounts:
95+
- mountPath: /host
96+
name: host
7497
nodeSelector: {{- toYaml .Values.controllerManager.nodeSelector | nindent 8 }}
7598
securityContext: {{- toYaml .Values.controllerManager.podSecurityContext | nindent
7699
8 }}
@@ -94,6 +117,17 @@ spec:
94117
type: File
95118
name: os-release
96119
- hostPath:
97-
path: /var/lib/kvm-node-agent
98-
type: Directory
99-
name: pki
120+
path: /etc/pki/CA
121+
type: DirectoryOrCreate
122+
name: pki-ca
123+
- hostPath:
124+
path: /etc/pki/libvirt
125+
type: DirectoryOrCreate
126+
name: pki-libvirt
127+
- hostPath:
128+
path: /etc/pki/qemu
129+
type: DirectoryOrCreate
130+
name: pki-qemu
131+
- hostPath:
132+
path: /
133+
name: host

charts/kvm-node-agent/values.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
controllerManager:
2+
createPkiDirs:
3+
containerSecurityContext:
4+
runAsUser: 0
5+
image:
6+
repository: busybox
7+
tag: "1.28"
28
manager:
39
args:
410
- --health-probe-bind-address=:8081
@@ -23,7 +29,6 @@ controllerManager:
2329
nodeSelector:
2430
nova.openstack.cloud.sap/virt-driver: libvirt
2531
podSecurityContext:
26-
runAsNonRoot: true
2732
supplementalGroups:
2833
- 108
2934
serviceAccount:

config/manager/manager.yaml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,18 @@ spec:
5353
# values:
5454
# - linux
5555
securityContext:
56-
runAsNonRoot: true
56+
# runAsNonRoot: true
5757
supplementalGroups:
5858
- 108 # libvirt group
59+
initContainers:
60+
- name: create-pki-dirs
61+
securityContext:
62+
runAsUser: 0
63+
image: busybox:1.28
64+
command: ['sh', '-c', 'cd /host/etc/pki && for i in CA libvirt qemu; do if [ -L ${i} ]; then rm ${i}; fi; done && mkdir -p CA libvirt qemu && chown 42438:42438 CA libvirt qemu && chmod 0755 CA libvirt qemu']
65+
volumeMounts:
66+
- mountPath: /host
67+
name: host
5968
containers:
6069
- command:
6170
- /manager
@@ -115,8 +124,12 @@ spec:
115124
- mountPath: /etc/os-release
116125
name: os-release
117126
readOnly: true
118-
- mountPath: /pki
119-
name: pki
127+
- mountPath: /pki/CA
128+
name: pki-ca
129+
- mountPath: /pki/libvirt
130+
name: pki-libvirt
131+
- mountPath: /pki/qemu
132+
name: pki-qemu
120133
serviceAccountName: controller-manager
121134
terminationGracePeriodSeconds: 10
122135
volumes:
@@ -136,7 +149,18 @@ spec:
136149
hostPath:
137150
path: /etc/os-release
138151
type: File
139-
- name: pki
152+
- name: pki-ca
153+
hostPath:
154+
path: /etc/pki/CA
155+
type: DirectoryOrCreate
156+
- name: pki-libvirt
157+
hostPath:
158+
path: /etc/pki/libvirt
159+
type: DirectoryOrCreate
160+
- name: pki-qemu
161+
hostPath:
162+
path: /etc/pki/qemu
163+
type: DirectoryOrCreate
164+
- name: host
140165
hostPath:
141-
path: /var/lib/kvm-node-agent
142-
type: Directory
166+
path: /

internal/certificates/manage_libvirt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func UpdateTLSCertificate(ctx context.Context, data map[string][]byte) error {
159159
}
160160

161161
// write the file
162-
if err := os.WriteFile(target, data[source], 0640); err != nil {
162+
if err := os.WriteFile(target, data[source], 0644); err != nil {
163163
return fmt.Errorf("failed to write targetFile %s: %w", target, err)
164164
}
165165
}

internal/controller/secret_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (r *SecretReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
7878

7979
// Save the last resource version to file system
8080
pki := os.Getenv("PKI_PATH")
81-
path := filepath.Join(pki, ".last_resource_version")
81+
path := filepath.Join(pki, "CA", ".last_resource_version")
8282
if err = os.WriteFile(path, []byte(secret.ResourceVersion), 0600); err != nil {
8383
// not a failure condition, just log the error
8484
log.Error(err, "failed to write last resource version", "path", path)
@@ -93,7 +93,7 @@ func (r *SecretReconciler) SetupWithManager(mgr ctrl.Manager) error {
9393
// Load the last resource version from file system, so we can skip
9494
// processing if the resource version hasn't changed
9595
pki := os.Getenv("PKI_PATH")
96-
path := filepath.Join(pki, ".last_resource_version")
96+
path := filepath.Join(pki, "CA", ".last_resource_version")
9797
if buf, err := os.ReadFile(path); err != nil {
9898
logger.Log.Info("No last resource version found for PKI secrets", "path", path)
9999
} else {

0 commit comments

Comments
 (0)