Skip to content

Instantly share code, notes, and snippets.

@yaroslavya
Forked from tallclair/git-repo-demo.yaml
Created November 11, 2019 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaroslavya/288aa32071713d5b285f5f060141a90c to your computer and use it in GitHub Desktop.
Save yaroslavya/288aa32071713d5b285f5f060141a90c to your computer and use it in GitHub Desktop.
More secure GitRepo volumes
# Example of using an InitContainer in place of a GitRepo volume.
# Unilke GitRepo volumes, this approach runs the git command in a container,
# with the associated hardening.
apiVersion: v1
kind: Pod
metadata:
name: git-repo-demo
annotations:
seccomp.security.alpha.kubernetes.io/pod: 'docker/default'
spec:
initContainers:
# This container clones the desired git repo to the EmptyDir volume.
- name: git-clone
image: alpine/git # Any image with git will do
args:
- clone
- --single-branch
- --
- https://github.com/kubernetes/kubernetes # Your repo
- /repo # Put it in the volume
securityContext:
runAsUser: 1 # Any non-root user will do. Match to the workload.
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
volumeMounts:
- name: git-repo
mountPath: /repo
containers:
# Replace with your actual workload.
- name: busybox
image: busybox
args: ['sleep', '100000'] # Do nothing
volumeMounts:
- name: git-repo
mountPath: /repo
volumes:
- name: git-repo
emptyDir: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment