Repository navigation
Secret Scrub Multi Write - #5149
Conversation
fc9a852 to
fffa7d8
Compare
sipsma
left a comment
There was a problem hiding this comment.
Just did a quick high-level pass since it's still in draft, but overall looks like it's all heading in a good direction!
fffa7d8 to
b9f782f
Compare
19d3111 to
9fada4e
Compare
sipsma
left a comment
There was a problem hiding this comment.
Was just digging into the weeds of the implementation and got a better feeling for how intricate it is.
That got me wondering if there is any library that we can use instead to do this. I found this one, which at a glance looks like it might do what we need? But not totally sure.
I'm not opposed to doing all this ourselves if it's the best option, just want to double check it makes sense to be written/maintained by us.
|
This seems best left for a future release, will not be in this week. |
9fada4e to
2f460b7
Compare
a1c4a09 to
3b2fd90
Compare
|
I don't see this one making it into this release @matiasinsaurralde. Would be nice to get it merged next week maybe. cc @samalba @mircubed |
3974e80 to
6e9a051
Compare
6e9a051 to
3242008
Compare
There was a problem hiding this comment.
I just noticed the test failure, looks like it may be significant: https://github.com/dagger/dagger/actions/runs/5189016555/jobs/9353423519?pr=5149#step:5:14608
Don't know, but I'm wondering if we are just ending up not always flushing all the output sometimes?
There was a problem hiding this comment.
I pushed the same changes and didn't see the issue again however I'm facing the following scenarios when testing latest main:
- On M1 with Docker Desktop all
TestContainerWithMountedSecretOwnertests work fine. - On my Linux box, if I use a regular user I see this issue:
=== RUN TestContainerWithMountedSecretOwner/userid
#1 resolve image config for docker.io/library/alpine:3.16.2
container_test.go:3671:
Error Trace: /home/matias/go/src/github.com/dagger/dagger/core/integration/container_test.go:3671
Error: Not equal:
expected: "auser auser"
actual : "auser "
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-auser auser
+auser
Test: TestContainerWithMountedSecretOwner/userid
- If I ran everything as root (
sudo ./hack/dev, etc.) tests pass.
I tried the same with this branch, when running with sudo test pass, regular usar fails.
So I'm wandering the following:
- I see there's some logic around inheriting permissions in 48fb31d. Could this break depending on which user is being used in the host?
- Based on the above, do we run tests in some privileged mode? And/or did we change anything related to it since the last failing test report you did?
Could be good to involve @vito here too, thanks! Besides that I don't see that the previously failing test is related to my changes but would be good to understand why the issue happened.
There was a problem hiding this comment.
I am running as a normal user on:
Server:
Server Version: 20.10.21
Storage Driver: overlay2
Backing Filesystem: extfs
Native Overlay Diff: true
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
containerd version: v1.6.18
Kernel Version: 5.15.81
Operating System: NixOS 22.11 (Raccoon)
Architecture: x86_64First 5 local runs of _EXPERIMENTAL_DAGGER_INTERACTIVE_TUI=1 dagger run ./hack/make engine:test passed:

Next 5 local runs of _EXPERIMENTAL_DAGGER_INTERACTIVE_TUI=1 dagger run ./hack/make engine:testrace also passed. I have delete the Engine container as well as the volume after every run. If this is a race condition - which I suspect it is - it's not an easy one to trigger. I will keep running it until I do.
FTR, this is the last run in CI which hit it: https://github.com/dagger/dagger/actions/runs/5189016555/jobs/9353423519?pr=5149#step:5:14607
There was a problem hiding this comment.
@gerhard Interesting, for me it works properly on Mac using a regular user.
The issue seems to occur on Linux only.
There was a problem hiding this comment.
I would also guess this is some kind of race condition or issue with the secret scrubbing. These tests should have no relation to what user runs them on the host. 🤔 I can't think of a way to convince stat -c '%U %G' to print an empty %G, so it seems more like the last chunk of output is bring dropped. Happy to be wrong, but that's my guess.
There was a problem hiding this comment.
@vito makes sense however I also see it in latest main -without my changes-. Will debug a bit more on Monday.
There was a problem hiding this comment.
I've verified this again, tried the following:
- Ran
TestContainerWithMountedSecretOwnermultiple times in both branches (mainand this one), with and without race. Didn't see any issues so far. - Added a
panic()to the block where secret scrub logic is initialized here so that the execution breaks If this part of the code is reached: regular secret scrub integration tests likeTestBigSecretScrubbedgot thepanicbutTestContainerWithMountedSecretOwnerdidn't, this indicates that the logic that's part of this PR isn't involved inTestContainerWithMountedSecretOwnerat all.
There was a problem hiding this comment.
Also the reason why test TestContainerWithMountedSecretOwner/userid has been failing to me seems to be a caching issue. Even with rebuilds it would still print the wrong output (a user ).
I renamed the test to TestContainerWithMountedSecretOwner/userid-111, ran go test -v -count=1 -timeout 30s -run ^TestContainerWithMountedSecretOwner/userid-111$ github.com/dagger/dagger/core/integration and the results are just fine!
There was a problem hiding this comment.
Are you saying that if TestContainerWithMountedSecretOwner/userid test changes, the previous run remains cached? That would be surprising behaviour which we should address.
There was a problem hiding this comment.
I continued running this as mentioned, and even though I have hit other issues - still to create them - I was not able to reproduce the original failure. I have seen it fail once locally, before I started looking for it, but not since.
9fbd078 to
16e58c4
Compare
16e58c4 to
f7b37c6
Compare
There was a problem hiding this comment.
@matiasinsaurralde I think the test failures are due to use of cmd.StdoutPipe and cmd.StderrPipe. The docs for those say:
It is thus incorrect to call Wait before all reads from the pipe have completed. For the same reason, it is incorrect to use Run when using StderrPipe. See the StdoutPipe example for idiomatic usage.
I was able to repro the failures consistently when pulling this PR locally, I was no longer able to repro w/ this (very rough patch):
diff --git a/cmd/shim/main.go b/cmd/shim/main.go
index ecdc8567..09972d94 100644
--- a/cmd/shim/main.go
+++ b/cmd/shim/main.go
@@ -291,21 +291,17 @@ func shim() int {
cmd.Stderr = errWriter
} else {
envToScrub := os.Environ()
- stdoutPipe, err := cmd.StdoutPipe()
- if err != nil {
- panic(err)
- }
- scrubOutReader, err := NewSecretScrubReader(stdoutPipe, currentDirPath, shimFS, envToScrub, secretsToScrub)
+ outR, outW := io.Pipe()
+ cmd.Stdout = outW
+ scrubOutReader, err := NewSecretScrubReader(outR, currentDirPath, shimFS, envToScrub, secretsToScrub)
if err != nil {
panic(err)
}
go io.Copy(outWriter, scrubOutReader)
- stderrPipe, err := cmd.StderrPipe()
- if err != nil {
- panic(err)
- }
- scrubErrReader, err := NewSecretScrubReader(stderrPipe, currentDirPath, shimFS, envToScrub, secretsToScrub)
+ errR, errW := io.Pipe()
+ cmd.Stderr = errW
+ scrubErrReader, err := NewSecretScrubReader(errR, currentDirPath, shimFS, envToScrub, secretsToScrub)
if err != nil {
panic(err)
}
8884a4f to
fd20bad
Compare
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
when the scrubbing happens, it will try to scrub the biggest first if a secret is a substring of a bigger one, it will avoid partial leaks of the bigger secret Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Tanguy ⧓ Herrmann <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
Signed-off-by: Matias Insaurralde <[email protected]>
fd20bad to
190a826
Compare
…roperly flushed Signed-off-by: Matias Insaurralde <[email protected]>
| if _, found := internalEnv("_DAGGER_ENABLE_NESTING"); !found { | ||
| // no nesting; run as normal | ||
| return cmd.Run() | ||
| if err := cmd.Start(); err != nil { |
There was a problem hiding this comment.
This approach looks good, we just also need to update the use of cmd.Run on line 611 with the same thing
Signed-off-by: Matias Insaurralde <[email protected]>
| cmdErr = cmd.Start() | ||
| if cmdErr != nil { | ||
| return cmdErr | ||
| } |
There was a problem hiding this comment.
Don't we need a pipeWg.Wait call before the cmd.Wait here too?
Signed-off-by: Matias Insaurralde <[email protected]>
Picking up #4944 with some refactoring:
First iteration:
SecretScrubWriterwrite logic and only use[]bytefor matching and replacements. I also exploredstrings.Replacerandbytes.Replacerbut didn't find a good overall performance in this context.SecretScrubWriterto store secrets as[]byteduring initialization, also moved empty secret value check to initialization step (it was previously happening on everyWrite) as part ofsplitSecretsByLine.secret_scrub_test.go.Second/current iteration:
exec.Cmdpipes to capture output andio.Copyfor writing to corresponding files and actual stdout and stderr.