Skip to content

Commit

Permalink
Merge pull request #52 from slickwarren/cwarren/hardened-example
Browse files Browse the repository at this point in the history
adding example for hardened linux clusters based on 'simple' example
  • Loading branch information
manno authored Nov 27, 2024
2 parents 49b4721 + 41a9218 commit dcf4917
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 0 deletions.
16 changes: 16 additions & 0 deletions hardened/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Hardened Example

This example will deploy the [Kubernetes sample guestbook](https://github.com/kubernetes/examples/tree/master/guestbook/) application, with modifications to securityContext which allow its deployment on a hardened cluster.
The app will be deployed into the `default` namespace. Note that you must have added the `default` namespace to the PSA to allow deployments to this namespace.

```yaml
kind: GitRepo
apiVersion: fleet.cattle.io/v1alpha1
metadata:
name: simple
namespace: fleet-local
spec:
repo: https://github.com/rancher/fleet-examples
paths:
- hardened
```
4 changes: 4 additions & 0 deletions hardened/fleet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace: hardened-fleet-deployments

namespaceLabels:
pod-security.kubernetes.io/enforce: baseline
33 changes: 33 additions & 0 deletions hardened/frontend-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
selector:
matchLabels:
app: guestbook
tier: frontend
replicas: 3
template:
metadata:
labels:
app: guestbook
tier: frontend
spec:
containers:
- name: php-redis
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
capabilities:
drop: ["ALL"]
image: us-docker.pkg.dev/google-samples/containers/gke/gb-frontend:v5
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 80
14 changes: 14 additions & 0 deletions hardened/frontend-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
type: NodePort
ports:
- port: 80
selector:
app: guestbook
tier: frontend
35 changes: 35 additions & 0 deletions hardened/redis-master-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-master
spec:
selector:
matchLabels:
app: redis
role: master
tier: backend
replicas: 1
template:
metadata:
labels:
app: redis
role: master
tier: backend
spec:
containers:
- name: master
image: redis:7-alpine
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
capabilities:
drop: ["ALL"]
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 6379
16 changes: 16 additions & 0 deletions hardened/redis-master-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: redis-master
labels:
app: redis
role: master
tier: backend
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
role: master
tier: backend
35 changes: 35 additions & 0 deletions hardened/redis-slave-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-slave
spec:
selector:
matchLabels:
app: redis
role: slave
tier: backend
replicas: 2
template:
metadata:
labels:
app: redis
role: slave
tier: backend
spec:
containers:
- name: slave
image: redis:7-alpine
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
capabilities:
drop: ["ALL"]
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 6379
15 changes: 15 additions & 0 deletions hardened/redis-slave-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: redis-slave
labels:
app: redis
role: slave
tier: backend
spec:
ports:
- port: 6379
selector:
app: redis
role: slave
tier: backend

0 comments on commit dcf4917

Please sign in to comment.