-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
frontend: allow mounting secret environment variables #5215
Conversation
Instead of RUN --mount=type=secret,id=mysecret,env=MY_SECRET Might be confusing though |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
20c94fb
to
85c9af4
Compare
Yes, it might be confusing given that regular secret mounts use the Ultimately, both |
Wondering; would there be use-cases where both a mount ( In that case, target could continue to be used to specify the name of the mounted secret, and That would likely mean that |
Hmm, that's a very good point. I don't think it's possible in LLB as currently implemented: Lines 391 to 410 in 979542e
but I can take a stab at it. |
Oh! Yes, I'm not super familiar with the BuildKit internals. For clarity; I'm not a maintainer for BuildKit, so mostly commenting as a user interested in this feature, so happy to hear from BuildKit maintainers on my suggestions as well 😅 |
Yes I think that would be fine to have both but would need LLB changes as stated by @a-palchikov. Not for this PR but we should also consider having a build check that warns if a secret env overrides ones from |
85c9af4
to
d66f9c9
Compare
}) | ||
} | ||
|
||
// SecretAsEnvName defines if the secret should be added as an environment variable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept the original functional option (SecretAsEnv
) intact to keep backwards compatibility as I think it might already be used.
2b083b3
to
1e498a4
Compare
client/llb/exec.go
Outdated
} | ||
pm := &pb.Mount{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a behavior change of creating a secret mount when SecretAsEnv
was set.
If there is a need for mounting the same secret both as file and env (can't think of one) then it should be optional.
|
||
dockerfile := []byte(` | ||
FROM busybox | ||
RUN --mount=type=secret,id=mysecret,env [ "$mysecret" == "pw" ] && [ -f /run/secrets/mysecret ] || false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this is needed in Dockerfile syntax. Would be more clearer if env
always has a string value.
1e498a4
to
0fc5f16
Compare
@tonistiigi Updated with the following semantics: A secret is defined with a tuple (id, target) which can be aliased as (source, destination) using the following format: RUN --mount=type=secret,id=FOO,target=/path/to/secret ... Existing secret rules:
Adding RUN --mount=type=secret,id=FOO,env=FOO with the following semantics:
|
I think you can squash the commits as don't think they are useful on their own. If you want, you can leave the client-llb and dockerfile changes separate. |
This adds the syntax to Dockerfile frontend. I purposedly chose to use a simple format for this as it's likely going to be debated. As implemented, the following format is supported: ``` RUN --mount=type=secret,id=MYSECRET,env ``` or, more explicitly: ``` RUN --mount=type=secret,id=MYSECRET,env=true ``` will mount the secret with id MYSECRET as a new environment variable with the same name. Using 'target', it's possible to create a different environment variable: ``` RUN --mount=type=secret,id=mysecret,target=MY_SECRET,env ``` will mount 'mysecret' secret as MY_SECRET environment variable. Any suggestions on making it more ergonomic are welcome. Signed-off-by: a-palchikov <deemok@gmail.com>
0fc5f16
to
96f746b
Compare
Implements frontend side of #2122.
This adds the syntax to Dockerfile frontend.
I purposefully chose to use a simple format for this as it's likely going to be debated. As implemented, the following format is supported:
RUN --mount=type=secret,id=MYSECRET,env
or, more explicitly:
RUN --mount=type=secret,id=mysecret,env=MYSECRET
will mount the secret with id
mysecret
as a new environment variable with the nameMYSECRET
).Either way, the secret will be mounted as a file (existing behavior).
Note, that this already implements a suggestion from the PR comments.
Any suggestions on making it even more ergonomic or straightforward are welcome.