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

Allow container exclusions based on regex #267

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,18 @@ popeye:
# Excludes excludes certain resources from Popeye scans
excludes:
v1/pods:
# In the monitoring namespace excludes all probes check on pod's containers.
- name: rx:monitoring
codes:
- 102
# Excludes all istio-proxy container scans for pods in the icx namespace.
- name: rx:icx/.*
containers:
# Excludes istio init/sidecar container from scan!
- istio-proxy
- istio-init
# In the monitoring namespace excludes all probes check on pod's containers.
- name: rx:monitoring
codes:
- 102
# Excludes all istio-proxy container scans for pods in the icx namespace.
- name: rx:icx/.*
containers:
# Excludes istio init/sidecar container from scan!
- istio-proxy
- istio-init
# Excludes the same containers, but with a regex
- rx:^istio
# ConfigMap sanitizer exclusions...
v1/configmaps:
# Excludes key must match the singular form of the resource.
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/excludes.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ func (e Excludes) ExcludeContainer(gvr, fqn, container string) bool {

func in(ss []string, victim string) bool {
for _, s := range ss {
if isRegex(s) {
return rxMatch(s, victim)
}
if s == victim {
return true
}
Expand Down
78 changes: 78 additions & 0 deletions pkg/config/excludes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ func TestExcludes(t *testing.T) {
res: "bleeblah",
code: 101,
},
"no_exclude_if_containers": {
excludes: config.Excludes{
"fred": {
config.Exclusion{Name: "rx:bird", Codes: []config.ID{100, 200, 300}, Containers: []string{"mike"}},
config.Exclusion{Name: "bb", Codes: []config.ID{100, 200, 300}},
config.Exclusion{Name: "cc", Codes: []config.ID{100, 200, 300}},
},
},
section: "fred",
res: "birds",
code: 101,
e: false,
},
}

for k := range uu {
Expand All @@ -172,3 +185,68 @@ func TestExcludes(t *testing.T) {
})
}
}

func TestExcludeContainer(t *testing.T) {
tests := []struct {
name string
gvr string
fqn string
container string
excludes config.Excludes
want bool
}{
{
name: "no excludes, no match",
gvr: "v1/pods",
fqn: "pod-1",
container: "container-1",
excludes: nil,
want: false,
},
{
name: "match",
gvr: "v1/pods",
fqn: "aa",
container: "container-1",
excludes: config.Excludes{
"v1/pods": {
config.Exclusion{Name: "aa", Codes: []config.ID{100, 200, 300}, Containers: []string{"container-1"}},
},
},
want: true,
},
{
name: "match regex",
gvr: "v1/pods",
fqn: "aa",
container: "container-1",
excludes: config.Excludes{
"v1/pods": {
config.Exclusion{Name: "aa", Codes: []config.ID{100, 200, 300}, Containers: []string{"rx:cont"}},
},
},
want: true,
},
{
name: "no match regex",
gvr: "v1/pods",
fqn: "aa",
container: "cron-tainer-1",
excludes: config.Excludes{
"v1/pods": {
config.Exclusion{Name: "aa", Codes: []config.ID{100, 200, 300}, Containers: []string{"rx:cont"}},
},
},
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := tt.excludes.ExcludeContainer(tt.gvr, tt.fqn, tt.container)
if got != tt.want {
t.Errorf("got %v, want %v", got, tt.want)
}
})
}
}
Loading