Skip to content

Commit 7f78aca

Browse files
weltekialexellis
authored andcommitted
Switch to shared socket for calling buildkitd
Use a shared socket for communication between Buildkit and the Pro Builder containers. This simplifies the deployment and removes the need to create and manage mTLS certificates. Chart changes: - `securityContext` for buildkit does not need to be set explicitly in the values.yaml file anymore. The appropriate default values are selected based on the value of the `buildkit.rootless` parameter. - BREAKING CHANGE - The `buildkit.image` parameter is now only used to set the image when `buildkit.rootless` is `false`. A new parameter `buildkitRootless.image` is used to set the image for rootless mode. Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
1 parent 7ba4f58 commit 7f78aca

File tree

3 files changed

+54
-82
lines changed

3 files changed

+54
-82
lines changed

chart/pro-builder/README.md

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The *Function Builder* aka [pro-builder](https://docs.openfaas.com/openfaas-pro/
1313
- A container image registry that is accessible from your cluster
1414

1515
You can generate a valid container registry login file by:
16-
16+
1717
* Running `faas-cli registry-login` (preferred)
1818
* Or, disable the keychain in Docker, then run `docker login`, and supply the `$HOME/.docker/config.json` file.
1919

@@ -70,33 +70,6 @@ kubectl create secret generic payload-secret \
7070
--from-file payload-secret=payload.txt -n openfaas
7171
```
7272

73-
### mTLS certificates
74-
75-
Generate mTLS certificates for BuildKit and the Pro Builder which are used to encrypt messages between the builder component and BuildKit.
76-
77-
```bash
78-
docker run -v `pwd`/out:/tmp/ -ti ghcr.io/openfaas/certgen:latest
79-
80-
# Reset the permissions of the files to your own user:
81-
sudo chown -R $USER:$USER out
82-
```
83-
84-
Then create two secrets, one for the BuildKit daemon and one for the builder component.
85-
86-
```bash
87-
kubectl create secret generic -n openfaas \
88-
buildkit-daemon-certs \
89-
--from-file ./out/certs/ca.crt \
90-
--from-file ./out/certs/server.crt \
91-
--from-file ./out/certs/server.key
92-
93-
kubectl create secret generic -n openfaas \
94-
buildkit-client-certs \
95-
--from-file ./out/certs/ca.crt \
96-
--from-file ./out/certs/client.crt \
97-
--from-file ./out/certs/client.key
98-
```
99-
10073
## Install the Chart
10174

10275
- Create the required secret with your OpenFaaS Pro license code:
@@ -123,28 +96,14 @@ Root mode, for development, or where rootless for some reason isn't working:
12396

12497
```yaml
12598
buildkit:
126-
image: moby/buildkit:v0.10.3
12799
rootless: false
128-
securityContext:
129-
runAsUser: 0
130-
runAsGroup: 0
131-
privileged: true
132100
```
133101
134102
Rootless mode (preferred, if possible):
135103
136104
```yaml
137105
buildkit:
138-
# For a rootless configuration
139-
image: moby/buildkit:master-rootless
140106
rootless: true
141-
securityContext:
142-
# Needs Kubernetes >= 1.19
143-
seccompProfile:
144-
type: Unconfined
145-
runAsUser: 1000
146-
runAsGroup: 1000
147-
privileged: false
148107
```
149108
150109
Then install the chart using its official path and the custom YAML file:
@@ -346,8 +305,9 @@ Additional pro-builder options in `values.yaml`.
346305
| `replicas` | How many replicas of buildkit and the pro-builder API to create | `1` |
347306
| `proBuilder.image` | Container image to use for the pro-builder | See values.yaml |
348307
| `proBuilder.maxInflight` | Limit the total amount of concurrent builds for the pro-builder replica | See values.yaml |
349-
| `buildkit.image` | Image version for the buildkit daemon | See values.yaml |
350-
| `buildkit.rootless` | When set to true, uses user-namespaces to avoid a privileged container | See notes in values.yaml |
308+
| `buildkit.image` | Image version for the buildkit daemon when `buildkit.rootless` is false | See values.yaml |
309+
| `buildkitRootless.image` | Image version for the buildkit daemon when `buildkit.rootless` is true | See values.yaml |
310+
| `buildkit.rootless` | When set to true, uses user-namespaces to avoid a privileged container | `true` |
351311
| `buildkit.securityContext` | Used to set security policy for buildkit | See values.yaml |
352312
| `imagePullPolicy` | The policy for pulling either of the containers deployed by this chart | `IfNotPresent` |
353313
| `disableHmac` | This setting disable request verification, so should never to set to `true` | `false` |

chart/pro-builder/templates/deployment.yml

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ spec:
4040
{{- toYaml .Values.securityContext | nindent 8 }}
4141
{{- end }}
4242
volumes:
43-
- name: client-certs
44-
secret:
45-
secretName: buildkit-client-certs
46-
- name: daemon-certs
47-
secret:
48-
secretName: buildkit-daemon-certs
4943
- name: registry-secret
5044
secret:
5145
defaultMode: 420
@@ -67,18 +61,17 @@ spec:
6761
secret:
6862
secretName: {{ .Values.awsCredentialsSecret }}
6963
{{- end}}
70-
{{- if .Values.serviceAccount}}
64+
- name: socket-dir
65+
emptyDir: {}
66+
{{- if .Values.serviceAccount}}
7167
serviceAccountName: {{ .Values.serviceAccount | quote }}
72-
{{- end }}
68+
{{- end }}
7369
containers:
7470
- name: pro-builder
7571
image: {{ .Values.proBuilder.image }}
7672
imagePullPolicy: {{ .Values.imagePullPolicy }}
7773
args:
7874
- "-license-file=/var/secrets/license/license"
79-
- "--tlscert=/var/secrets/certs/client.crt"
80-
- "--tlskey=/var/secrets/certs/client.key"
81-
- "--tlscacert=/var/secrets/certs/ca.crt"
8275
env:
8376
- name: buildkit_server_name
8477
value: "127.0.0.1"
@@ -87,7 +80,7 @@ spec:
8780
- name: insecure
8881
value: "false"
8982
- name: buildkit_url
90-
value: "tcp://127.0.0.1:1234"
83+
value: "unix:///home/app/.local/run/buildkit/buildkitd.sock"
9184
- name: "disable_hmac"
9285
value: {{ .Values.disableHmac | quote }}
9386
- name: "max_inflight"
@@ -118,8 +111,13 @@ spec:
118111
{{- with .Values.proBuilder.securityContext }}
119112
securityContext:
120113
{{- . | toYaml | nindent 12 }}
114+
{{- else }}
115+
securityContext:
116+
runAsGroup: 1000
121117
{{- end }}
122118
volumeMounts:
119+
- name: socket-dir
120+
mountPath: /home/app/.local/run/buildkit
123121
- name: registry-secret
124122
readOnly: true
125123
mountPath: "/home/app/.docker/"
@@ -132,24 +130,25 @@ spec:
132130
- name: builder-workspace
133131
mountPath: /tmp/
134132
readOnly: false
135-
- name: client-certs
136-
readOnly: true
137-
mountPath: /var/secrets/certs
138133
{{- if .Values.awsCredentialsSecret }}
139134
- name: aws-credentials
140135
readOnly: true
141136
mountPath: "/var/secrets/aws-credentials"
142137
{{- end }}
143138
- name: buildkit
144139
args:
145-
- "--addr=tcp://127.0.0.1:1234"
146-
- "--tlscert=/var/secrets/certs/server.crt"
147-
- "--tlskey=/var/secrets/certs/server.key"
148-
- "--tlscacert=/var/secrets/certs/ca.crt"
149-
{{- if .Values.buildkit.rootless }}
140+
{{- if .Values.buildkit.rootless }}
141+
- "--addr=unix:///home/user/.local/run/buildkit/buildkitd.sock"
150142
- "--oci-worker-no-process-sandbox"
151-
{{- end }}
143+
{{- else }}
144+
- "--addr=unix:///run/buildkit/buildkitd.sock"
145+
- "--group=1000"
146+
{{- end }}
147+
{{- if .Values.buildkit.rootless }}
148+
image: {{ .Values.buildkitRootless.image }}
149+
{{- else }}
152150
image: {{ .Values.buildkit.image }}
151+
{{- end }}
153152
imagePullPolicy: {{ .Values.imagePullPolicy | quote }}
154153
ports:
155154
- containerPort: 1234
@@ -159,11 +158,28 @@ spec:
159158
{{- with .Values.buildkit.securityContext }}
160159
securityContext:
161160
{{- . | toYaml | nindent 12 }}
161+
{{- else }}
162+
{{- if .Values.buildkit.rootless }}
163+
securityContext:
164+
seccompProfile:
165+
type: Unconfined
166+
runAsUser: 1000
167+
runAsGroup: 1000
168+
privileged: false
169+
{{- else }}
170+
securityContext:
171+
runAsUser: 0
172+
runAsGroup: 0
173+
privileged: true
174+
{{- end }}
162175
{{- end }}
163176
volumeMounts:
164-
- name: daemon-certs
165-
readOnly: true
166-
mountPath: /var/secrets/certs
177+
- name: socket-dir
178+
{{- if .Values.buildkit.rootless }}
179+
mountPath: /home/user/.local/run/buildkit
180+
{{- else }}
181+
mountPath: /run/buildkit/
182+
{{- end }}
167183
- name: buildkit-workspace
168184
mountPath: /tmp/
169185
readOnly: false

chart/pro-builder/values.yaml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ proBuilder:
1919
image: ghcr.io/openfaasltd/pro-builder:0.5.3
2020

2121
# Set to 0 for unlimited, or some non-zero value for a hard limit
22-
# the builder will return a HTTP 429 status code, then the client
22+
# the builder will return a HTTP 429 status code, then the client
2323
# must retry the request.
2424
# A function executed via the async queue will be retried, so can be
2525
# a convenient way to build functions without blocking the client.
@@ -32,20 +32,24 @@ proBuilder:
3232
# limits:
3333
# memory: "256Mi"
3434

35+
buildkitRootless:
36+
# Image used when running buildkit in rootless mode.
37+
image: moby/buildkit:v0.23.2-rootless
38+
3539
# buildkit.image is for the buildkit daemon
3640
# Check for the latest release on GitHub: https://github.com/moby/buildkit/releases
3741
#
3842
# Both configurations are "rootless", however the rootless: true mode does not
3943
# require Buildkit to run as a privileged container and is preferred.
4044
buildkit:
41-
# A configuration which uses a privileged container for when
45+
# A configuration which uses a privileged container for when
4246
# your nodes have issues running in rootless mode
4347
#
44-
# Use rootless if possible, and if not, set up a dedicated
48+
# Use rootless if possible, and if not, set up a dedicated
4549
# nodepool for the function builder pods, which is recycled often
4650
# through the use of spot instances or preemptive VMs.
4751
#
48-
# image: moby/buildkit:v0.23.2-rootless
52+
# image: moby/buildkit:v0.23.2
4953
# rootless: false
5054
# securityContext:
5155
# runAsUser: 0
@@ -54,16 +58,9 @@ buildkit:
5458

5559
# For a rootless configuration, preferred, if the configuration
5660
# and Kernel version of your Kubernetes nodes supports it
57-
#
58-
image: moby/buildkit:v0.23.2-rootless
61+
#
62+
image: moby/buildkit:v0.23.2
5963
rootless: true
60-
securityContext:
61-
# Needs Kubernetes >= 1.19
62-
seccompProfile:
63-
type: Unconfined
64-
runAsUser: 1000
65-
runAsGroup: 1000
66-
privileged: false
6764

6865
resources:
6966
requests:
@@ -97,4 +94,3 @@ nodeSelector: {}
9794
tolerations: []
9895

9996
affinity: {}
100-

0 commit comments

Comments
 (0)