[hi] add example access
parent
83b05e5430
commit
b94d144fad
|
@ -0,0 +1,28 @@
|
|||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: csr-approver
|
||||
rules:
|
||||
- apiGroups:
|
||||
- certificates.k8s.io
|
||||
resources:
|
||||
- certificatesigningrequests
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- certificates.k8s.io
|
||||
resources:
|
||||
- certificatesigningrequests/approval
|
||||
verbs:
|
||||
- update
|
||||
- apiGroups:
|
||||
- certificates.k8s.io
|
||||
resources:
|
||||
- signers
|
||||
resourceNames:
|
||||
- example.com/my-signer-name # example.com/* can be used to authorize for all signers in the 'example.com' domain
|
||||
verbs:
|
||||
- approve
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: csr-creator
|
||||
rules:
|
||||
- apiGroups:
|
||||
- certificates.k8s.io
|
||||
resources:
|
||||
- certificatesigningrequests
|
||||
verbs:
|
||||
- create
|
||||
- get
|
||||
- list
|
||||
- watch
|
|
@ -0,0 +1,27 @@
|
|||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: csr-signer
|
||||
rules:
|
||||
- apiGroups:
|
||||
- certificates.k8s.io
|
||||
resources:
|
||||
- certificatesigningrequests
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- certificates.k8s.io
|
||||
resources:
|
||||
- certificatesigningrequests/status
|
||||
verbs:
|
||||
- update
|
||||
- apiGroups:
|
||||
- certificates.k8s.io
|
||||
resources:
|
||||
- signers
|
||||
resourceNames:
|
||||
- example.com/my-signer-name # example.com/* can be used to authorize for all signers in the 'example.com' domain
|
||||
verbs:
|
||||
- sign
|
|
@ -0,0 +1,19 @@
|
|||
apiVersion: admissionregistration.k8s.io/v1
|
||||
kind: ValidatingAdmissionPolicy
|
||||
metadata:
|
||||
name: "deploy-replica-policy.example.com"
|
||||
spec:
|
||||
paramKind:
|
||||
apiVersion: rules.example.com/v1
|
||||
kind: ReplicaLimit
|
||||
matchConstraints:
|
||||
resourceRules:
|
||||
- apiGroups: ["apps"]
|
||||
apiVersions: ["v1"]
|
||||
operations: ["CREATE", "UPDATE"]
|
||||
resources: ["deployments"]
|
||||
validations:
|
||||
- expression: "object.spec.replicas <= params.maxReplicas"
|
||||
messageExpression: "'object.spec.replicas must be no greater than ' + string(params.maxReplicas)"
|
||||
reason: Invalid
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
annotations:
|
||||
kubernetes.io/description: |-
|
||||
Add endpoints write permissions to the edit and admin roles. This was
|
||||
removed by default in 1.22 because of CVE-2021-25740. See
|
||||
https://issue.k8s.io/103675. This can allow writers to direct LoadBalancer
|
||||
or Ingress implementations to expose backend IPs that would not otherwise
|
||||
be accessible, and can circumvent network policies or security controls
|
||||
intended to prevent/isolate access to those backends.
|
||||
EndpointSlices were never included in the edit or admin roles, so there
|
||||
is nothing to restore for the EndpointSlice API.
|
||||
labels:
|
||||
rbac.authorization.k8s.io/aggregate-to-edit: "true"
|
||||
name: custom:aggregate-to-edit:endpoints # you can change this if you wish
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
resources: ["endpoints"]
|
||||
verbs: ["create", "delete", "deletecollection", "patch", "update"]
|
|
@ -0,0 +1,28 @@
|
|||
# This policy enforces that all containers of a deployment has the image repo match the environment label of its namespace.
|
||||
# Except for "exempt" deployments, or any containers that do not belong to the "example.com" organization (e.g. common sidecars).
|
||||
# For example, if the namespace has a label of {"environment": "staging"}, all container images must be either staging.example.com/*
|
||||
# or do not contain "example.com" at all, unless the deployment has {"exempt": "true"} label.
|
||||
apiVersion: admissionregistration.k8s.io/v1
|
||||
kind: ValidatingAdmissionPolicy
|
||||
metadata:
|
||||
name: "image-matches-namespace-environment.policy.example.com"
|
||||
spec:
|
||||
failurePolicy: Fail
|
||||
matchConstraints:
|
||||
resourceRules:
|
||||
- apiGroups: ["apps"]
|
||||
apiVersions: ["v1"]
|
||||
operations: ["CREATE", "UPDATE"]
|
||||
resources: ["deployments"]
|
||||
variables:
|
||||
- name: environment
|
||||
expression: "'environment' in namespaceObject.metadata.labels ? namespaceObject.metadata.labels['environment'] : 'prod'"
|
||||
- name: exempt
|
||||
expression: "'exempt' in object.metadata.labels && object.metadata.labels['exempt'] == 'true'"
|
||||
- name: containers
|
||||
expression: "object.spec.template.spec.containers"
|
||||
- name: containersToCheck
|
||||
expression: "variables.containers.filter(c, c.image.contains('example.com/'))"
|
||||
validations:
|
||||
- expression: "variables.exempt || variables.containersToCheck.all(c, c.image.startsWith(variables.environment + '.'))"
|
||||
messageExpression: "'only ' + variables.environment + ' images are allowed in namespace ' + namespaceObject.metadata.name"
|
|
@ -0,0 +1,12 @@
|
|||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
# "namespace" omitted since ClusterRoles are not namespaced
|
||||
name: secret-reader
|
||||
rules:
|
||||
- apiGroups: [""]
|
||||
#
|
||||
# at the HTTP level, the name of the resource for accessing Secret
|
||||
# objects is "secrets"
|
||||
resources: ["secrets"]
|
||||
verbs: ["get", "watch", "list"]
|
|
@ -0,0 +1,13 @@
|
|||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
# This cluster role binding allows anyone in the "manager" group to read secrets in any namespace.
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: read-secrets-global
|
||||
subjects:
|
||||
- kind: Group
|
||||
name: manager # Name is case sensitive
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
roleRef:
|
||||
kind: ClusterRole
|
||||
name: secret-reader
|
||||
apiGroup: rbac.authorization.k8s.io
|
|
@ -0,0 +1,9 @@
|
|||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
namespace: default
|
||||
name: pod-reader
|
||||
rules:
|
||||
- apiGroups: [""] # "" indicates the core API group
|
||||
resources: ["pods"]
|
||||
verbs: ["get", "watch", "list"]
|
|
@ -0,0 +1,18 @@
|
|||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
# This role binding allows "dave" to read secrets in the "development" namespace.
|
||||
# You need to already have a ClusterRole named "secret-reader".
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: read-secrets
|
||||
#
|
||||
# The namespace of the RoleBinding determines where the permissions are granted.
|
||||
# This only grants permissions within the "development" namespace.
|
||||
namespace: development
|
||||
subjects:
|
||||
- kind: User
|
||||
name: dave # Name is case sensitive
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
roleRef:
|
||||
kind: ClusterRole
|
||||
name: secret-reader
|
||||
apiGroup: rbac.authorization.k8s.io
|
|
@ -0,0 +1,17 @@
|
|||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
# This role binding allows "jane" to read pods in the "default" namespace.
|
||||
# You need to already have a Role named "pod-reader" in that namespace.
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: read-pods
|
||||
namespace: default
|
||||
subjects:
|
||||
# You can specify more than one "subject"
|
||||
- kind: User
|
||||
name: jane # "name" is case sensitive
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
roleRef:
|
||||
# "roleRef" specifies the binding to a Role / ClusterRole
|
||||
kind: Role #this must be Role or ClusterRole
|
||||
name: pod-reader # this must match the name of the Role or ClusterRole you wish to bind to
|
||||
apiGroup: rbac.authorization.k8s.io
|
|
@ -0,0 +1,18 @@
|
|||
apiVersion: admissionregistration.k8s.io/v1
|
||||
kind: ValidatingAdmissionPolicy
|
||||
metadata:
|
||||
name: "demo-policy.example.com"
|
||||
spec:
|
||||
failurePolicy: Fail
|
||||
matchConstraints:
|
||||
resourceRules:
|
||||
- apiGroups: ["apps"]
|
||||
apiVersions: ["v1"]
|
||||
operations: ["CREATE", "UPDATE"]
|
||||
resources: ["deployments"]
|
||||
validations:
|
||||
- expression: "object.spec.replicas > 50"
|
||||
messageExpression: "'Deployment spec.replicas set to ' + string(object.spec.replicas)"
|
||||
auditAnnotations:
|
||||
- key: "high-replica-count"
|
||||
valueExpression: "'Deployment spec.replicas set to ' + string(object.spec.replicas)"
|
|
@ -0,0 +1,22 @@
|
|||
apiVersion: admissionregistration.k8s.io/v1
|
||||
kind: ValidatingAdmissionPolicy
|
||||
metadata:
|
||||
name: "demo-policy.example.com"
|
||||
spec:
|
||||
failurePolicy: Fail
|
||||
matchConstraints:
|
||||
resourceRules:
|
||||
- apiGroups: ["*"]
|
||||
apiVersions: ["*"]
|
||||
operations: ["CREATE", "UPDATE"]
|
||||
resources: ["*"]
|
||||
matchConditions:
|
||||
- name: 'exclude-leases' # Each match condition must have a unique name
|
||||
expression: '!(request.resource.group == "coordination.k8s.io" && request.resource.resource == "leases")' # Match non-lease resources.
|
||||
- name: 'exclude-kubelet-requests'
|
||||
expression: '!("system:nodes" in request.userInfo.groups)' # Match requests made by non-node users.
|
||||
- name: 'rbac' # Skip RBAC requests.
|
||||
expression: 'request.resource.group != "rbac.authorization.k8s.io"'
|
||||
validations:
|
||||
- expression: "!object.metadata.name.contains('demo') || object.metadata.namespace == 'demo'"
|
||||
|
Loading…
Reference in New Issue