Skip to content

Commit f4ffb45

Browse files
feat: rootless dind (#521)
1 parent 47eb2a8 commit f4ffb45

File tree

16 files changed

+228
-70
lines changed

16 files changed

+228
-70
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ venona/venona
4242
**/*.tgz
4343
**/charts/**/charts
4444
**/dry-run.yaml
45-
**/values-dev.yaml
45+
**/values-dev**.yaml
4646

4747
# coverage
4848
**/cover
4949

5050
# debug
51-
**/debug
51+
**/.debug
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
volumeProvisioner:
2+
env:
3+
IS_ROOTLESS: true
4+
dind-lv-monitor:
5+
image:
6+
tag: 1.30.0-rootless
7+
digest: sha256:712e549e6e843b04684647f17e0973f8047e0d60e6e8b38a693ea64dc75b0479
8+
containerSecurityContext:
9+
runAsUser: 1000
10+
podSecurityContext:
11+
fsGroup: 1000
12+
fsGroupChangePolicy: "OnRootMismatch"
13+
volumePermissions:
14+
enabled: true
15+
16+
runtime:
17+
dind:
18+
image:
19+
tag: 26.1.4-1.28.10-rootless
20+
digest: sha256:59dfc004eb22a8f09c8a3d585271a055af9df4591ab815bca418c24a2077f5c8
21+
userVolumeMounts:
22+
dind:
23+
name: dind
24+
mountPath: /home/rootless/.local/share/docker
25+
containerSecurityContext:
26+
privileged: true
27+
runAsUser: 1000
28+
podSecurityContext:
29+
fsGroup: 1000
30+
fsGroupChangePolicy: "OnRootMismatch"
31+
volumePermissions:
32+
enabled: true

charts/cf-runtime/Chart.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: v2
22
description: A Helm chart for Codefresh Runner
33
name: cf-runtime
4-
version: 7.0.1
4+
version: 7.1.0
55
keywords:
66
- codefresh
77
- runner
@@ -17,8 +17,14 @@ annotations:
1717
artifacthub.io/containsSecurityUpdates: "false"
1818
# Supported kinds: `added`, `changed`, `deprecated`, `removed`, `fixed`, `security`:
1919
artifacthub.io/changes: |
20-
- kind: security
21-
description: "updating k8s-agent"
20+
- kind: changed
21+
description: "(rootless runtime) Update dind-volume-provisioner and dind-volume-utils images"
22+
- kind: added
23+
description: "(rootless runtime) Add values-rootless.yaml example"
24+
- kind: changed
25+
description: "(dind) Update runtime environment spec to allow specifying podSecurityContext and containerSecurityContext for dind"
26+
- kind: fixed
27+
description: "Update helm unittests"
2228
dependencies:
2329
- name: cf-common
2430
repository: oci://quay.io/codefresh/charts

charts/cf-runtime/README.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Codefresh Runner
22

3-
![Version: 7.0.1](https://img.shields.io/badge/Version-7.0.1-informational?style=flat-square)
3+
![Version: 7.1.0](https://img.shields.io/badge/Version-7.1.0-informational?style=flat-square)
44

55
Helm chart for deploying [Codefresh Runner](https://codefresh.io/docs/docs/installation/codefresh-runner/) to Kubernetes.
66

@@ -715,14 +715,48 @@ volumeProvisioner:
715715
### Rootless DinD
716716
717717
DinD pod runs a `priviliged` container with **rootfull** docker.
718-
To run the docker daemon as non-root user (**rootless** mode), change dind image tag:
719718

720-
`values.yaml`
719+
To run the docker daemon as non-root user (**rootless** mode), refer to `values-rootless.yaml`:
720+
721721
```yaml
722+
volumeProvisioner:
723+
env:
724+
IS_ROOTLESS: true
725+
# -- Only if local volumes are used as backend storage (ignored for ebs/ebs-csi disks)
726+
dind-lv-monitor:
727+
image:
728+
tag: 1.30.0-rootless
729+
digest: sha256:712e549e6e843b04684647f17e0973f8047e0d60e6e8b38a693ea64dc75b0479
730+
containerSecurityContext:
731+
runAsUser: 1000
732+
podSecurityContext:
733+
fsGroup: 1000
734+
# Ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#configure-volume-permission-and-ownership-change-policy-for-pods
735+
fsGroupChangePolicy: "OnRootMismatch"
736+
# -- Enable initContainer to run chmod for /var/lib/codefresh/dind-volumes on host nodes
737+
volumePermissions:
738+
enabled: false
739+
722740
runtime:
723741
dind:
724742
image:
725-
tag: rootless
743+
tag: 26.1.4-1.28.10-rootless
744+
digest: sha256:59dfc004eb22a8f09c8a3d585271a055af9df4591ab815bca418c24a2077f5c8
745+
userVolumeMounts:
746+
dind:
747+
name: dind
748+
mountPath: /home/rootless/.local/share/docker
749+
containerSecurityContext:
750+
privileged: true
751+
runAsUser: 1000
752+
podSecurityContext:
753+
fsGroup: 1000
754+
# Ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#configure-volume-permission-and-ownership-change-policy-for-pods
755+
fsGroupChangePolicy: "OnRootMismatch"
756+
# -- Enable initContainer to run chmod for /home/rootless in DinD pod
757+
# !!! Will slow down dind pod startup
758+
volumePermissions:
759+
enabled: true
726760
```
727761

728762
### ARM
@@ -1143,13 +1177,15 @@ Go to [https://<YOUR_ONPREM_DOMAIN_HERE>/admin/runtime-environments/system](http
11431177
| runtime.accounts | list | `[]` | (for On-Premise only) Assign accounts to runtime (list of account ids) |
11441178
| runtime.agent | bool | `true` | (for On-Premise only) Enable agent |
11451179
| runtime.description | string | `""` | Runtime description |
1146-
| runtime.dind | object | `{"affinity":{},"env":{"DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE":true},"image":{"digest":"sha256:ccaf26ab24db0e00760beba79ce1810a12aef5be296f538ceab416af9ec481f7","pullPolicy":"IfNotPresent","registry":"quay.io","repository":"codefresh/dind","tag":"26.1.4-1.28.7"},"nodeSelector":{},"podAnnotations":{},"podLabels":{},"pvcs":{"dind":{"annotations":{},"name":"dind","reuseVolumeSelector":"codefresh-app,io.codefresh.accountName","reuseVolumeSortOrder":"pipeline_id","storageClassName":"{{ include \"dind-volume-provisioner.storageClassName\" . }}","volumeSize":"16Gi"}},"resources":{"limits":{"cpu":"400m","memory":"800Mi"},"requests":null},"schedulerName":"","serviceAccount":"codefresh-engine","terminationGracePeriodSeconds":30,"tolerations":[],"userAccess":true,"userVolumeMounts":{},"userVolumes":{}}` | Parameters for DinD (docker-in-docker) pod (aka "runtime" pod). |
1180+
| runtime.dind | object | `{"affinity":{},"containerSecurityContext":{},"env":{"DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE":true},"image":{"digest":"sha256:ccaf26ab24db0e00760beba79ce1810a12aef5be296f538ceab416af9ec481f7","pullPolicy":"IfNotPresent","registry":"quay.io","repository":"codefresh/dind","tag":"26.1.4-1.28.7"},"nodeSelector":{},"podAnnotations":{},"podLabels":{},"podSecurityContext":{},"pvcs":{"dind":{"annotations":{},"name":"dind","reuseVolumeSelector":"codefresh-app,io.codefresh.accountName","reuseVolumeSortOrder":"pipeline_id","storageClassName":"{{ include \"dind-volume-provisioner.storageClassName\" . }}","volumeSize":"16Gi"}},"resources":{"limits":{"cpu":"400m","memory":"800Mi"},"requests":null},"schedulerName":"","serviceAccount":"codefresh-engine","terminationGracePeriodSeconds":30,"tolerations":[],"userAccess":true,"userVolumeMounts":{},"userVolumes":{},"volumePermissions":{"enabled":false,"image":{"digest":"sha256:2995c82e8e723d9a5c8585cb8e901d1c50e3c2759031027d3bff577449435157","registry":"docker.io","repository":"alpine","tag":3.18},"resources":{},"securityContext":{"runAsUser":0}}}` | Parameters for DinD (docker-in-docker) pod (aka "runtime" pod). |
11471181
| runtime.dind.affinity | object | `{}` | Set affinity |
1182+
| runtime.dind.containerSecurityContext | object | `{}` | Set container security context. |
11481183
| runtime.dind.env | object | `{"DOCKER_ENABLE_DEPRECATED_PULL_SCHEMA_1_IMAGE":true}` | Set additional env vars. |
11491184
| runtime.dind.image | object | `{"digest":"sha256:ccaf26ab24db0e00760beba79ce1810a12aef5be296f538ceab416af9ec481f7","pullPolicy":"IfNotPresent","registry":"quay.io","repository":"codefresh/dind","tag":"26.1.4-1.28.7"}` | Set dind image. |
11501185
| runtime.dind.nodeSelector | object | `{}` | Set node selector. |
11511186
| runtime.dind.podAnnotations | object | `{}` | Set pod annotations. |
11521187
| runtime.dind.podLabels | object | `{}` | Set pod labels. |
1188+
| runtime.dind.podSecurityContext | object | `{}` | Set security context for the pod. |
11531189
| runtime.dind.pvcs | object | `{"dind":{"annotations":{},"name":"dind","reuseVolumeSelector":"codefresh-app,io.codefresh.accountName","reuseVolumeSortOrder":"pipeline_id","storageClassName":"{{ include \"dind-volume-provisioner.storageClassName\" . }}","volumeSize":"16Gi"}}` | PV claim spec parametes. |
11541190
| runtime.dind.pvcs.dind | object | `{"annotations":{},"name":"dind","reuseVolumeSelector":"codefresh-app,io.codefresh.accountName","reuseVolumeSortOrder":"pipeline_id","storageClassName":"{{ include \"dind-volume-provisioner.storageClassName\" . }}","volumeSize":"16Gi"}` | Default dind PVC parameters |
11551191
| runtime.dind.pvcs.dind.annotations | object | `{}` | PV annotations. |
@@ -1234,7 +1270,7 @@ Go to [https://<YOUR_ONPREM_DOMAIN_HERE>/admin/runtime-environments/system](http
12341270
| volumeProvisioner.dind-lv-monitor | object | See below | `dind-lv-monitor` DaemonSet parameters (local volumes cleaner) |
12351271
| volumeProvisioner.enabled | bool | `true` | Enable volume-provisioner |
12361272
| volumeProvisioner.env | object | `{}` | Add additional env vars |
1237-
| volumeProvisioner.image | object | `{"digest":"sha256:c036ad717391debdf43f8da337b81b5df0e79de274d2d9af1425c675b0296dda","registry":"quay.io","repository":"codefresh/dind-volume-provisioner","tag":"1.35.0"}` | Set image |
1273+
| volumeProvisioner.image | object | `{"digest":"sha256:ede6f663c912a08b7d335b5ec5518ccc266b27c431d0854d22971005992adc5d","registry":"quay.io","repository":"codefresh/dind-volume-provisioner","tag":"1.35.2"}` | Set image |
12381274
| volumeProvisioner.nodeSelector | object | `{}` | Set node selector |
12391275
| volumeProvisioner.podAnnotations | object | `{}` | Set pod annotations |
12401276
| volumeProvisioner.podSecurityContext | object | See below | Set security context for the pod |

charts/cf-runtime/README.md.gotmpl

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,14 +717,48 @@ volumeProvisioner:
717717
### Rootless DinD
718718

719719
DinD pod runs a `priviliged` container with **rootfull** docker.
720-
To run the docker daemon as non-root user (**rootless** mode), change dind image tag:
721720

722-
`values.yaml`
721+
To run the docker daemon as non-root user (**rootless** mode), refer to `values-rootless.yaml`:
722+
723723
```yaml
724+
volumeProvisioner:
725+
env:
726+
IS_ROOTLESS: true
727+
# -- Only if local volumes are used as backend storage (ignored for ebs/ebs-csi disks)
728+
dind-lv-monitor:
729+
image:
730+
tag: 1.30.0-rootless
731+
digest: sha256:712e549e6e843b04684647f17e0973f8047e0d60e6e8b38a693ea64dc75b0479
732+
containerSecurityContext:
733+
runAsUser: 1000
734+
podSecurityContext:
735+
fsGroup: 1000
736+
# Ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#configure-volume-permission-and-ownership-change-policy-for-pods
737+
fsGroupChangePolicy: "OnRootMismatch"
738+
# -- Enable initContainer to run chmod for /var/lib/codefresh/dind-volumes on host nodes
739+
volumePermissions:
740+
enabled: false
741+
724742
runtime:
725743
dind:
726744
image:
727-
tag: rootless
745+
tag: 26.1.4-1.28.10-rootless
746+
digest: sha256:59dfc004eb22a8f09c8a3d585271a055af9df4591ab815bca418c24a2077f5c8
747+
userVolumeMounts:
748+
dind:
749+
name: dind
750+
mountPath: /home/rootless/.local/share/docker
751+
containerSecurityContext:
752+
privileged: true
753+
runAsUser: 1000
754+
podSecurityContext:
755+
fsGroup: 1000
756+
# Ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#configure-volume-permission-and-ownership-change-policy-for-pods
757+
fsGroupChangePolicy: "OnRootMismatch"
758+
# -- Enable initContainer to run chmod for /home/rootless in DinD pod
759+
# !!! Will slow down dind pod startup
760+
volumePermissions:
761+
enabled: true
728762
```
729763

730764
### ARM

charts/cf-runtime/templates/_components/volume-provisioner/_daemonset.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ spec:
3737
args:
3838
- -ec
3939
- |
40-
chown -R {{ .Values.podSecurityContext.runAsUser }}:{{ .Values.podSecurityContext.fsGroup }} {{ $localVolumeParentDir }}
40+
chown -R {{ .Values.containerSecurityContext.runAsUser }}:{{ .Values.podSecurityContext.fsGroup }} {{ $localVolumeParentDir }}
4141
volumeMounts:
4242
- mountPath: {{ $localVolumeParentDir }}
4343
name: dind-volume-dir
@@ -95,4 +95,4 @@ spec:
9595
{{- toYaml . | nindent 6 }}
9696
{{- end }}
9797
{{- end }}
98-
{{- end -}}
98+
{{- end -}}

charts/cf-runtime/templates/runtime/runtime-env-spec-tmpl.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,34 @@ dockerDaemonScheduler:
183183
secret:
184184
secretName: codefresh-certs-server
185185
{{- end }}
186+
{{- with $dindContext.podSecurityContext }}
187+
podSecurityContext: {{- toYaml . | nindent 4 }}
188+
{{- end }}
189+
{{- with $dindContext.containerSecurityContext }}
190+
containerSecurityContext: {{- toYaml . | nindent 4 }}
191+
{{- end }}
192+
{{- if $dindContext.volumePermissions.enabled }}
193+
initContainers:
194+
- name: volume-permissions
195+
image: {{ include (printf "%s.image.name" $cfCommonTplSemver ) (dict "image" $dindContext.volumePermissions.image "context" .) }}
196+
imagePullPolicy: {{ $dindContext.volumePermissions.image.pullPolicy | default "Always" }}
197+
command:
198+
- /bin/sh
199+
args:
200+
- -ec
201+
- |
202+
chown -R {{ $dindContext.containerSecurityContext.runAsUser }}:{{ $dindContext.podSecurityContext.fsGroup }} /home/rootless/.local/share/docker
203+
volumeMounts:
204+
- mountPath: /home/rootless/.local/share/docker
205+
name: dind
206+
{{- if eq ( toString ( $dindContext.volumePermissions.securityContext.runAsUser )) "auto" }}
207+
securityContext: {{- omit $dindContext.volumePermissions.securityContext "runAsUser" | toYaml | nindent 6 }}
208+
{{- else }}
209+
securityContext: {{- $dindContext.volumePermissions.securityContext | toYaml | nindent 6 }}
210+
{{- end }}
211+
resources:
212+
{{- toYaml $dindContext.volumePermissions.resources | nindent 6 }}
213+
{{- end }}
186214
extends: {{- toYaml .Values.runtime.runtimeExtends | nindent 2 }}
187215
{{- if .Values.runtime.description }}
188216
description: {{ .Values.runtime.description }}

charts/cf-runtime/tests/private-registry/private_registry_test.yaml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,15 @@ values:
44
- ../values.yaml
55
- ../values-private-registry.yaml
66
templates:
7-
- templates/hooks/post-install/cm-update-runtime.yaml
8-
- templates/runner/deployment.yaml
9-
- templates/volume-provisioner/deployment.yaml
10-
- templates/volume-provisioner/daemonset.yaml
11-
- templates/volume-provisioner/cronjob.yaml
12-
- templates/monitor/deployment.yaml
13-
- templates/app-proxy/deployment.yaml
7+
- templates/**.yaml
148
release:
159
name: cf-runtime
1610
namespace: codefresh
1711
revision: 1
1812
upgrade: true
19-
chart:
20-
version: 1.0.0
21-
appVersion: 1.0.0
13+
# chart:
14+
# version: 1.0.0
15+
# appVersion: 1.0.0
2216
tests:
2317
- it: Test private registry in runtime spec
2418
template: templates/hooks/post-install/cm-update-runtime.yaml

charts/cf-runtime/tests/runner/runner_test.yaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ suite: runner test
33
values:
44
- ../values.yaml
55
templates:
6-
- templates/runner/deployment.yaml
7-
- templates/runner/rbac.yaml
8-
- templates/runner/secret.yaml
6+
- templates/**.yaml
97
release:
108
name: cf-runtime
119
namespace: codefresh
1210
revision: 1
1311
upgrade: true
1412
chart:
15-
version: 1.0.0
1613
appVersion: 1.0.0
1714
tests:
1815
- it: Test runner default metadata
@@ -24,14 +21,12 @@ tests:
2421
of: Deployment
2522
- isNull:
2623
path: metadata.annotations
27-
- equal:
24+
- isSubset:
2825
path: metadata.labels
29-
value:
26+
content:
3027
app.kubernetes.io/instance: cf-runtime
3128
app.kubernetes.io/managed-by: Helm
3229
app.kubernetes.io/name: cf-runtime
33-
app.kubernetes.io/version: 1.0.0
34-
helm.sh/chart: cf-runtime-1.0.0
3530
codefresh.io/application: runner
3631
- equal:
3732
path: metadata.name

charts/cf-runtime/tests/runtime/runtime_onprem_test.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
# yaml-language-server: $schema=https://raw.githubusercontent.com/quintush/helm-unittest/master/schema/helm-testsuite.json
22
suite: runtime onprem test
33
templates:
4-
- templates/hooks/post-install/job-update-runtime.yaml
5-
- templates/hooks/post-install/cm-update-runtime.yaml
6-
- templates/runtime/secret.yaml
4+
- templates/**.yaml
75
release:
86
name: cf-runtime
97
namespace: codefresh
108
revision: 1
119
upgrade: true
1210
chart:
13-
version: 1.0.0
1411
appVersion: 1.0.0
1512
tests:
1613
- it: Test default runtime spec metadata

0 commit comments

Comments
 (0)