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
Copy file name to clipboardExpand all lines: docs/build-secrets.md
+17-18Lines changed: 17 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,18 @@
1
1
# Build Secrets
2
2
3
-
Envbuilder supports [build secrets](https://docs.docker.com/reference/dockerfile/#run---mounttypesecret). For envbuilder, build secrets are useful when you need to use sensitive information during the image build process and:
3
+
Envbuilder supports [build secrets](https://docs.docker.com/reference/dockerfile/#run---mounttypesecret). Build secrets are useful when you need to use sensitive information during the image build process and:
4
4
* the secrets should not be present in the built image.
5
-
* the secrets should not be accessible in the container after its built has concluded.
5
+
* the secrets should not be accessible in the container after its build has concluded.
6
6
7
-
If your Dockerfile contains directives of the form `RUN --mount=type=secret,...`, Envbuilder will attempt to mount build secrets as specified. Envbuilder does need to find these secrets. Unlike the `docker build` command, Envbuilder does not support the `--secret` flag. Instead, Envbuilder collects build secrets from environment variables prefixed with `ENVBUILDER_BUILD_SECRET_`.
8
-
These build secrets will not be present in any cached layers or images that are pushed to an image repository. Nor will they be available at run time.
7
+
If your Dockerfile contains directives of the form `RUN --mount=type=secret,...`, Envbuilder will attempt to mount build secrets as specified in the directive. Unlike the `docker build` command, Envbuilder does not support the `--secret` flag. Instead, Envbuilder collects build secrets from environment variables prefixed with `Envbuilder_BUILD_SECRET_`. These build secrets will not be present in any cached layers or images that are pushed to an image repository. Nor will they be available at run time.
9
8
10
9
## Example
11
10
12
-
To illustrate build secrets in envbuilder, let's build, push and run a container locally. These concepts will transfer to Kubernetes or other containerised environments. Note that this example is for illustrative purposes only and is not fit for production use. Production considerations are discussed in the next section.
11
+
To illustrate build secrets in Envbuilder, let's build, push and run a container locally. These concepts will transfer to Kubernetes or other containerised environments. Note that this example is for illustrative purposes only and is not fit for production use. Production considerations are discussed in the next section.
13
12
14
13
First, start a local docker registry, so that we can push and inspect the built image:
15
14
```bash
16
-
docker run --rm -d -p 5000:5000 --name envbuilder-registry registry:2
15
+
docker run --rm -d -p 5000:5000 --name Envbuilder-registry registry:2
17
16
```
18
17
19
18
Then, build an image based on this Dockerfile:
@@ -27,19 +26,19 @@ RUN --mount=type=secret,id=BAR,dst=/tmp/bar.secret cat /tmp/bar.secret > /bar_se
This will result in a shell session inside the built container.
40
39
You can now verify two things:
41
40
* 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`.
42
-
* The secrets were still useful during the build:
41
+
* 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:
43
42
```bash
44
43
cat /foo_secret_hash.txt
45
44
cat /bar_secret_hash.txt
@@ -62,7 +61,7 @@ cd ../
62
61
```
63
62
64
63
The output of both find/grep commands should be empty.
65
-
To verify that it scans correctly, replace "envbuilder-test-secret" with "envbuilder" and rerun the commands.
64
+
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.
66
65
67
66
Having verified that no secrets were included in the image, we can now delete the artifacts that we saved to disk.
68
67
```bash
@@ -79,13 +78,13 @@ Build secrets are meant for use cases where the secret should not be accessible
79
78
Build secrets are only protected if they are not copied or moved from their location as designated in the `RUN` directive. If a build secret is used, care should be taken to ensure that it is not copied or otherwise persisted into an image layer beyond the control of Envbuilder.
80
79
81
80
### Who should be able to access build secrets, when and where?
82
-
The secure way to use build secrets with envbuilder is to deny users access to the platform that hosts envbuilder. Only grant access to the envbuilder container once it has concluded its build, using a trusted non-platform channel like ssh or the coder agent running inside the container. Once control has been handed to such a runtime container process, envbuilder will have cleared all secrets that it set from the container.
81
+
The secure way to use build secrets with Envbuilder is to deny users access to the platform that hosts Envbuilder. Only grant access to the Envbuilder container once it has concluded its build, using a trusted non-platform channel like ssh or the coder agent running inside the container. Once control has been handed to such a runtime container process, Envbuilder will have cleared all secrets that it set from the container.
83
82
84
-
Anyone with sufficient access to attach directly to the container (eg. using `kubectl`), will be able to read build secrets if they attach to the container before it has concluded its build. Anyone with sufficient access to the platform that hosts the envbuilder container will also be able to read these build secrets from where the platform stores them. This is true for other build systems, and software in general.
83
+
Anyone with sufficient access to attach directly to the container (eg. using `kubectl`), will be able to read build secrets if they attach to the container before it has concluded its build. Anyone with sufficient access to the platform that hosts the Envbuilder container will also be able to read these build secrets from where the platform stores them. This is true for other build systems, and containerised software in general.
85
84
86
85
If secrets should be accessible at runtime, do not use build secrets. Rather, mount the secret data using a volume or environment variable. Envbuilder will not include mounted volumes in the image that it pushes to any cache repositories, but they will still be available to users that connect to the container.
87
86
88
87
### Container Management beyond Envbuilder's control
89
-
Container orchestration systems mount certain artifacts into containers for various reasons. It is possible that some of these might grant indirect access to build secrets. Consider kubernetes. It will mount a service account token into running containers. Depending on the access granted to this service account token, it may be possible to read build secrets and other sensitive data using the kubernetes API. This should not be possible by default, but envbuilder cannot provide such a guarantee.
88
+
Container orchestration systems mount certain artifacts into containers for various reasons. It is possible that some of these might grant indirect access to build secrets. Consider kubernetes. It will mount a service account token into running containers. Depending on the access granted to this service account token, it may be possible to read build secrets and other sensitive data using the kubernetes API. This should not be possible by default, but Envbuilder cannot provide such a guarantee.
90
89
91
-
When building a system that uses envbuilder, ensure that your platform does not expose unintended secret information to the container.
90
+
When building a system that uses Envbuilder, ensure that your platform does not expose unintended secret information to the container.
0 commit comments