Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Commit c9b7710

Browse files
author
hadar-co
authored
fix: update name rule logic to ignore incorrect kinds (#957)
* fix: update name rule logic to ignore incorrect kinds * fix: update name rule logic to ignore incorrect kinds * fix: update name rule logic to ignore incorrect kinds * fix: update name rule logic to ignore incorrect kinds * fix: update name rule logic to ignore incorrect kinds
1 parent 6ec89d2 commit c9b7710

File tree

5 files changed

+92
-22
lines changed

5 files changed

+92
-22
lines changed

pkg/defaultRules/defaultRules.yaml

+42-22
Original file line numberDiff line numberDiff line change
@@ -1861,28 +1861,48 @@ rules:
18611861
impact: Configurations with a missing or invalid name will pass k8s schema validation, but will fail when pushed into a cluster (i.e. when running kubectl apply/create)
18621862
schema:
18631863
definitions:
1864-
metadataNamePattern:
1865-
properties:
1866-
metadata:
1867-
type: object
1868-
properties:
1869-
name:
1870-
type: string
1871-
format: hostname
1872-
required:
1873-
- name
1874-
required:
1875-
- metadata
1876-
metadataGenerateNamePattern:
1864+
strictNamesPattern:
1865+
if:
1866+
properties:
1867+
kind:
1868+
not:
1869+
enum:
1870+
- ClusterRole
1871+
- ClusterRoleBinding
1872+
then:
1873+
properties:
1874+
metadata:
1875+
type: object
1876+
anyOf:
1877+
- properties:
1878+
name:
1879+
type: string
1880+
format: hostname
1881+
required:
1882+
- name
1883+
- properties:
1884+
generateName:
1885+
type: string
1886+
format: hostname
1887+
required:
1888+
- generateName
1889+
required:
1890+
- metadata
1891+
nonStrictNamesPattern:
18771892
properties:
18781893
metadata:
18791894
type: object
1880-
properties:
1881-
generateName:
1882-
type: string
1883-
format: hostname
1884-
required:
1885-
- generateName
1895+
anyOf:
1896+
- properties:
1897+
name:
1898+
type: string
1899+
required:
1900+
- name
1901+
- properties:
1902+
generateName:
1903+
type: string
1904+
required:
1905+
- generateName
18861906
required:
18871907
- metadata
18881908
if:
@@ -1892,9 +1912,9 @@ rules:
18921912
enum:
18931913
- Kustomization
18941914
then:
1895-
anyOf:
1896-
- $ref: "#/definitions/metadataNamePattern"
1897-
- $ref: "#/definitions/metadataGenerateNamePattern"
1915+
allOf:
1916+
- $ref: "#/definitions/strictNamesPattern"
1917+
- $ref: "#/definitions/nonStrictNamesPattern"
18981918
- id: 55
18991919
name: Ensure each container probe has an initial delay configured
19001920
uniqueName: CONTAINERS_INCORRECT_INITIALDELAYSECONDS_VALUE
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: invalid:format
5+
spec:
6+
selector:
7+
matchLabels:
8+
app: frontend-deployment
9+
template:
10+
metadata:
11+
labels:
12+
app: frontend-deployment
13+
spec:
14+
containers:
15+
- name: app
16+
image: foo/bar:latest
17+
ports:
18+
- name: http
19+
containerPort: 8080
20+
protocol: TCP
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
# "namespace" omitted since ClusterRoles are not namespaced
5+
name: system:secret-reader
6+
rules:
7+
- apiGroups: [""]
8+
#
9+
# at the HTTP level, the name of the resource for accessing Secret
10+
# objects is "secrets"
11+
resources: ["secrets"]
12+
verbs: ["get", "watch", "list"]
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- service.yaml
5+
- deployment.yaml
6+
- hpa.yaml
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
# "namespace" omitted since ClusterRoles are not namespaced
5+
name: valid:name
6+
rules:
7+
- apiGroups: [""]
8+
#
9+
# at the HTTP level, the name of the resource for accessing Secret
10+
# objects is "secrets"
11+
resources: ["secrets"]
12+
verbs: ["get", "watch", "list"]

0 commit comments

Comments
 (0)