Skip to content

Commit 33c33d7

Browse files
committed
Document initial setup and testing for build time secrets
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent c6672ce commit 33c33d7

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

docs/openfaas-pro/builder.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,123 @@ faas-cli up --remote-builder http://127.0.0.1:8081/build \
109109
--payload-secret $HOME/.openfaas/payload.txt
110110
```
111111

112+
### Build secrets
113+
114+
Build secrets let you pass private registry tokens, CA certificates, or other sensitive values into a `RUN --mount=type=secret` instruction during a remote build. Secrets are sealed (encrypted) client-side so they are protected in transit, even without TLS.
115+
116+
#### Setup
117+
118+
Generate a keypair and create a Kubernetes secret with the private key:
119+
120+
```bash
121+
faas-cli secret keygen
122+
123+
kubectl create secret generic -n openfaas \
124+
pro-builder-build-secrets-key \
125+
--from-file key=./key
126+
```
127+
128+
Then set `buildSecrets.privateKeySecret` and `buildSecrets.keyID` in the [helm chart values](https://github.com/openfaas/faas-netes/tree/master/chart/pro-builder) and upgrade the release.
129+
130+
Distribute the `key.pub` file to anyone who needs to build with secrets.
131+
132+
#### Using build secrets with `faas-cli`
133+
134+
Add `build_secrets` to your `stack.yaml`:
135+
136+
```yaml
137+
functions:
138+
my-function:
139+
lang: dockerfile
140+
handler: ./my-function
141+
image: registry.example.com/my-function:latest
142+
build_secrets:
143+
pip_token: my-secret-token
144+
registry_url: https://token:secret@registry.example.com/simple
145+
```
146+
147+
Use `--mount=type=secret` in your Dockerfile to access them:
148+
149+
```Dockerfile
150+
RUN --mount=type=secret,id=pip_token \
151+
pip install --index-url "https://$(cat /run/secrets/pip_token)@registry.example.com/simple" mypackage
152+
```
153+
154+
Then publish using the remote builder:
155+
156+
```bash
157+
faas-cli publish \
158+
--remote-builder http://127.0.0.1:8081 \
159+
--payload-secret $HOME/.openfaas/payload.txt \
160+
--builder-public-key ./key.pub \
161+
--builder-key-id builder-key-1
162+
```
163+
164+
The secrets are sealed automatically by `faas-cli` before sending to the builder.
165+
166+
#### Using build secrets with `curl`
167+
168+
You can also seal secrets ahead of time using `faas-cli secret seal` and include the sealed file in the build tar:
169+
170+
```bash
171+
faas-cli secret seal key.pub \
172+
--key-id builder-key-1 \
173+
--from-literal pip_token=my-secret-token \
174+
--from-file ca.crt=./certs/ca.crt
175+
```
176+
177+
This writes `com.openfaas.secrets` in the current directory. Include it in the tar alongside the build config:
178+
179+
```bash
180+
ls -1
181+
# com.openfaas.docker.config
182+
# com.openfaas.secrets
183+
# context/
184+
# Dockerfile
185+
186+
tar cvf req.tar --exclude=req.tar .
187+
```
188+
189+
Then send the build request as normal — the HMAC covers the entire tar including the sealed file:
190+
191+
```bash
192+
PAYLOAD=$(kubectl get secret -n openfaas payload-secret \
193+
-o jsonpath='{.data.payload-secret}' | base64 --decode)
194+
195+
HMAC=$(cat req.tar | openssl dgst -sha256 -hmac $PAYLOAD | sed -e 's/^.* //')
196+
197+
curl -H "X-Build-Signature: sha256=$HMAC" \
198+
-H "Accept: application/x-ndjson" \
199+
http://127.0.0.1:8081/build -X POST --data-binary @req.tar
200+
```
201+
202+
#### Inspecting sealed secrets
203+
204+
To verify the contents of a sealed file without sending it to the builder:
205+
206+
```bash
207+
faas-cli secret unseal key
208+
209+
# Or inspect a single key:
210+
faas-cli secret unseal key --key pip_token
211+
```
212+
213+
#### Retrieving the builder's public key
214+
215+
If you don't have the `key.pub` file, you can fetch it from a running builder:
216+
217+
```bash
218+
curl -s http://127.0.0.1:8081/publickey | jq
219+
```
220+
221+
```json
222+
{
223+
"key_id": "builder-key-1",
224+
"algorithm": "nacl/box",
225+
"public_key": "3kS3sOxOE4nHPn7+RqFRzWZ8hG5cJ4FPTm6JlQKJHlg="
226+
}
227+
```
228+
112229
### Remote builds via `curl`
113230

114231
As an alternative to a private or authenticated registry, you can use [ttl.sh by Replicated](https://ttl.sh) as a temporary registry for testing (only). It allows you to publish containers that are removed after a certain time-limit, try `ttl.sh/test-image-hello:1h` for an image that is removed after 1 hour.

0 commit comments

Comments
 (0)