Skip to content

Commit 03bd8b8

Browse files
committed
fix(docs): update docs on build secrets to illustrate volume safety
1 parent 2fcd340 commit 03bd8b8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

docs/build-secrets.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ cat << EOF > devcontainer.json
3232
}
3333
}
3434
EOF
35+
echo 'runtime-secret-a' > runtime-secret.txt
3536
```
3637

37-
The Dockerfile requires two secrets: `TEST_BUILD_SECRET_A` and `TEST_BUILD_SECRET_B`. Their values are arbitrarily set to `secret-foo` and `secret-bar` by the command below. Building the container image writes the checksums for these secrets to disk. This illustrates that the secrets can be used in the build to enact side effects without exposing the secrets themselves.
38+
The Dockerfile requires two build secrets: `TEST_BUILD_SECRET_A` and `TEST_BUILD_SECRET_B`. Their values are arbitrarily set to `secret-foo` and `secret-bar` by the command below. Building the container image writes the checksums for these secrets to disk. This illustrates that the secrets can be used in the build to enact side effects without exposing the secrets themselves.
3839

3940
Execute the build using this command:
4041
```bash
@@ -44,11 +45,12 @@ docker run -it --rm \
4445
-e ENVBUILDER_CACHE_REPO=$(docker inspect envbuilder-registry | jq -r '.[].NetworkSettings.IPAddress'):5000/test-container \
4546
-e ENVBUILDER_PUSH_IMAGE=1 \
4647
-v $PWD:/workspaces/empty \
48+
-v $PWD/runtime-secret.txt:/runtime-secret.txt \
4749
ghcr.io/coder/envbuilder:latest
4850
```
4951

5052
This will result in a shell session inside the built container.
51-
You can now verify two things:
53+
You can now verify three things:
5254

5355
Firstly, the secrets provided to build are not available once the container is running. They are no longer on disk, nor are they in the process environment, or in `/proc/self/environ`:
5456
```bash
@@ -82,7 +84,7 @@ DEVCONTAINER=true
8284
/workspaces/empty #
8385
```
8486

85-
Finally, the secrets were still useful during the build. The following commands show that the secrets had side effects inside the build, without remaining in the image:
87+
Secondly, the secrets were still useful during the build. The following commands show that the secrets had side effects inside the build, without remaining in the image:
8688
```bash
8789
echo -n "secret-foo" | sha256sum
8890
cat /foo_secret_hash.txt
@@ -103,6 +105,8 @@ fb1c9d1220e429b30c60d028b882f735b5af72d7b5496d9202737fe9f1d38289 -
103105
/workspaces/empty #
104106
```
105107

108+
Thirdly, the runtime secret that was mounted as a volume is still mounted into the container and accessible. This is why volumes are inappropriate analogues to native docker build secrets. However, notice further down that this runtime secret volume's contents are not present in the built image. It is therefore safe to mount a volume into envbuilder for use during runtime without fear that it will be present in the image that envbuilder builds.
109+
106110
Finally, exit the container:
107111
```bash
108112
exit
@@ -120,13 +124,15 @@ cd test-container
120124
# Scan image layers for secrets:
121125
find . -type f | xargs tar -xOf 2>/dev/null | strings | grep -rn "secret-foo"
122126
find . -type f | xargs tar -xOf 2>/dev/null | strings | grep -rn "secret-bar"
127+
find . -type f | xargs tar -xOf 2>/dev/null | strings | grep -rn "runtime-secret"
123128
# Scan image manifests for secrets:
124129
find . -type f | xargs -n1 grep -rnI 'secret-foo'
125130
find . -type f | xargs -n1 grep -rnI 'secret-bar'
131+
find . -type f | xargs -n1 grep -rnI 'runtime-secret'
126132
cd ../
127133
```
128134

129-
The output of both find/grep commands should be empty.
135+
The output of all find/grep commands should be empty.
130136
To verify that it scans correctly, replace "secret-foo" with "envbuilder" and rerun the commands. It should find strings related to Envbuilder that are not secrets.
131137

132138
### Cleanup

0 commit comments

Comments
 (0)