Skip to content

Commit

Permalink
flare: Do not scrub pprof files (#15399)
Browse files Browse the repository at this point in the history
  • Loading branch information
L3n41c committed Feb 2, 2023
1 parent 2d9746e commit 17dce24
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
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

0 comments on commit 17dce24

Please sign in to comment.