Repository navigation
Secret Scrub Multi Write #5149
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
Secret Scrub Multi Write #5149
Changes from all commits
83ee5c2
b1c0e94
2a91fb5
823da3f
b4e1b44
e7b2c77
1aed29a
2b35204
4b26559
1be5225
9c1bab9
cae9082
44476c8
213a3f7
71c88ed
a04fc64
533d8d1
33a1f9a
249d30b
0567025
213218f
46bf7bc
190a826
6e879d2
39f7258
a7932e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import ( | |
| "runtime" | ||
| "strconv" | ||
| "strings" | ||
| "sync" | ||
| "syscall" | ||
| "time" | ||
|
|
||
|
|
@@ -38,6 +39,7 @@ const ( | |
| var ( | ||
| stdoutPath = metaMountPath + "/stdout" | ||
| stderrPath = metaMountPath + "/stderr" | ||
| pipeWg sync.WaitGroup | ||
| ) | ||
|
|
||
| /* | ||
|
|
@@ -286,22 +288,40 @@ func shim() int { | |
| outWriter := io.MultiWriter(stdoutFile, os.Stdout) | ||
| errWriter := io.MultiWriter(stderrFile, os.Stderr) | ||
|
|
||
| // Only initialize scrubbing logic if secrets are set: | ||
| if len(secretsToScrub.Envs) == 0 && len(secretsToScrub.Files) == 0 { | ||
| cmd.Stdout = outWriter | ||
| cmd.Stderr = errWriter | ||
| } else { | ||
| // Get pipes for command's stdout and stderr and process output | ||
| // through secret scrub reader in multiple goroutines: | ||
| envToScrub := os.Environ() | ||
| scrubOutWriter, err := NewSecretScrubWriter(outWriter, currentDirPath, shimFS, envToScrub, secretsToScrub) | ||
| stdoutPipe, err := cmd.StdoutPipe() | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| cmd.Stdout = scrubOutWriter | ||
| scrubErrWriter, err := NewSecretScrubWriter(errWriter, currentDirPath, shimFS, envToScrub, secretsToScrub) | ||
| scrubOutReader, err := NewSecretScrubReader(stdoutPipe, currentDirPath, shimFS, envToScrub, secretsToScrub) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| cmd.Stderr = scrubErrWriter | ||
| pipeWg.Add(1) | ||
| go func() { | ||
| defer pipeWg.Done() | ||
| io.Copy(outWriter, scrubOutReader) | ||
| }() | ||
|
|
||
| stderrPipe, err := cmd.StderrPipe() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matiasinsaurralde I think the test failures are due to use of
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): |
||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| scrubErrReader, err := NewSecretScrubReader(stderrPipe, currentDirPath, shimFS, envToScrub, secretsToScrub) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| pipeWg.Add(1) | ||
| go func() { | ||
| defer pipeWg.Done() | ||
| io.Copy(errWriter, scrubErrReader) | ||
| }() | ||
| } | ||
|
|
||
| exitCode := 0 | ||
|
|
@@ -540,7 +560,17 @@ func internalEnv(name string) (string, bool) { | |
| func runWithNesting(ctx context.Context, cmd *exec.Cmd) error { | ||
| if _, found := internalEnv("_DAGGER_ENABLE_NESTING"); !found { | ||
| // no nesting; run as normal | ||
| return cmd.Run() | ||
| if err := cmd.Start(); err != nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This approach looks good, we just also need to update the use of |
||
| return err | ||
| } | ||
|
|
||
| // Wait for stdout and stderr copy goroutines to finish: | ||
| pipeWg.Wait() | ||
|
|
||
| if err := cmd.Wait(); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // setup a session and associated env vars for the container | ||
|
|
@@ -578,8 +608,16 @@ func runWithNesting(ctx context.Context, cmd *exec.Cmd) error { | |
| var cmdErr error | ||
| engineErr = engine.Start(ctx, engineConf, func(ctx context.Context, r *router.Router) error { | ||
| go http.Serve(l, r) //nolint:gosec | ||
| cmdErr = cmd.Run() | ||
| return cmdErr | ||
| cmdErr = cmd.Start() | ||
| if cmdErr != nil { | ||
| return cmdErr | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sipsma My bad, just added it! |
||
| pipeWg.Wait() | ||
| cmdErr = cmd.Wait() | ||
| if cmdErr != nil { | ||
| return cmdErr | ||
| } | ||
| return nil | ||
| }) | ||
| if cmdErr != nil { | ||
| // propagate inner error with higher priority | ||
|
|
||
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 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?
Uh oh!
There was an error while loading. Please reload this page.
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 pushed the same changes and didn't see the issue again however I'm facing the following scenarios when testing latest
main:TestContainerWithMountedSecretOwnertests work fine.sudo ./hack/dev, etc.) tests pass.I tried the same with this branch, when running with
sudotest pass, regular usar fails.So I'm wandering the following:
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am running as a normal user on:
First

5local runs of_EXPERIMENTAL_DAGGER_INTERACTIVE_TUI=1 dagger run ./hack/make engine:testpassed:Next
5local runs of_EXPERIMENTAL_DAGGER_INTERACTIVE_TUI=1 dagger run ./hack/make engine:testracealso 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've verified this again, tried the following:
TestContainerWithMountedSecretOwnermultiple times in both branches (mainand this one), with and without race. Didn't see any issues so far.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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the reason why test
TestContainerWithMountedSecretOwner/useridhas 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, rango test -v -count=1 -timeout 30s -run ^TestContainerWithMountedSecretOwner/userid-111$ github.com/dagger/dagger/core/integrationand the results are just fine!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.
Are you saying that if
TestContainerWithMountedSecretOwner/useridtest changes, the previous run remains cached? That would be surprising behaviour which we should address.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 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.