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
Dagger cannot scrub secret values from its various logs and output streams. This is a regression from Dagger 0.2 and the CUE SDK. This can result in secrets leaking in the case of a crash, for example.
Below is the known status of this problem, broken down by source of the sensitive value:
Source of the secret value
Dagger 0.2 scrubbed the value
Dagger 0.3 scrubs the value
Dagger 0.3 could scrub the value without a new API
Raw contents of a file
Yes ✅
No ❌
Yes ✅
Raw contents of an environment variable
Yes ✅
No ❌
Yes ✅
Decoded from a structured file or stream (eg. JSON value, line split)
Yes ✅
No ❌
No, requires new API 🏗️
Solution
Give developers a way to mark sensitive values, by 1) leveraging existing APIs as much as possible, and 2) adding new APIs if needed.
I think this should be the top priority for the team to address since it's been noted as a blocker and critical security concern for users trying out Dagger in production environments.
@aluzzardi if we go for a helper-based approach to dynamic secrets (a-la Earthly, #4193 ), could this approach still work? The big difference I see is that a secret.Store would no longer be needed, since secrets would be resolved just-in-time by external helpers. But I guess we could still keep the secret.Store as a "pull-through cache", and use it specifically for the purpose of scrubbing? Does this makes sense to you?
Yes. secret.Store would be renamed to something else, but would still perform the same job: keep track of "seen" secrets so the scrubber can do its job.
This holds true no matter how secrets are implemented: Host().Env(), a container, helper, API call, ...
The one shortcoming is we can only scrub once the secret exists. If secrets are leaked during creation, or fail to be created and leak in errors, they won't get scrubbed.
Another factor here is that if you print a secret to stdout/stderr it will be persisted to the buildkit cache as part of the shim stdio redirection. So if we only scrub secrets later when displaying the output to users, it will still be in the cache. We also would need to scrub the secrets from the values returned by the Stdout and Stderr APIs, which aren't buildkit events. Also in the exec failure error message (which now includes stdout+stderr).
This makes me wonder if we should just scrub the secrets as part of the shim stdio redirection itself. That way they never leak to the cache and we don't have to think about scrubbing return values all over the place. Then I think @aluzzardi's suggestion would probably handle the rest of the cases?
@sipsma You're absolutely right -- I forgot about that part.
This makes me wonder if we should just scrub the secrets as part of the shim stdio redirection itself.
Yeah, that sounds right.
We'd have to somehow let the shim know that such and such file or env is a secret. Maybe by injecting a metadata file? Or a special env? Does it matter if it's part of the cache key (I guess not)?
Sounds doable.
That way they never leak to the cache and we don't have to think about scrubbing return values all over the place. Then I think @aluzzardi's suggestion would probably handle the rest of the cases?
Wondering if implementing only at the shim level is enough. It won't catch secrets in vertex name (e.g. echo <plaintext secret>), but I think that's alright? It's a much simpler design.
edit: Updated straw-man
Engine passes secrets either by ENV or File (already the case -- container.Exec in core/container.go)
Engine injects a new variable, e.g. _DAGGER_SCRUB_SECRETS={files: ["/path"], envs: ["ENV1"]} containing the location of secrets
Alternative: it's injected as a file somewhere in /.dagger_meta_mount
In either of those cases, the path and/or env name is part of the cache key: that's ok since it's already the case anyway
In either of those cases, the value of the secret is not part of the cache (nor cache key)
Shim parses _DAGGER_SCRUB_SECRETS, loads all secret values from env and files, and scrubs stdout/stderr in real-time
Regarding the caching. I don't know how buildkit would know if it needs to restart a step or not.
If the step needs a secret (MY_SECRET=mysecretvalue) and it gets scrubbed into ***.
But if we decide to change the secret to myothersecretvalue, how can buildkit know that it needs to restart the step? I guess the cache key would contain a hash of MY_SECRET secret name, but not the value. Therefore, it might think it doesn't need to restart the step?
Or does it restart any step that has secrets?
We use hashes of secret values as Secret IDs. So changing a value changes the secret ID, which invalidates the cache of everything referring to that secret id
Activity
[-]Mark secret values as sensitive[/-][+]Scrub secret values to avoid leaks[/+]d3rp3tt3 commentedon Jan 25, 2023
I think this should be the top priority for the team to address since it's been noted as a blocker and critical security concern for users trying out Dagger in production environments.
aluzzardi commentedon Jan 27, 2023
Straw-man design:
secret.StorehandleSolveEvents) and re-dispatched to different "listeners"Therefore I propose:
handleSolveEvents, we strip all secrets from the raw buildkit events (whether it's logs, vertex name ... anything)secret.Storeprovides a way to list secretsThis is similar to the 0.2.x design: https://github.com/dagger/dagger/blob/v0.2.36/client/client.go#L303-L314
/cc @sipsma @dolanor
shykes commentedon Jan 27, 2023
@aluzzardi if we go for a helper-based approach to dynamic secrets (a-la Earthly, #4193 ), could this approach still work? The big difference I see is that a
secret.Storewould no longer be needed, since secrets would be resolved just-in-time by external helpers. But I guess we could still keep thesecret.Storeas a "pull-through cache", and use it specifically for the purpose of scrubbing? Does this makes sense to you?aluzzardi commentedon Jan 27, 2023
Yes.
secret.Storewould be renamed to something else, but would still perform the same job: keep track of "seen" secrets so the scrubber can do its job.This holds true no matter how secrets are implemented: Host().Env(), a container, helper, API call, ...
The one shortcoming is we can only scrub once the secret exists. If secrets are leaked during creation, or fail to be created and leak in errors, they won't get scrubbed.
sipsma commentedon Jan 27, 2023
Another factor here is that if you print a secret to stdout/stderr it will be persisted to the buildkit cache as part of the shim stdio redirection. So if we only scrub secrets later when displaying the output to users, it will still be in the cache. We also would need to scrub the secrets from the values returned by the
StdoutandStderrAPIs, which aren't buildkit events. Also in the exec failure error message (which now includes stdout+stderr).This makes me wonder if we should just scrub the secrets as part of the shim stdio redirection itself. That way they never leak to the cache and we don't have to think about scrubbing return values all over the place. Then I think @aluzzardi's suggestion would probably handle the rest of the cases?
shykes commentedon Jan 27, 2023
That would be amazing 🥇
aluzzardi commentedon Jan 27, 2023
@sipsma You're absolutely right -- I forgot about that part.
Yeah, that sounds right.
We'd have to somehow let the shim know that such and such file or env is a secret. Maybe by injecting a metadata file? Or a special env? Does it matter if it's part of the cache key (I guess not)?
Sounds doable.
Wondering if implementing only at the shim level is enough. It won't catch secrets in vertex name (e.g.
echo <plaintext secret>), but I think that's alright? It's a much simpler design.edit: Updated straw-man
container.Execincore/container.go)_DAGGER_SCRUB_SECRETS={files: ["/path"], envs: ["ENV1"]}containing the location of secrets/.dagger_meta_mount_DAGGER_SCRUB_SECRETS, loads all secret values from env and files, and scrubs stdout/stderr in real-timedolanor commentedon Feb 3, 2023
Regarding the caching. I don't know how buildkit would know if it needs to restart a step or not.
If the step needs a secret (
MY_SECRET=mysecretvalue) and it gets scrubbed into***.But if we decide to change the secret to
myothersecretvalue, how can buildkit know that it needs to restart the step? I guess the cache key would contain a hash ofMY_SECRETsecret name, but not the value. Therefore, it might think it doesn't need to restart the step?Or does it restart any step that has secrets?
aluzzardi commentedon Feb 3, 2023
We use hashes of secret values as Secret IDs. So changing a value changes the secret ID, which invalidates the cache of everything referring to that secret id
aluzzardi commentedon Feb 3, 2023
To clarify: the shim has nothing to do with buildkit. The shim runs in the container alongside user code (well, it wraps user code).
Whatever the shim does, it will not affect the cache status (the shim invocation itself will be cached or not)