Skip to content

Commit

Permalink
Add detection of projected secrets & config maps
Browse files Browse the repository at this point in the history
  • Loading branch information
bpfoster committed Oct 31, 2024
1 parent 13f3b9c commit ba9291c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
17 changes: 17 additions & 0 deletions internal/cache/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,23 @@ func (*Pod) volumeRefs(ns string, vv []v1.Volume, refs *sync.Map) {
if cmv != nil {
addKeys(ConfigMapKey, FQN(ns, cmv.LocalObjectReference.Name), cmv.Items, refs)
}

if v.VolumeSource.Projected != nil {
vp := v.VolumeSource.Projected.Sources
if vp != nil {
for _, projection := range vp {
ps := projection.Secret
if ps != nil {
addKeys(SecretKey, FQN(ns, ps.Name), ps.Items, refs)
}

pcm := projection.ConfigMap
if pcm != nil {
addKeys(ConfigMapKey, FQN(ns, pcm.Name), pcm.Items, refs)
}
}
}
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions internal/lint/cm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ func TestConfigMapLint(t *testing.T) {
assert.Equal(t, rules.InfoLevel, ii[0].Level)

ii = cm.Outcome()["default/cm2"]
assert.Equal(t, 1, len(ii))
assert.Equal(t, "[POP-400] Used? Unable to locate resource reference", ii[0].Message)
assert.Equal(t, rules.InfoLevel, ii[0].Level)
assert.Equal(t, 0, len(ii))

ii = cm.Outcome()["default/cm3"]
assert.Equal(t, 0, len(ii))
Expand Down
4 changes: 1 addition & 3 deletions internal/lint/sec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func TestSecretLint(t *testing.T) {
assert.Equal(t, rules.InfoLevel, ii[0].Level)

ii = sec.Outcome()["default/sec2"]
assert.Equal(t, 1, len(ii))
assert.Equal(t, `[POP-400] Used? Unable to locate resource reference`, ii[0].Message)
assert.Equal(t, rules.InfoLevel, ii[0].Level)
assert.Equal(t, 0, len(ii))

ii = sec.Outcome()["default/sec3"]
assert.Equal(t, 1, len(ii))
Expand Down
17 changes: 17 additions & 0 deletions internal/lint/testdata/core/pod/1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ items:
path: "game.properties"
- key: namespace
path: "user-interface.properties"
- name: projected
projected:
sources:
- secret:
name: sec2
items:
- key: admin-user
path: "user"
- key: admin-password
path: "password"
- configMap:
name: cm2
items:
- key: k1
path: "k1"
- key: k2
path: "k2"
status:
podIPs:
- ip: 172.1.0.3
Expand Down

0 comments on commit ba9291c

Please sign in to comment.