-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCPBUGS-6731: Anonymize env vars from containers: HTTP_PROXY, HTTPS_P…
…ROXY (#723) * WIP draft overwriting env vars values * Add unit test for env var obfuscation on container images gatherer * Refactor obfuscate env vars functionality * Fix obfusctation functionality and tests lint issues * Move sensitive env vars obfuscation logic to anonymize utils package * Add env vars obfuscation to pod recording * Use assert library * Add PR 723 Obfuscate HTTP_PROXY and HTTPS_PROXY * Fix PR 723 type to bugfix
- Loading branch information
Showing
7 changed files
with
74 additions
and
0 deletions.
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) | ||
}) | ||
} |