Skip to content
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

Redact EXPLICIT_COMMAND_LINE #4525

Merged
merged 2 commits into from
Aug 11, 2023
Merged

Conversation

siggisim
Copy link
Member

@siggisim siggisim commented Aug 9, 2023

Explicitly redacts EXPLICIT_COMMAND_LINE in the BuildMetadata event so it can be rendered in the UI with <redacted> for any command line options that should be redacted.

In all other events, it's just dropped so we don't have to deal with parsing it.

Fixes: https://github.com/buildbuddy-io/buildbuddy-internal/issues/2540

@siggisim siggisim requested a review from bduffany August 9, 2023 22:39
server/util/redact/redact.go Outdated Show resolved Hide resolved
server/util/redact/redact.go Outdated Show resolved Hide resolved
@@ -282,6 +301,7 @@ func TestRedactMetadata_BuildMetadata_StripsURLSecrets(t *testing.T) {
})

assert.Equal(t, "https://github.com/buildbuddy-io/metadata_repo_url", buildMetadata.Metadata["REPO_URL"])
assert.Equal(t, `["--remote_header=\u003cREDACTED\u003e","--foo=SAFE"]`, buildMetadata.Metadata["EXPLICIT_COMMAND_LINE"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use < and > since they are plain ascii chars?

Suggested change
assert.Equal(t, `["--remote_header=\u003cREDACTED\u003e","--foo=SAFE"]`, buildMetadata.Metadata["EXPLICIT_COMMAND_LINE"])
assert.Equal(t, `["--remote_header=<REDACTED>","--foo=SAFE"]`, buildMetadata.Metadata["EXPLICIT_COMMAND_LINE"])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had this initially, but it seems the JSON marshalling / unmarshalling code converts these into \u003c and \u003e. They're rendered correctly in the UI so it doesn't seem like a huge deal (there's a way to enable this escaping, but I'd kinda rather leave it enabled because I'm sure there's some reason for it).

What I was really looking for was an assert.Equal that behaves more like strings.EqualFold() but couldn't find anything.

Copy link
Member

@bduffany bduffany Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd kinda rather leave it enabled because I'm sure there's some reason for it

ah I bet it's to support dumping these into HTML templates without the < being treated as a tag or something like that.

Copy link
Member

@bduffany bduffany Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, TIL: https://codepen.io/bduffs/pen/LYXoKoP

I guess the HTML parser isn't aware of what's going on inside the <script> and is just blindly looking for the closing </script>.

func stripExplicitCommandLineFromCmdLine(tokens []string) {
for i, token := range tokens {
if strings.HasPrefix(token, buildMetadataOptionPrefix+explicitCommandLineName+"=") {
tokens[i] = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearing out the arg (instead of dropping) might cause issues later, since a literal "" argument is treated by bazel as an error, but seems fine for now since we won't actually render the "" in the UI. just something to be aware of in case we see errors in the future

ERROR: Skipping '': invalid target name '': empty target name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, this should just be for UI rendering - we can switch to filtering if it causes issues.

Co-authored-by: Brandon Duffany <brandon@buildbuddy.io>
@siggisim siggisim merged commit e7772d9 into master Aug 11, 2023
1 of 2 checks passed
@siggisim siggisim deleted the siggi-dev-branch-20230809-153809 branch August 11, 2023 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants