Skip to content

Commit

Permalink
fix: conditional expressions should be at very top of additionalSchem…
Browse files Browse the repository at this point in the history
…aStrings (#1025)
  • Loading branch information
jslivka authored Jan 3, 2024
1 parent 0b765df commit c8394bf
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 9 deletions.
4 changes: 2 additions & 2 deletions checks/clusterrolebindingClusterAdmin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ schemaString: |
const: "cluster-admin"
additionalSchemaStrings:
rbac.authorization.k8s.io/ClusterRole: |
type: object
# Do not alert on default ClusterRoleBindings.
{{ if (ne .roleRef.name "view") }}
{{ if and (ne .metadata.name "cluster-admin") (not (hasPrefix .metadata.name "system:")) (ne .metadata.name "gce:podsecuritypolicy:calico-sa") }}
# Do not alert on default ClusterRoleBindings.
type: object
required: ["metadata", "rules"]
allOf:
- properties:
Expand Down
4 changes: 2 additions & 2 deletions checks/rolebindingClusterAdminClusterRole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ schemaString: |
const: "cluster-admin"
additionalSchemaStrings:
rbac.authorization.k8s.io/ClusterRole: |
type: object
# This schema is validated for all roleBindings, regardless of their roleRef.
{{ if eq .roleRef.kind "ClusterRole" }}
{{ if and (not (hasPrefix .metadata.name "system:")) (ne .metadata.name "gce:podsecuritypolicy:calico-sa") }}
# This schema is validated for all roleBindings, regardless of their roleRef.
type: object
required: ["metadata", "rules"]
allOf:
- properties:
Expand Down
4 changes: 2 additions & 2 deletions checks/rolebindingClusterRolePodExecAttach.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ schemaString: |
minLength: 1
additionalSchemaStrings:
rbac.authorization.k8s.io/ClusterRole: |
type: object
# This schema is validated for all roleBindings, regardless of their roleRef.
{{ if eq .roleRef.kind "ClusterRole" }}
{{ if and (not (hasPrefix .metadata.name "system:")) (ne .metadata.name "gce:podsecuritypolicy:calico-sa") }}
# This schema is validated for all roleBindings, regardless of their roleRef.
type: object
required: ["metadata", "rules"]
allOf:
- properties:
Expand Down
4 changes: 2 additions & 2 deletions checks/rolebindingRolePodExecAttach.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ schemaString: |
minLength: 1
additionalSchemaStrings:
rbac.authorization.k8s.io/Role: |
type: object
# This schema is validated for all roleBindings, regardless of their roleRef.
{{ if eq .roleRef.kind "Role" }}
{{ if and (not (hasPrefix .metadata.name "system:")) (ne .metadata.name "gce:podsecuritypolicy:calico-sa") }}
# This schema is validated for all roleBindings, regardless of their roleRef.
type: object
required: ["metadata", "rules"]
allOf:
- properties:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/fairwindsops/controller-utils v0.3.0
github.com/fairwindsops/insights-plugins/plugins/workloads v0.0.0-20230601204422-5c789e15990c
github.com/fatih/color v1.15.0
github.com/gobuffalo/packr/v2 v2.8.3
Expand All @@ -30,7 +31,6 @@ require (
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fairwindsops/controller-utils v0.3.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: test
labels:
role: service
tier: backend
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: test
rules:
- apiGroups: [""]
resources: [services]
verbs: [get, list]
---
# check when there are no cluster roles present
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: test
roleRef:
kind: Role
name: test
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: test
labels:
role: service
tier: backend
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: test
rules:
- apiGroups: [""]
resources: [services]
verbs: [get, list]
---
# check when there are no cluster roles present
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: test
roleRef:
kind: Role
name: test
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: test
labels:
role: service
tier: backend
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: test
rules:
- apiGroups: [""]
resources: [services]
verbs: [get, list]
---
# check when there are no cluster roles present
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: test
roleRef:
kind: Role
name: test
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: test

0 comments on commit c8394bf

Please sign in to comment.