fix: container hardening + NetworkPolicy for waitlist-api
- deployment.yaml: securityContext (runAsNonRoot, readOnlyRootFilesystem, drop ALL caps) - network-policy.yaml: egress only to CNPG PG (5432) + api.telegram.org (443) - kustomization.yaml: register new NetworkPolicy resource - waitlist-telegram-secret: add admin_api_key field
This commit is contained in:
parent
36b1d637f1
commit
ac994f144a
4 changed files with 72 additions and 0 deletions
|
|
@ -13,6 +13,12 @@ spec:
|
||||||
labels:
|
labels:
|
||||||
app: waitlist-api
|
app: waitlist-api
|
||||||
spec:
|
spec:
|
||||||
|
serviceAccountName: waitlist-api
|
||||||
|
securityContext:
|
||||||
|
runAsNonRoot: true
|
||||||
|
runAsUser: 1000
|
||||||
|
runAsGroup: 1000
|
||||||
|
fsGroup: 1000
|
||||||
containers:
|
containers:
|
||||||
- name: api
|
- name: api
|
||||||
image: ghcr.io/sirius0xdev/waitlist-api:latest
|
image: ghcr.io/sirius0xdev/waitlist-api:latest
|
||||||
|
|
@ -20,6 +26,12 @@ spec:
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8080
|
- containerPort: 8080
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
|
securityContext:
|
||||||
|
readOnlyRootFilesystem: true
|
||||||
|
allowPrivilegeEscalation: false
|
||||||
|
capabilities:
|
||||||
|
drop:
|
||||||
|
- ALL
|
||||||
env:
|
env:
|
||||||
- name: DB_HOST
|
- name: DB_HOST
|
||||||
value: "siriusdevops-pgdb-rw.customer1.svc.cluster.local"
|
value: "siriusdevops-pgdb-rw.customer1.svc.cluster.local"
|
||||||
|
|
@ -47,6 +59,11 @@ spec:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: waitlist-telegram-secret
|
name: waitlist-telegram-secret
|
||||||
key: chat_id
|
key: chat_id
|
||||||
|
- name: ADMIN_API_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: waitlist-telegram-secret
|
||||||
|
key: admin_api_key
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
cpu: 50m
|
cpu: 50m
|
||||||
|
|
@ -55,6 +72,11 @@ spec:
|
||||||
cpu: 200m
|
cpu: 200m
|
||||||
memory: 256Mi
|
memory: 256Mi
|
||||||
|
|
||||||
|
volumeMounts:
|
||||||
|
- name: tmp
|
||||||
|
mountPath: /tmp
|
||||||
|
readOnly: false
|
||||||
|
|
||||||
startupProbe:
|
startupProbe:
|
||||||
httpGet:
|
httpGet:
|
||||||
path: /healthz
|
path: /healthz
|
||||||
|
|
@ -88,6 +110,10 @@ spec:
|
||||||
failureThreshold: 3
|
failureThreshold: 3
|
||||||
successThreshold: 1
|
successThreshold: 1
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: tmp
|
||||||
|
emptyDir: {}
|
||||||
|
|
||||||
---
|
---
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,4 @@ resources:
|
||||||
- deployment.yaml
|
- deployment.yaml
|
||||||
- waitlist-telegram-secret.yaml
|
- waitlist-telegram-secret.yaml
|
||||||
- http-route.yaml
|
- http-route.yaml
|
||||||
|
- network-policy.yaml
|
||||||
|
|
|
||||||
44
apps/base/customer1/waitlist-api/network-policy.yaml
Normal file
44
apps/base/customer1/waitlist-api/network-policy.yaml
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: NetworkPolicy
|
||||||
|
metadata:
|
||||||
|
name: waitlist-api-egress
|
||||||
|
namespace: customer1
|
||||||
|
spec:
|
||||||
|
podSelector:
|
||||||
|
matchLabels:
|
||||||
|
app: waitlist-api
|
||||||
|
policyTypes:
|
||||||
|
- Egress
|
||||||
|
egress:
|
||||||
|
# Allow DNS resolution (required for api.telegram.org lookups)
|
||||||
|
- to:
|
||||||
|
- namespaceSelector:
|
||||||
|
matchLabels:
|
||||||
|
kubernetes.io/metadata.name: kube-system
|
||||||
|
- podSelector:
|
||||||
|
matchLabels:
|
||||||
|
k8s-app: kube-dns
|
||||||
|
ports:
|
||||||
|
- protocol: UDP
|
||||||
|
port: 53
|
||||||
|
- protocol: TCP
|
||||||
|
port: 53
|
||||||
|
# Allow PostgreSQL to CNPG cluster
|
||||||
|
- to:
|
||||||
|
- podSelector:
|
||||||
|
matchLabels:
|
||||||
|
cnpg.io/cluster: siriusdevops-pgdb
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 5432
|
||||||
|
# Allow Telegram Bot API
|
||||||
|
- to:
|
||||||
|
- ipBlock:
|
||||||
|
cidr: 0.0.0.0/0
|
||||||
|
except:
|
||||||
|
- 10.0.0.0/8
|
||||||
|
- 172.16.0.0/12
|
||||||
|
- 192.168.0.0/16
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 443
|
||||||
|
|
@ -7,6 +7,7 @@ type: Opaque
|
||||||
stringData:
|
stringData:
|
||||||
bot_token: CHANGEME
|
bot_token: CHANGEME
|
||||||
chat_id: CHANGEME
|
chat_id: CHANGEME
|
||||||
|
admin_api_key: CHANGEME
|
||||||
sops:
|
sops:
|
||||||
age:
|
age:
|
||||||
- recipient: age1uuxf066xuuqgvjppxfcmqkwfcufnwp3wcwnl9h20g9k4l8nkw9jsaungf7
|
- recipient: age1uuxf066xuuqgvjppxfcmqkwfcufnwp3wcwnl9h20g9k4l8nkw9jsaungf7
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue