add role and validation policy for namespaces

This commit is contained in:
2025-10-28 16:03:26 -05:00
parent 08060d8d97
commit 5dfc7e8871
6 changed files with 54 additions and 81 deletions

View File

@@ -1,3 +1,11 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: edit-namespaces
rules:
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["create", "get", "list", "watch", "update", "patch", "delete"]
--- ---
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding kind: ClusterRoleBinding
@@ -11,3 +19,16 @@ roleRef:
kind: ClusterRole kind: ClusterRole
name: ontime-operator-stage-editor-role name: ontime-operator-stage-editor-role
apiGroup: rbac.authorization.k8s.io apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: edit-namespaces-clusterrolebinding
subjects:
- kind: ServiceAccount
name: stage-editor
namespace: stage-maker
roleRef:
kind: ClusterRole
name: edit-namespaces
apiGroup: rbac.authorization.k8s.io

View File

@@ -1,44 +0,0 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: stage-maker
namespace: stage-maker
labels:
app: stage-maker
spec:
replicas: 1
selector:
matchLabels:
app: stage-maker
template:
metadata:
labels:
app: stage-maker
spec:
serviceAccountName: stage-editor
volumes:
- name: storage
nfs:
path: /volume1/docker/ontime-k8s
server: 10.0.0.17
containers:
- name: stage-maker
image: git.jwetzell.com/jwetzell/stage-maker:v0.0.18
env:
- name: ONTIME_HOSTNAME
value: "ontime.jwetzell.com"
- name: NFS_SERVER
value: "10.0.0.17"
- name: NFS_BASE_PATH
value: "/volume1/docker/ontime-k8s"
- name: STORAGE_BASE_PATH
value: "/data"
resources:
limits:
memory: "1024Mi"
requests:
cpu: 1000m
memory: "512Mi"
volumeMounts:
- name: storage
mountPath: "/data"

View File

@@ -1,18 +0,0 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: stage-maker-ingress
namespace: stage-maker
spec:
ingressClassName: nginx
rules:
- host: ontime.jwetzell.com
http:
paths:
- path: /api/v1/stage
pathType: Prefix
backend:
service:
name: stage-maker-service
port:
number: 3000

View File

@@ -1,9 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1 apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
resources: resources:
- namespace.yaml
- deployment.yaml
- ingress.yaml
- cluster-role-binding.yaml - cluster-role-binding.yaml
- namespace-prefix-policy.yaml
- namespace.yaml
- service-account.yaml - service-account.yaml
- service.yaml

View File

@@ -0,0 +1,31 @@
apiVersion: admissionregistration.k8s.io/v1alpha1
kind: ValidatingAdmissionPolicy
metadata:
name: "force-ns-prefix-for-stage-editor"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups: [""]
apiVersions: ["v1"]
operations: ["CREATE", "UPDATE"]
resources: ["namespaces"]
matchConditions:
- name: 'only-stage-editor'
value: "request.userInfo.username == 'system:serviceaccount:stage-maker:stage-editor'"
validations:
- expression: "object.metadata.namespace.startsWith('team-')"
message: "All namespace requests by stage-editor must start with 'team-'"
---
apiVersion: admissionregistration.k8s.io/v1alpha1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: "force-ns-prefix-for-stage-editor-binding"
spec:
policyName: "force-ns-prefix-for-stage-editor"
matchResources:
resourceRules:
- apiGroups: [""]
apiVersions: ["v1"]
operations: ["CREATE", "UPDATE"]
resources: ["namespaces"]

View File

@@ -1,15 +0,0 @@
apiVersion: v1
kind: Service
metadata:
name: stage-maker-service
namespace: stage-maker
spec:
selector:
app: stage-maker
ports:
- protocol: "TCP"
port: 3000
targetPort: 3000
name: web