You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RUN --mount=type=secret,id=FOO,env cat $FOO > /foo_secret_hash.txt
24
-
RUN --mount=type=secret,id=BAR,dst=/tmp/bar.secret cat /tmp/bar.secret > /bar_secret_hash.txt
26
+
Inspect the Dockerfile and devcontainer.json files in the new directory.
27
+
```bash
28
+
cat devcontainer.json
29
+
cat Dockerfile
25
30
```
26
-
using this command:
31
+
32
+
Note that 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.
This will result in a shell session inside the built container.
38
-
You can now verify two things:
46
+
You can now verify three things:
39
47
* 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`.
40
-
* The secrets were still useful during the build. The following comnmands show that the secrets had side effects inside the build, without remaining in the image:
41
48
```bash
49
+
cat /proc/self/environ | tr '\0''\n'
50
+
printenv
51
+
```
52
+
* 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:
53
+
```bash
54
+
echo -n "secret-foo"| sha256sum
42
55
cat /foo_secret_hash.txt
56
+
echo -n "secret-bar"| sha256sum
43
57
cat /bar_secret_hash.txt
44
58
```
45
59
60
+
Notice that the first two checksums match and that the last two checksums match.
61
+
62
+
Finally, exit the container:
63
+
```bash
64
+
exit
65
+
```
66
+
46
67
### Verifying that images are secret free
47
-
To verify that the build image doesn't contain build secrets, run the following:
68
+
To verify that the built image doesn't contain build secrets, run the following:
48
69
49
70
```bash
50
71
docker pull localhost:5000/test-container:latest
@@ -53,19 +74,24 @@ mkdir -p test-container
53
74
tar -xf test-container.tar -C test-container/
54
75
cd test-container
55
76
# Scan image layers for secrets:
56
-
find . -type f | xargs tar -xOf 2>/dev/null | strings | grep -rin "envbuilder-test-secret"
77
+
find . -type f | xargs tar -xOf 2>/dev/null | strings | grep -rn "secret-foo"
78
+
find . -type f | xargs tar -xOf 2>/dev/null | strings | grep -rn "secret-bar"
57
79
# Scan image manifests for secrets:
58
-
find . -type f | xargs -n1 grep -rinI 'envbuilder-test-secret'
80
+
find . -type f | xargs -n1 grep -rnI 'secret-foo'
81
+
find . -type f | xargs -n1 grep -rnI 'secret-bar'
59
82
cd ../
60
83
```
61
84
62
85
The output of both find/grep commands should be empty.
63
-
To verify that it scans correctly, replace "envbuilder-test-secret" with "Envbuilder" and rerun the commands. It should find strings related to Envbuilder that are not secrets.
86
+
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.
87
+
88
+
### Cleanup
64
89
65
-
Having verified that no secrets were included in the image, we can now delete the artifacts that we saved to disk.
90
+
Having verified that no secrets were included in the image, we can now delete the artifacts that we saved to disk and remove the containers.
0 commit comments