-
Notifications
You must be signed in to change notification settings - Fork 98
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
OCPBUGS-6731: Anonymize env vars from containers: HTTP_PROXY, HTTPS_PROXY #723
Merged
openshift-merge-robot
merged 9 commits into
openshift:master
from
ncaak:CCXDEV-10028/anonymize-env-vars-https-proxy
Feb 16, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
28ff383
WIP draft overwriting env vars values
ncaak 73296b0
Add unit test for env var obfuscation on container images gatherer
ncaak 7d06bb8
Refactor obfuscate env vars functionality
ncaak 6b05167
Fix obfusctation functionality and tests lint issues
ncaak 8a806b7
Move sensitive env vars obfuscation logic to anonymize utils package
ncaak 9dc37de
Add env vars obfuscation to pod recording
ncaak f9126b4
Use assert library
ncaak fa98699
Add PR 723 Obfuscate HTTP_PROXY and HTTPS_PROXY
ncaak 1ed8ebf
Fix PR 723 type to bugfix
ncaak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package anonymize | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// SensitiveEnvVars finds env variables within the given container list | ||
// and, if they are a target, it will obfuscate their value | ||
func SensitiveEnvVars(containers []corev1.Container) { | ||
targets := []string{"HTTP_PROXY", "HTTPS_PROXY"} | ||
search := regexp.MustCompile(strings.Join(targets, "|")) | ||
|
||
for i := range containers { | ||
for j := range containers[i].Env { | ||
if search.MatchString(containers[i].Env[j].Name) { | ||
containers[i].Env[j].Value = String(containers[i].Env[j].Value) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package anonymize | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func Test_EnvVar_Obfuscation(t *testing.T) { | ||
// Given | ||
mock := []corev1.Container{ | ||
{ | ||
Env: []corev1.EnvVar{ | ||
{Name: "NO_TARGET", Value: "original_value"}, | ||
{Name: "HTTP_PROXY", Value: "original_value"}, | ||
{Name: "HTTPS_PROXY", Value: "original_value"}, | ||
}, | ||
}, | ||
} | ||
envOriginalValue := "original_value" | ||
|
||
// When | ||
SensitiveEnvVars(mock) | ||
|
||
// Assert | ||
t.Run("Non target env vars keep their original value", func(t *testing.T) { | ||
test := mock[0].Env[0] | ||
assert.Equal(t, envOriginalValue, test.Value) | ||
}) | ||
t.Run("HTTP_PROXY is updated with obfuscated value", func(t *testing.T) { | ||
test := mock[0].Env[1] | ||
assert.NotEqual(t, envOriginalValue, test.Value) | ||
}) | ||
t.Run("HTTPS_PROXY is updated with obfuscated value", func(t *testing.T) { | ||
test := mock[0].Env[2] | ||
assert.NotEqual(t, envOriginalValue, test.Value) | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
First time someone updated changelog with a new PR. :) This is not a new data enhancement, but rather bugfix or other (and yes it corresponds to the PR template selection)
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.
New data enhancement is e.g new gatherer for XYZ.
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.
Ok, updating it right now to BugFix. Thanks.