Skip to content

Commit

Permalink
feat(manifests): add securityContext to deployments
Browse files Browse the repository at this point in the history
Set `seccompProfile`, forbid containers to run as root, and disable
unnecessary system calls. This applies to:

- Model registry itself
- Example database (MySQL and PostgreSQL)
- Model registry UI

Signed-off-by: Paul Boyd <[email protected]>
  • Loading branch information
pboyd committed Feb 6, 2025
1 parent 5cbf43c commit 021a0b8
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
16 changes: 16 additions & 0 deletions manifests/kustomize/base/model-registry-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ spec:
labels:
component: model-registry-server
spec:
securityContext:
seccompProfile:
type: RuntimeDefault
runAsNonRoot: true
containers:
- name: rest-container
args:
Expand Down Expand Up @@ -44,6 +48,11 @@ spec:
tcpSocket:
port: http-api
timeoutSeconds: 2
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
- name: grpc-container
# ! Sync to the same MLMD version:
# * backend/metadata_writer/requirements.in and requirements.txt
Expand Down Expand Up @@ -102,4 +111,11 @@ spec:
initialDelaySeconds: 3
periodSeconds: 5
timeoutSeconds: 2
securityContext:
runAsUser: 70
runAsGroup: 70
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
serviceAccountName: model-registry-server
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ spec:
app: model-registry-ui
spec:
serviceAccountName: model-registry-ui
securityContext:
seccompProfile:
type: RuntimeDefault
runAsNonRoot: true
containers:
- name: model-registry-ui
image: model-registry-ui-image
Expand Down Expand Up @@ -51,3 +55,8 @@ spec:
- containerPort: 8080
args:
- "--port=8080"
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: kubeflow

resources:
- ../../base
Expand Down
11 changes: 11 additions & 0 deletions manifests/kustomize/overlays/db/model-registry-db-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ spec:
annotations:
sidecar.istio.io/inject: "false"
spec:
securityContext:
seccompProfile:
type: RuntimeDefault
runAsNonRoot: true
containers:
- name: db-container
image: mysql:8.3.0
Expand Down Expand Up @@ -46,6 +50,13 @@ spec:
volumeMounts:
- name: metadata-mysql
mountPath: /var/lib/mysql
securityContext:
runAsUser: 999
runAsGroup: 999
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumes:
- name: metadata-mysql
persistentVolumeClaim:
Expand Down
2 changes: 1 addition & 1 deletion manifests/kustomize/overlays/postgres/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ vars:
- name: POSTGRES_PORT
objref:
kind: ConfigMap
name: model-registry-db-parameters
name: metadata-postgres-db-parameters
apiVersion: v1
fieldref:
fieldpath: data.POSTGRES_PORT
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ spec:
annotations:
sidecar.istio.io/inject: "false"
spec:
securityContext:
seccompProfile:
type: RuntimeDefault
runAsNonRoot: true
containers:
- name: db-container
image: postgres
Expand All @@ -36,8 +40,14 @@ spec:
volumeMounts:
- name: metadata-postgres
mountPath: /var/lib/postgresql/data
securityContext:
runAsUser: 70
runAsGroup: 70
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
volumes:
- name: metadata-postgres
persistentVolumeClaim:
claimName: metadata-postgres

0 comments on commit 021a0b8

Please sign in to comment.