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

Backport #15399: flare: Do not scrub pprof files #15402

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions comp/core/flare/helpers/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,13 @@ func (fb *builder) AddFileFromFunc(destFile string, cb func() ([]byte, error)) e
return fb.AddFile(destFile, content)
}

func (fb *builder) AddFile(destFile string, content []byte) error {
content, err := fb.scrubber.ScrubBytes(content)
if err != nil {
return fb.logError("error scrubbing content for '%s': %s", destFile, err)
func (fb *builder) addFile(shouldScrub bool, destFile string, content []byte) error {
if shouldScrub {
var err error
content, err = fb.scrubber.ScrubBytes(content)
if err != nil {
return fb.logError("error scrubbing content for '%s': %s", destFile, err)
}
}

f, err := fb.PrepareFilePath(destFile)
Expand All @@ -197,6 +200,14 @@ func (fb *builder) AddFile(destFile string, content []byte) error {
return nil
}

func (fb *builder) AddFile(destFile string, content []byte) error {
return fb.addFile(true, destFile, content)
}

func (fb *builder) AddFileWithoutScrubbing(destFile string, content []byte) error {
return fb.addFile(false, destFile, content)
}

func (fb *builder) copyFileTo(shouldScrub bool, srcFile string, destFile string) error {
fb.permsInfos.add(srcFile)

Expand Down
11 changes: 11 additions & 0 deletions comp/core/flare/helpers/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ func TestAddFile(t *testing.T) {
assertFileContent(t, fb, "api_key: \"********\"", "test/AddFile_scrubbed_api_key")
}

func TestAddFileWithoutScrubbing(t *testing.T) {
fb := getNewBuilder(t)
defer fb.clean()

fb.AddFileWithoutScrubbing(FromSlash("test/AddFile"), []byte("some data"))
assertFileContent(t, fb, "some data", "test/AddFile")

fb.AddFileWithoutScrubbing(FromSlash("test/AddFile_scrubbed_api_key"), []byte("api_key : 123456789006789009"))
assertFileContent(t, fb, "api_key: \"123456789006789009\"", "test/AddFile_scrubbed_api_key")
}

// Test that writeScrubbedFile actually scrubs third-party API keys.
func TestRedactingOtherServicesApiKey(t *testing.T) {
fb := getNewBuilder(t)
Expand Down
9 changes: 9 additions & 0 deletions comp/core/flare/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ type FlareBuilder interface {
// 'content' is automatically scrubbed of any sensitive informations before being added to the flare.
AddFile(destFile string, content []byte) error

// AddFileWithoutScrubbing creates a new file in the flare with the content.
//
// 'destFile' is a path relative to the flare root (ex: "some/path/to/a/file"). Any necessary directory will
// automatically be created.
//
// 'content' is NOT scrubbed of any sensitive informations before being added to the flare.
// Can be used for binary files that mustn’t be corrupted, like pprof profiles for ex.
AddFileWithoutScrubbing(destFile string, content []byte) error

// AddFileFromFunc creates a new file in the flare with the content returned by the callback.
//
// 'destFile' is a path relative to the flare root (ex: "some/path/to/a/file"). Any necessary directory will
Expand Down
2 changes: 1 addition & 1 deletion pkg/flare/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func getVersionHistory(fb flarehelpers.FlareBuilder) {

func getPerformanceProfile(fb flarehelpers.FlareBuilder, pdata ProfileData) {
for name, data := range pdata {
fb.AddFile(filepath.Join("profiles", name), data)
fb.AddFileWithoutScrubbing(filepath.Join("profiles", name), data)
}
}

Expand Down