Skip to content

Commit e3afd14

Browse files
committed
Add custom CA support for buildkit/pro-builder
These are breaking changes to allow easier management of the images, and root/rootless settings. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent d76026c commit e3afd14

File tree

3 files changed

+119
-23
lines changed

3 files changed

+119
-23
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- if .Values.buildkit.config}}
2+
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: buildkit-config
7+
namespace: {{ .Release.Namespace }}
8+
data:
9+
buildkitd.toml: |
10+
{{ .Values.buildkit.config | indent 4 }}
11+
12+
{{- end}}

chart/pro-builder/templates/deployment.yml

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
4-
{{- if .Values.buildkit.rootless }}
4+
{{- if eq .Values.buildkit.mode "rootless" }}
55
annotations:
66
container.apparmor.security.beta.kubernetes.io/buildkitd: unconfined
77
{{- end }}
@@ -36,6 +36,20 @@ spec:
3636
component: pro-builder
3737
spec:
3838
volumes:
39+
40+
{{- if .Values.buildkit.config }}
41+
- name: buildkit-config
42+
configMap:
43+
name: buildkit-config
44+
{{- end }}
45+
46+
# If given, mount buildkit caSecret as /var/var/run/registry-tls/
47+
{{- if .Values.buildkit.caSecret }}
48+
- name: registry-tls
49+
secret:
50+
secretName: {{ .Values.buildkit.caSecret }}
51+
{{- end }}
52+
3953
- name: client-certs
4054
secret:
4155
secretName: buildkit-client-certs
@@ -146,27 +160,67 @@ spec:
146160
- "--tlscert=/var/secrets/certs/server.crt"
147161
- "--tlskey=/var/secrets/certs/server.key"
148162
- "--tlscacert=/var/secrets/certs/ca.crt"
149-
{{- if .Values.buildkit.rootless }}
163+
{{- if eq .Values.buildkit.mode "rootless" }}
150164
- "--oci-worker-no-process-sandbox"
165+
- "--config=/home/user/.config/buildkit/buildkitd.toml"
151166
{{- end }}
152-
image: {{ .Values.buildkit.image }}
167+
168+
{{- if eq .Values.buildkit.mode "rootless" }}
169+
image: {{ .Values.buildkit.rootless.image }}
170+
{{- else }}
171+
image: {{ .Values.buildkit.root.image }}
172+
{{- end }}
173+
153174
imagePullPolicy: {{ .Values.imagePullPolicy | quote }}
154175
ports:
155176
- containerPort: 1234
156177
protocol: TCP
157178
resources:
158179
{{- .Values.buildkit.resources | toYaml | nindent 12 }}
159-
{{- with .Values.buildkit.securityContext }}
180+
181+
{{- if eq .Values.buildkit.mode "rootless" }}
182+
{{- with .Values.buildkit.rootless.securityContext }}
160183
securityContext:
161184
{{- . | toYaml | nindent 12 }}
162185
{{- end }}
186+
{{- else }}
187+
{{- with .Values.buildkit.root.securityContext }}
188+
securityContext:
189+
{{- . | toYaml | nindent 12 }}
190+
{{- end }}
191+
{{- end }}
192+
163193
volumeMounts:
164194
- name: daemon-certs
165195
readOnly: true
166196
mountPath: /var/secrets/certs
167197
- name: buildkit-workspace
168198
mountPath: /tmp/
169199
readOnly: false
200+
201+
{{- if .Values.buildkit.config }}
202+
203+
# If rootless, add buildkit-config ConfigMap to: ~/.config/buildkit/buildkitd
204+
{{- if eq .Values.buildkit.mode "rootless" }}
205+
- name: buildkit-config
206+
mountPath: /home/user/.config/buildkit
207+
{{- else }}
208+
# If rootful, add buildkit-config ConfigMap to: /etc/buildkit/buildkitd.toml
209+
- name: buildkit-config
210+
mountPath: /etc/buildkit
211+
{{- end }}
212+
{{- end }}
213+
214+
# If rootless, mount CA to /home/user/.config/buildkit-tls
215+
{{- if eq .Values.buildkit.mode "rootless" }}
216+
- name: registry-tls
217+
mountPath: /home/user/.config/buildkit-tls
218+
{{- else }}
219+
# If rootful, mount CA to /var/run/registry-tls/
220+
- name: registry-tls
221+
mountPath: /var/run/registry-tls/
222+
{{- end }}
223+
170224
{{- with .Values.nodeSelector }}
171225
nodeSelector:
172226
{{- toYaml . | nindent 8 }}

chart/pro-builder/values.yaml

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,62 @@ proBuilder:
2727
# Both configurations are "rootless", however the rootless: true mode does not
2828
# require Buildkit to run as a privileged container and is preferred.
2929
buildkit:
30+
31+
# "mode" can be set to "rootless" or "root"
32+
#
33+
# "rootless" (preferred)
34+
# If the Kubernetes node's OS/configuration, Kernel and Kubernetes
35+
# support it, rootless mode runs without needing root or a privileged container.
36+
#
37+
# "root" (fallback)
3038
# A configuration which uses a privileged container for when
3139
# your nodes have issues running in rootless mode
3240
#
3341
# Use rootless if possible, and if not, set up a dedicated
3442
# nodepool for the function builder pods, which is recycled often
3543
# through the use of spot instances or preemptive VMs.
44+
45+
mode: rootless
46+
47+
rootless:
48+
image: moby/buildkit:v0.15.1-rootless
49+
securityContext:
50+
seccompProfile:
51+
type: Unconfined
52+
runAsUser: 1000
53+
runAsGroup: 1000
54+
privileged: false
55+
56+
root:
57+
image: moby/buildkit:v0.15.1
58+
securityContext:
59+
runAsUser: 0
60+
runAsGroup: 0
61+
privileged: true
62+
63+
# Custom CA certificates for the registry / and custom buildkit configuration
64+
65+
# Provide the name of the secret containing the CA certificate
66+
# for a self-signed registry, when pushing or pulling images
67+
#
68+
# kubectl create secret generic -n openfaas \
69+
# registry-tls --from-file=ca.crt=ca.crt
70+
# caSecret: "registry-tls"
71+
caSecret: ""
72+
73+
# Provide a custom buildkit configuration, ideal for setting up
74+
# a custom CA for a registry, or other advanced configuration.
3675
#
37-
# image: moby/buildkit:v0.15.1
38-
# rootless: false
39-
# securityContext:
40-
# runAsUser: 0
41-
# runAsGroup: 0
42-
# privileged: true
43-
44-
# For a rootless configuration, preferred, if the configuration
45-
# and Kernel version of your Kubernetes nodes supports it
46-
#
47-
image: moby/buildkit:v0.15.1-rootless
48-
rootless: true
49-
securityContext:
50-
# Needs Kubernetes >= 1.19
51-
seccompProfile:
52-
type: Unconfined
53-
runAsUser: 1000
54-
runAsGroup: 1000
55-
privileged: false
76+
# Reference: https://docs.docker.com/build/buildkit/toml-configuration/
77+
# Config for rootless mode, reads the CA from the home directory
78+
# config: |
79+
# [registry."registry-service:443"]
80+
# ca=["/home/user/.config/buildkit-tls/ca.crt"]
81+
82+
# The config for root mode, reads the CA from the /var/run/registry-tls directory
83+
config: |
84+
[registry."registry-service:443"]
85+
ca=["/var/run/registry-tls/ca.crt"]
5686
5787
resources:
5888
requests:

0 commit comments

Comments
 (0)