Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: psp with rbac #5

Open
wants to merge 1 commit into
base: trivy-ci
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
feat: psp with rbac
  • Loading branch information
IronCore864 committed Nov 28, 2021
commit 6ddb4a16944bdaaedd98ec134de9753405755f8f
5 changes: 1 addition & 4 deletions deploy.yaml
Expand Up @@ -18,12 +18,9 @@ spec:
spec:
containers:
- name: hello
image: ironcore864/k8s-security-demo:pod-as-non-root
image: ironcore864/k8s-security-demo:pod-as-root
ports:
- containerPort: 8080
securityContext:
runAsNonRoot: True
readOnlyRootFilesystem: True
---
kind: Service
apiVersion: v1
Expand Down
22 changes: 22 additions & 0 deletions psp.yaml
@@ -0,0 +1,22 @@
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: restricted
annotations:
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default'
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default'
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default'
spec:
privileged: false
seLinux:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
volumes:
- '*'
runAsUser:
# Require the container to run without root privileges.
rule: 'MustRunAsNonRoot'
fsGroup:
rule: RunAsAny
readOnlyRootFilesystem: false
44 changes: 44 additions & 0 deletions rbac.yaml
@@ -0,0 +1,44 @@
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: fake-user
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: fake-editor
namespace: default
subjects:
- kind: ServiceAccount
name: fake-user
namespace: default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: edit
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: psp:unprivileged
rules:
- apiGroups: ['policy']
resources: ['podsecuritypolicies']
verbs: ['use']
resourceNames:
- restricted
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: fake-user:psp:unprivileged
roleRef:
kind: ClusterRole
name: psp:unprivileged
apiGroup: rbac.authorization.k8s.io
subjects:
# Authorize specific service accounts (not recommended):
- kind: ServiceAccount
name: fake-user
namespace: default