11package processor
22
33import (
4- "strings"
5-
64 "github.com/sysdiglabs/kube-psp-advisor/advisor/types"
75
86 "k8s.io/api/core/v1"
@@ -32,7 +30,6 @@ func (p *Processor) getSecuritySpecFromDaemonSets() ([]types.ContainerSecuritySp
3230 }
3331
3432 for _ , ds := range daemonSetList .Items {
35- p .resourceNamePrefix [ds .Name ] = true
3633 sa := p .serviceAccountMap [ds .Spec .Template .Spec .ServiceAccountName ]
3734 cspList2 , podSecurityPosture := p .gen .GetSecuritySpecFromPodSpec (types.Metadata {
3835 Name : ds .Name ,
@@ -58,11 +55,10 @@ func (p *Processor) getSecuritySpecFromReplicaSets() ([]types.ContainerSecurityS
5855 }
5956
6057 for _ , rs := range replicaSetList .Items {
61- if p . hasSpecRecorded (rs .Name ) {
58+ if len (rs .OwnerReferences ) > 0 {
6259 continue
6360 }
6461
65- p .resourceNamePrefix [rs .Name ] = true
6662 sa := p .serviceAccountMap [rs .Spec .Template .Spec .ServiceAccountName ]
6763 cspList2 , psc := p .gen .GetSecuritySpecFromPodSpec (types.Metadata {
6864 Name : rs .Name ,
@@ -88,7 +84,6 @@ func (p *Processor) getSecuritySpecFromStatefulSets() ([]types.ContainerSecurity
8884 }
8985
9086 for _ , sts := range statefulSetList .Items {
91- p .resourceNamePrefix [sts .Name ] = true
9287 sa := p .serviceAccountMap [sts .Spec .Template .Spec .ServiceAccountName ]
9388 cspList2 , pss := p .gen .GetSecuritySpecFromPodSpec (types.Metadata {
9489 Name : sts .Name ,
@@ -114,7 +109,6 @@ func (p *Processor) getSecuritySpecFromReplicationController() ([]types.Containe
114109 }
115110
116111 for _ , rc := range replicationControllerList .Items {
117- p .resourceNamePrefix [rc .Name ] = true
118112 sa := p .serviceAccountMap [rc .Spec .Template .Spec .ServiceAccountName ]
119113 cspList2 , pss := p .gen .GetSecuritySpecFromPodSpec (types.Metadata {
120114 Name : rc .Name ,
@@ -140,7 +134,6 @@ func (p *Processor) getSecuritySpecFromCronJobs() ([]types.ContainerSecuritySpec
140134 }
141135
142136 for _ , cronJob := range jobList .Items {
143- p .resourceNamePrefix [cronJob .Name ] = true
144137 sa := p .serviceAccountMap [cronJob .Spec .JobTemplate .Spec .Template .Spec .ServiceAccountName ]
145138 cspList2 , pss := p .gen .GetSecuritySpecFromPodSpec (types.Metadata {
146139 Name : cronJob .Name ,
@@ -166,11 +159,9 @@ func (p *Processor) getSecuritySpecFromJobs() ([]types.ContainerSecuritySpec, []
166159 }
167160
168161 for _ , job := range jobList .Items {
169- if p . hasSpecRecorded (job .Name ) {
162+ if len (job .OwnerReferences ) > 0 {
170163 continue
171164 }
172-
173- p .resourceNamePrefix [job .Name ] = true
174165 sa := p .serviceAccountMap [job .Spec .Template .Spec .ServiceAccountName ]
175166 cspList2 , pss := p .gen .GetSecuritySpecFromPodSpec (types.Metadata {
176167 Name : job .Name ,
@@ -196,7 +187,6 @@ func (p *Processor) getSecuritySpecFromDeployments() ([]types.ContainerSecurityS
196187 }
197188
198189 for _ , deploy := range deployments .Items {
199- p .resourceNamePrefix [deploy .Name ] = true
200190 sa := p .serviceAccountMap [deploy .Spec .Template .Spec .ServiceAccountName ]
201191 cspList2 , pss := p .gen .GetSecuritySpecFromPodSpec (types.Metadata {
202192 Name : deploy .Name ,
@@ -210,15 +200,6 @@ func (p *Processor) getSecuritySpecFromDeployments() ([]types.ContainerSecurityS
210200 return cssList , pssList , nil
211201}
212202
213- func (p * Processor ) hasSpecRecorded (resourceName string ) bool {
214- for prefix := range p .resourceNamePrefix {
215- if strings .HasPrefix (resourceName , prefix ) {
216- return true
217- }
218- }
219- return false
220- }
221-
222203func (p * Processor ) getSecuritySpecFromPods () ([]types.ContainerSecuritySpec , []types.PodSecuritySpec , error ) {
223204 clientset := p .k8sClient
224205 cssList := []types.ContainerSecuritySpec {}
@@ -231,7 +212,7 @@ func (p *Processor) getSecuritySpecFromPods() ([]types.ContainerSecuritySpec, []
231212 }
232213
233214 for _ , pod := range pods .Items {
234- if p . hasSpecRecorded (pod .Name ) {
215+ if len (pod .OwnerReferences ) > 0 {
235216 continue
236217 }
237218
0 commit comments