Skip to content

Commit

Permalink
feat: misc security improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
reevejd committed Dec 16, 2023
1 parent 9420237 commit 9e0ffef
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ RUN CGO_ENABLED=0 go build -o webhook -ldflags '-w -extldflags "-static"' .

FROM alpine:3.18 as final

RUN addgroup -g 1000 appgroup && adduser -u 1000 -G appgroup -D webhook

RUN apk add --no-cache ca-certificates

USER 1000

COPY --from=build /workspace/webhook /usr/local/bin/webhook

ENTRYPOINT ["webhook"]
2 changes: 1 addition & 1 deletion deploy/cert-manager-ibm-cis-webhook/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: cert-manager-ibm-cis-webhook
version: 1.0.0
version: 1.1.0
19 changes: 17 additions & 2 deletions deploy/cert-manager-ibm-cis-webhook/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ spec:
labels:
app: {{ include "cert-manager-ibm-cis-webhook.name" . }}
release: {{ .Release.Name }}
annotations:
checksum/secrets: {{ include (print $.Template.BasePath "/secret.yaml") $ | sha256sum }}

spec:
securityContext:
runAsNonRoot: true
serviceAccountName: {{ include "cert-manager-ibm-cis-webhook.fullname" . }}
imagePullSecrets:
{{- range .Values.imagePullSecrets }}
Expand All @@ -30,16 +35,20 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- --secure-port={{ .Values.containerPort }}
- --tls-cert-file=/tls/tls.crt
- --tls-private-key-file=/tls/tls.key
env:
- name: GROUP_NAME
value: {{ .Values.groupName | quote }}
- name: IBMCLOUD_API_KEY
value: {{ .Values.ibmCloudApiKey | quote }}
valueFrom:
secretKeyRef:
name: {{ include "cert-manager-ibm-cis-webhook.fullname" . }}-ibmcis-credentials
key: api-token
ports:
- name: https
containerPort: 443
containerPort: {{ .Values.containerPort }}
protocol: TCP
livenessProbe:
httpGet:
Expand All @@ -51,6 +60,12 @@ spec:
scheme: HTTPS
path: /healthz
port: https
securityContext:
runAsNonRoot: true
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
volumeMounts:
- name: certs
mountPath: /tls
Expand Down
52 changes: 52 additions & 0 deletions deploy/cert-manager-ibm-cis-webhook/templates/networkpolicies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{- if .Values.networkPolicies.enabled }}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "cert-manager-ibm-cis-webhook.fullname" . }}-allow-dns
spec:
podSelector:
matchLabels:
app: {{ include "cert-manager-ibm-cis-webhook.name" . }}
policyTypes:
- Egress
egress:
- to:
- namespaceSelector: {}
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- protocol: UDP
port: 53
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: {{ include "cert-manager-ibm-cis-webhook.fullname" . }}-allow-ingress
spec:
podSelector:
matchLabels:
app: {{ include "cert-manager-ibm-cis-webhook.name" . }}
policyTypes:
- Ingress
ingress:
- from:
- podSelector: {}
ports:
- protocol: TCP
port: {{ .Values.containerPort }}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-egress-to-k8s-api
spec:
podSelector:
matchLabels:
app: {{ include "cert-manager-ibm-cis-webhook.name" . }}
policyTypes:
- Egress
egress:
- {}
{{- end }}
2 changes: 1 addition & 1 deletion deploy/cert-manager-ibm-cis-webhook/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: ibmcis-credentials
name: {{ include "cert-manager-ibm-cis-webhook.fullname" . }}-ibmcis-credentials
type: Opaque
stringData:
api-token: {{ .Values.ibmCloudApiKey | quote }}
5 changes: 5 additions & 0 deletions deploy/cert-manager-ibm-cis-webhook/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ groupName: acme.skills.network

ibmCloudApiKey: ""

networkPolicies:
enabled: false

certManager:
namespace: cert-manager
serviceAccountName: cert-manager
Expand All @@ -25,6 +28,8 @@ imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

containerPort: 8443

service:
type: ClusterIP
port: 443
Expand Down

0 comments on commit 9e0ffef

Please sign in to comment.