Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions charts/sourcegraph-executor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<!-- START CHANGELOG -->
## Unreleased

* Added `sourcegraph.runtimeClassName` to the `sourcegraph-executor-k8s` and `sourcegraph-executor-dind` charts, to assign a [RuntimeClass](https://kubernetes.io/docs/concepts/containers/runtime-class/) to their pods, with `executor.runtimeClassName` and `privateDockerRegistry.runtimeClassName` overrides. In the `sourcegraph-executor-dind` chart, either one replaces the `gvisor` default of `dind.gVisor.enabled`.
* Added `executor.kubernetesJob.runtimeClassName` to the `sourcegraph-executor-k8s` chart, to assign a RuntimeClass to job pods (`EXECUTOR_KUBERNETES_RUNTIME_CLASS`), e.g. to run them in a sandbox. Job pods do not inherit `sourcegraph.runtimeClassName`.

## 8.0.0

* Added a `network-policy` example to the `sourcegraph-executor-k8s` and `sourcegraph-executor-dind` charts, with `CiliumNetworkPolicy` resources which limit Executor and job pods to the frontend API.
Expand Down
3 changes: 2 additions & 1 deletion charts/sourcegraph-executor/dind/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ In addition to the documented values, the `executor` and `private-docker-registr
| dind.daemonConfig | object | `{"hosts":["tcp://127.0.0.1:2375"],"insecure-registries":["private-docker-registry:5000"],"mtu":1200,"registry-mirrors":["http://private-docker-registry:5000"],"tls":false}` | Docker daemon configuration passed as daemon.json to the dind sidecar. Learn more from: https://docs.docker.com/reference/cli/dockerd/#on-linux |
| dind.gVisor.command | list | `["/bin/sh","-c","ip link del docker0 2>/dev/null || true\necho 1 > /proc/sys/net/ipv4/ip_forward\ndev=$(ip route show default | awk '{for(i=1;i<=NF;i++) if($i==\"dev\"){print $(i+1); exit}}')\naddr=$(ip addr show dev \"$dev\" | awk '/inet /{gsub(/\\/.*/, \"\", $2); print $2; exit}')\niptables-legacy -t nat -A POSTROUTING -o \"$dev\" -j SNAT --to-source \"$addr\" -p tcp || true\niptables-legacy -t nat -A POSTROUTING -o \"$dev\" -j SNAT --to-source \"$addr\" -p udp || true\nexec dockerd\n"]` | Command for the dind container when gVisor is enabled. Overrides dind.command. Prepares the network environment that gVisor does not initialise automatically before handing off to dockerd. |
| dind.gVisor.daemonConfig | object | `{"features":{"containerd-snapshotter":false},"ip6tables":false,"iptables":false,"storage-driver":"vfs"}` | Extra daemon.json settings merged into dind.daemonConfig when gVisor is enabled. These defaults configure Docker to work within gVisor's kernel constraints. |
| dind.gVisor.enabled | bool | `false` | Enable gVisor sandbox (GKE only). Requires the GKE node pool to have sandbox type set to gvisor. When enabled, sets runtimeClassName: gvisor on executor pods and replaces privileged: true with explicit capabilities — these are intercepted in-sandbox and never granted to the host kernel. See: https://gvisor.dev/docs/tutorials/docker-in-gvisor/ |
| dind.gVisor.enabled | bool | `false` | Enable gVisor sandbox (GKE only). Requires the GKE node pool to have sandbox type set to gvisor. When enabled, sets runtimeClassName: gvisor on executor pods, unless `executor.runtimeClassName` or `sourcegraph.runtimeClassName` is set, and replaces privileged: true with explicit capabilities — these are intercepted in-sandbox and never granted to the host kernel. See: https://gvisor.dev/docs/tutorials/docker-in-gvisor/ |
| dind.gVisor.securityContext | object | `{"capabilities":{"add":["NET_ADMIN","SYS_ADMIN","AUDIT_WRITE","CHOWN","DAC_OVERRIDE","FOWNER","FSETID","KILL","MKNOD","NET_BIND_SERVICE","NET_RAW","SETFCAP","SETGID","SETPCAP","SETUID","SYS_CHROOT","SYS_PTRACE"]}}` | securityContext for the dind container when gVisor is enabled. Replaces privileged: true — gVisor intercepts these capabilities in-sandbox and never grants them to the host kernel. |
| dind.image.registry | string | `"index.docker.io"` | |
| dind.image.repository | string | `"docker"` | |
Expand Down Expand Up @@ -104,6 +104,7 @@ In addition to the documented values, the `executor` and `private-docker-registr
| sourcegraph.podAnnotations | object | `{}` | Add extra annotations to attach to all pods |
| sourcegraph.podLabels | object | `{}` | Add extra labels to attach to all pods |
| sourcegraph.priorityClassName | string | `""` | Assign a priorityClass to all pods (daemonSets, deployments, and statefulSets) |
| sourcegraph.runtimeClassName | string | `""` | Assign a [RuntimeClass](https://kubernetes.io/docs/concepts/containers/runtime-class/) to all pods, e.g. to run them in a sandbox. Override it per service with `<serviceName>.runtimeClassName`; set that to `""` to keep a service on the cluster default runtime |
| sourcegraph.tolerations | list | `[]` | Tolerations, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) |
| storageClass.allowedTopologies | object | `{}` | Persistent volumes topology configuration, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/storage/storage-classes/#allowed-topologies) |
| storageClass.create | bool | `false` | Enable creation of storageClass. Defaults to Google Cloud Platform. Disable if you have your own existing storage class |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Run the executor pod and the private Docker registry in confidential-sandbox
# with EKS Nitro Sandboxes. Use it on top of override.yaml:
# helm upgrade ... -f override.yaml -f override-confidential.yaml
#
# Confidential mode needs a policy for both pods. Generate them as described
# in the sourcegraph chart's
# examples/aws-eks-nitro-sandboxes/override-confidential.yaml
#
# The executor Deployment needs two changes:
# - Before generating, change the executor-scratch volume from "emptyDir:" to
# "emptyDir: {}" in the manifest. With executor.storage.size unset, the
# chart renders it with no value, and the generator then expects a pod with
# no emptyDir volume
# - After generating, remove the dind container's context.mounts condition
# from the policy. Its subPath mount of daemon.json pins a source that does
# not match, so the container is denied at CreateContainer. The executor
# container's condition can stay
#
# The private-docker-registry StatefulSet needs only the volumeClaimTemplates
# step.
#
# Jobs run as Docker containers inside the executor pod's sandbox, so they
# need no policy of their own

sourcegraph:
runtimeClassName: confidential-sandbox

executor:
podAnnotations:
sandbox.amazonaws.com/policy: <policy of the executor Deployment>

privateDockerRegistry:
podAnnotations:
sandbox.amazonaws.com/policy: <policy of the private-docker-registry StatefulSet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Run the executor pod, with its Docker daemon and every job container, in one
# microVM with EKS Nitro Sandboxes, and the private Docker registry in another
# https://docs.aws.amazon.com/eks/latest/userguide/sandboxing.html

sourcegraph:
# The executor pod and the private Docker registry pod
runtimeClassName: isolated-sandbox

# A sandbox defaults to 100 Mbps and 1,500 packets per second each way.
# Raise both; the limits are read once, when the pod is created
podAnnotations:
sandbox.amazonaws.com/ingress-bandwidth: "1G"
sandbox.amazonaws.com/egress-bandwidth: "1G"
sandbox.amazonaws.com/ingress-packets-per-second: "15000"
sandbox.amazonaws.com/egress-packets-per-second: "15000"

executor:
# Jobs run as Docker containers inside the executor pod, so its microVM must
# hold them too. The chart has no resources value for the dind or
# private-docker-registry containers, so size the microVM for the jobs with
# the executor container's requests: vCPUs are the CPU request rounded up,
# and memory is the memory request
resources:
requests:
cpu: "2"
memory: 4G
limits:
memory: 4G
5 changes: 4 additions & 1 deletion charts/sourcegraph-executor/dind/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ spec:
name: docker
{{- end }}
enableServiceLinks: false
{{- if $r.Values.dind.gVisor.enabled }}
{{- $runtimeClassName := include "sourcegraph.runtimeClassName" (list $r "executor") | trim }}
{{- if $runtimeClassName }}
{{- $runtimeClassName | nindent 6 }}
{{- else if $r.Values.dind.gVisor.enabled }}
runtimeClassName: gvisor
{{- end }}
{{- with $r.Values.sourcegraph.nodeSelector }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{/*

Allow customers to assign a runtimeClassName to all resources which create pods (ex. DaemonSets, Deployments, StatefulSets)

Customers can configure an instance-wide default runtime class name at .Values.sourcegraph.runtimeClassName,
and can override it for individual services, if needed, at .Values.<service>.runtimeClassName

Unlike priorityClassName, an empty .Values.<service>.runtimeClassName also overrides the instance-wide default,
so pods which a sandboxed runtime cannot run (ex. hostPID or privileged) can keep the cluster's default runtime

*/}}

{{- define "sourcegraph.runtimeClassName" -}}
{{- $top := index . 0 }}
{{- $service := index . 1 }}
{{- $serviceValues := index $top.Values $service | default dict }}
{{- $runtimeClassName := index $top.Values "sourcegraph" "runtimeClassName" }}
{{- if hasKey $serviceValues "runtimeClassName" }}
{{- $runtimeClassName = index $serviceValues "runtimeClassName" }}
{{- end }}
{{- with $runtimeClassName }}
runtimeClassName: {{ . | toYaml | trim }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with include "sourcegraph.priorityClassName" (list . "privateDockerRegistry") | trim }}{{ . | nindent 6 }}{{- end }}
{{- with include "sourcegraph.runtimeClassName" (list . "privateDockerRegistry") | trim }}{{ . | nindent 6 }}{{- end }}
{{- with .Values.sourcegraph.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
Expand Down
38 changes: 38 additions & 0 deletions charts/sourcegraph-executor/dind/tests/executor_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,41 @@ tests:
apiVersion: apps/v1
name: executor-batches
documentIndex: 1

- it: should not set runtimeClassName by default
template: executor/executor.Deployment.yaml
set:
executor:
queueName: batches
asserts:
- notExists:
path: spec.template.spec.runtimeClassName

- it: should default runtimeClassName to gvisor when gVisor is enabled
template: executor/executor.Deployment.yaml
set:
executor:
queueName: batches
dind:
gVisor:
enabled: true
asserts:
- equal:
path: spec.template.spec.runtimeClassName
value: gvisor

- it: should prefer executor.runtimeClassName over the global one and the gVisor default
template: executor/executor.Deployment.yaml
set:
sourcegraph:
runtimeClassName: global-class
executor:
queueName: batches
runtimeClassName: executor-class
dind:
gVisor:
enabled: true
asserts:
- equal:
path: spec.template.spec.runtimeClassName
value: executor-class
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ tests:
asserts:
- hasDocuments:
count: 0

- it: should fall back to the global runtimeClassName
template: private-docker-registry/private-docker-registry.Statefulset.yaml
set:
sourcegraph:
runtimeClassName: global-class
asserts:
- equal:
path: spec.template.spec.runtimeClassName
value: global-class
6 changes: 5 additions & 1 deletion charts/sourcegraph-executor/dind/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ sourcegraph:
podLabels: {}
# -- Assign a priorityClass to all pods (daemonSets, deployments, and statefulSets)
priorityClassName: ""
# -- Assign a [RuntimeClass](https://kubernetes.io/docs/concepts/containers/runtime-class/) to all pods, e.g. to run them in a sandbox.
# Override it per service with `<serviceName>.runtimeClassName`; set that to `""` to keep a service on the cluster default runtime
runtimeClassName: ""


storageClass:
Expand Down Expand Up @@ -158,7 +161,8 @@ dind:
- private-docker-registry:5000
gVisor:
# -- Enable gVisor sandbox (GKE only). Requires the GKE node pool to have sandbox type set to gvisor.
# When enabled, sets runtimeClassName: gvisor on executor pods and replaces privileged: true with
# When enabled, sets runtimeClassName: gvisor on executor pods, unless `executor.runtimeClassName` or
# `sourcegraph.runtimeClassName` is set, and replaces privileged: true with
# explicit capabilities — these are intercepted in-sandbox and never granted to the host kernel.
# See: https://gvisor.dev/docs/tutorials/docker-in-gvisor/
enabled: false
Expand Down
2 changes: 2 additions & 0 deletions charts/sourcegraph-executor/k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ In addition to the documented values, the `executor` and `private-docker-registr
| executor.kubernetesJob.resources.requests.memory | string | `"1Gi"` | The requested memory for a job. |
| executor.kubernetesJob.runAsGroup | int | `nil`; accepts [0, 2147483647] | The group ID to run Kubernetes jobs as. |
| executor.kubernetesJob.runAsUser | int | `nil`; accepts [0, 2147483647] | The user ID to run Kubernetes jobs as. |
| executor.kubernetesJob.runtimeClassName | string | `""` | The RuntimeClass to set on job pods, e.g. `gvisor`. Job pods do not inherit `sourcegraph.runtimeClassName` |
| executor.log.format | string | `"condensed"` | |
| executor.log.level | string | `"warn"` | Possible values are `dbug`, `info`, `warn`, `eror`, `crit`. |
| executor.log.trace | string | `"false"` | |
Expand Down Expand Up @@ -117,4 +118,5 @@ In addition to the documented values, the `executor` and `private-docker-registr
| sourcegraph.podAnnotations | object | `{}` | Add extra annotations to attach to all pods |
| sourcegraph.podLabels | object | `{}` | Add extra labels to attach to all pods |
| sourcegraph.priorityClassName | string | `""` | Assign a priorityClass to all pods (daemonSets, deployments, and statefulSets) |
| sourcegraph.runtimeClassName | string | `""` | Assign a [RuntimeClass](https://kubernetes.io/docs/concepts/containers/runtime-class/) to all pods, e.g. to run them in a sandbox. Override it per service with `<serviceName>.runtimeClassName`; set that to `""` to keep a service on the cluster default runtime |
| sourcegraph.tolerations | list | `[]` | Tolerations, learn more from the [Kubernetes documentation](https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Run the executor and each job pod in confidential-sandbox with EKS Nitro
# Sandboxes. Use it on top of override.yaml:
# helm upgrade ... -f override.yaml -f override-confidential.yaml
#
# Confidential mode needs a policy for every pod. Generate them as described
# in the sourcegraph chart's
# examples/aws-eks-nitro-sandboxes/override-confidential.yaml
#
# Make the job pods' policy first: it is part of the executor's env, which the
# executor's own policy pins. The executor's policy needed no edit.
#
# Job pods have no manifest to generate a policy from, and they all get the
# same annotations, so one policy has to allow every job you run:
# 1. Run one job of each kind, and save its pod with `kubectl get pod -o yaml`
# while it exists. The pod fails to start until its policy allows it, and
# that pod is enough. Remove what the API server added: status, the uid,
# resourceVersion, and ownerReferences, nodeName, overhead, tolerations,
# priority, and the kube-api-access volume with its mounts
# 2. Generate a policy from each saved pod, with these flags added, because
# args, env, and hostname differ on every job:
# --no-pin-args --no-pin-env --no-pin-hostname
# 3. Merge the policies into one. Decode each to its envelope, append the
# admission_policy and runtime_policy text of the others to the first, and
# encode the result. A pod is allowed when any one permit matches
#
# A job policy still pins the container names, image digests, working
# directories, and mounts. Each number of batch spec steps, each step image,
# and each indexer needs its own permits: a batch spec with two steps was
# denied by a policy made from a batch spec with one

sourcegraph:
# The executor pod
runtimeClassName: confidential-sandbox

executor:
podAnnotations:
sandbox.amazonaws.com/policy: <policy of the executor Deployment>

kubernetesJob:
runtimeClassName: confidential-sandbox

# Replaces the list in override.yaml
extraEnv:
- name: KUBERNETES_JOB_POD_ANNOTATIONS
value: '{"sandbox.amazonaws.com/ingress-bandwidth": "1G", "sandbox.amazonaws.com/egress-bandwidth": "1G", "sandbox.amazonaws.com/ingress-packets-per-second": "15000", "sandbox.amazonaws.com/egress-packets-per-second": "15000", "sandbox.amazonaws.com/policy": "<merged policy of the job pods>"}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Run the executor and each job pod in its own microVM with EKS Nitro Sandboxes
# https://docs.aws.amazon.com/eks/latest/userguide/sandboxing.html

sourcegraph:
# The executor pod
runtimeClassName: isolated-sandbox

# A sandbox defaults to 100 Mbps and 1,500 packets per second each way.
# Raise both; the limits are read once, when the pod is created
podAnnotations:
sandbox.amazonaws.com/ingress-bandwidth: "1G"
sandbox.amazonaws.com/egress-bandwidth: "1G"
sandbox.amazonaws.com/ingress-packets-per-second: "15000"
sandbox.amazonaws.com/egress-packets-per-second: "15000"

executor:
# This chart reads the Secret named executor-<queueName>, or
# executor-<queueNames joined with "-">, whatever name is set here; setting
# it only stops the chart from creating that Secret. Create it under that
# name, with the key EXECUTOR_FRONTEND_PASSWORD
# frontendExistingSecret: executor-batches-codeintel
# queueNames: [batches, codeintel]

# Job pods do not inherit sourcegraph.runtimeClassName or sourcegraph.podAnnotations
kubernetesJob:
runtimeClassName: isolated-sandbox

# The requests size the job's microVM: vCPUs are the CPU request rounded up,
# and memory is the memory request. A job is OOM-killed once it uses more
# than the memory request, so request as much memory as the limit
resources:
requests:
cpu: "1"
memory: 2Gi
limits:
memory: 2Gi

# The chart has no value for job pod annotations
extraEnv:
- name: KUBERNETES_JOB_POD_ANNOTATIONS
value: '{"sandbox.amazonaws.com/ingress-bandwidth": "1G", "sandbox.amazonaws.com/egress-bandwidth": "1G", "sandbox.amazonaws.com/ingress-packets-per-second": "15000", "sandbox.amazonaws.com/egress-packets-per-second": "15000"}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{/*

Allow customers to assign a runtimeClassName to all resources which create pods (ex. DaemonSets, Deployments, StatefulSets)

Customers can configure an instance-wide default runtime class name at .Values.sourcegraph.runtimeClassName,
and can override it for individual services, if needed, at .Values.<service>.runtimeClassName

Unlike priorityClassName, an empty .Values.<service>.runtimeClassName also overrides the instance-wide default,
so pods which a sandboxed runtime cannot run (ex. hostPID or privileged) can keep the cluster's default runtime

*/}}

{{- define "sourcegraph.runtimeClassName" -}}
{{- $top := index . 0 }}
{{- $service := index . 1 }}
{{- $serviceValues := index $top.Values $service | default dict }}
{{- $runtimeClassName := index $top.Values "sourcegraph" "runtimeClassName" }}
{{- if hasKey $serviceValues "runtimeClassName" }}
{{- $runtimeClassName = index $serviceValues "runtimeClassName" }}
{{- end }}
{{- with $runtimeClassName }}
runtimeClassName: {{ . | toYaml | trim }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ data:
KUBERNETES_RUN_AS_USER: "{{ .Values.executor.kubernetesJob.runAsUser }}"
KUBERNETES_RUN_AS_GROUP: "{{ .Values.executor.kubernetesJob.runAsGroup }}"
KUBERNETES_FS_GROUP: "{{ .Values.executor.kubernetesJob.fsGroup }}"
EXECUTOR_KUBERNETES_RUNTIME_CLASS: "{{ .Values.executor.kubernetesJob.runtimeClassName }}"

EXECUTOR_DOCKER_ADD_HOST_GATEWAY: "{{.Values.executor.dockerAddHostGateway }}"
KUBERNETES_KEEP_JOBS: "{{ .Values.executor.debug.keepJobs }}"
Expand Down
Loading
Loading