diff --git a/CHANGELOG.md b/CHANGELOG.md index 06e4ace..a37494d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- `runtimeClassName` and `automountServiceAccountToken` on the pod spec +- `networkPolicy.egress`: egress rules; non-empty adds `Egress` to `policyTypes` - `checksum/env` and `checksum/secret-env` pod template annotations, so changes to `env` or `secretEnv` roll the pods - `checksum/cf-path-filter` pod template annotation, so changes to the Cloudflare Tunnel `pathFilter` nginx config roll the pods diff --git a/Chart.yaml b/Chart.yaml index 1b66ab2..013f00b 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -17,8 +17,8 @@ keywords: - infisical - secrets type: application -version: 1.10.1 -appVersion: "1.10.1" +version: 1.11.0 +appVersion: "1.11.0" maintainers: - name: Artem Yakimenko email: helm@temik.me diff --git a/README.md b/README.md index 508f11d..a5a179a 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,9 @@ All configuration is done through `values.yaml`. See the file for full documenta | `autoscaling.enabled` | Enable HorizontalPodAutoscaler (`autoscaling/v2`) | `false` | | `hostNetwork.enabled` | Enable host networking | `false` | | `strategy` | Rollout strategy (`RollingUpdate`/`Recreate` for Deployment; `RollingUpdate`/`OnDelete` for StatefulSet) | `{}` | -| `networkPolicy.enabled` | Create a NetworkPolicy restricting ingress traffic | `false` | +| `networkPolicy.enabled` | Create a NetworkPolicy restricting ingress traffic (and egress, with `networkPolicy.egress`) | `false` | +| `runtimeClassName` | Pod RuntimeClass, e.g. `gvisor` | `""` | +| `automountServiceAccountToken` | Set `false` to keep the API token out of the pod; `null` keeps the Kubernetes default | `null` | | `extraServices` | Additional multi-port Service resources alongside port-derived services | `[]` | | `env` / `secretEnv` | Environment variables rendered into a ConfigMap / a Secret | `{}` | | `envFrom` | Extra `secretRef`/`configMapRef` entries for the main container | `[]` | @@ -253,6 +255,30 @@ networkPolicy: kubernetes.io/metadata.name: monitoring ``` +`egress` is empty by default, which leaves egress unrestricted. Any rule adds +`Egress` to `policyTypes`, so traffic it doesn't list is denied, DNS included. +For example, DNS plus the public internet only: + +```yaml +networkPolicy: + enabled: true + egress: + - to: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: kube-system + podSelector: + matchLabels: + k8s-app: kube-dns + ports: + - { port: 53, protocol: UDP } + - { port: 53, protocol: TCP } + - to: + - ipBlock: + cidr: 0.0.0.0/0 + except: [10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 100.64.0.0/10, 169.254.0.0/16] +``` + ### Extra Services (`extraServices`) Create additional Service resources with custom port mappings (e.g. for UDP discovery protocols or mixed-type services). diff --git a/ci/statefulset-values.yaml b/ci/statefulset-values.yaml index ced4b66..4d6c84a 100644 --- a/ci/statefulset-values.yaml +++ b/ci/statefulset-values.yaml @@ -24,3 +24,13 @@ volumes: type: File containerPath: path: /etc/localtime +runtimeClassName: gvisor +automountServiceAccountToken: false +networkPolicy: + enabled: true + egress: + - to: + - ipBlock: + cidr: 0.0.0.0/0 + except: + - 10.0.0.0/8 diff --git a/templates/_helpers/_network_policy.tpl b/templates/_helpers/_network_policy.tpl index ed6cc21..dbf2611 100644 --- a/templates/_helpers/_network_policy.tpl +++ b/templates/_helpers/_network_policy.tpl @@ -1,6 +1,7 @@ {{/* NetworkPolicy template -Restricts ingress traffic to the pod based on configured rules. +Restricts ingress traffic to the pod based on configured rules, and egress +too when egress rules are given. */}} {{- define "hwl.networkPolicy" -}} {{- $np := .Values.networkPolicy -}} @@ -16,6 +17,11 @@ spec: {{- include "hwl.selectorLabels" . | nindent 6 }} policyTypes: - Ingress +{{- with $np.egress }} + - Egress + egress: + {{- toYaml . | nindent 4 }} +{{- end }} {{- if $np.ingress }} ingress: {{- range $np.ingress }} diff --git a/templates/_helpers/_pod.tpl b/templates/_helpers/_pod.tpl index c3e8189..f88e54f 100644 --- a/templates/_helpers/_pod.tpl +++ b/templates/_helpers/_pod.tpl @@ -7,6 +7,12 @@ imagePullSecrets: {{- toYaml . | nindent 2 }} {{- end -}} serviceAccountName: {{ include "hwl.serviceAccountName" . }} +{{- if not (kindIs "invalid" .Values.automountServiceAccountToken) }} +automountServiceAccountToken: {{ .Values.automountServiceAccountToken }} +{{- end }} +{{- with .Values.runtimeClassName }} +runtimeClassName: {{ . }} +{{- end }} {{- if (.Values.shareProcessNamespace) }} shareProcessNamespace: true {{- end }} diff --git a/tests/deployment_test.yaml b/tests/deployment_test.yaml index a78ddd3..952ee3f 100644 --- a/tests/deployment_test.yaml +++ b/tests/deployment_test.yaml @@ -165,3 +165,20 @@ tests: - equal: path: spec.template.spec.containers[0].volumeMounts[0].readOnly value: true + - it: should leave runtimeClassName and automountServiceAccountToken unset by default + asserts: + - notExists: + path: spec.template.spec.runtimeClassName + - notExists: + path: spec.template.spec.automountServiceAccountToken + - it: should set runtimeClassName and disable the service account token + set: + runtimeClassName: gvisor + automountServiceAccountToken: false + asserts: + - equal: + path: spec.template.spec.runtimeClassName + value: gvisor + - equal: + path: spec.template.spec.automountServiceAccountToken + value: false diff --git a/tests/network_policy_test.yaml b/tests/network_policy_test.yaml index 3996981..ef6e90f 100644 --- a/tests/network_policy_test.yaml +++ b/tests/network_policy_test.yaml @@ -186,3 +186,49 @@ tests: - equal: path: spec.ingress[0].ports[0].port value: 443 + + - it: should leave egress unrestricted by default + set: + networkPolicy: + enabled: true + asserts: + - equal: + path: spec.policyTypes + value: + - Ingress + - notExists: + path: spec.egress + + - it: should restrict egress to the given rules + set: + networkPolicy: + enabled: true + allowPortsIngress: false + egress: + - to: + - ipBlock: + cidr: 0.0.0.0/0 + except: + - 10.0.0.0/8 + ports: + - port: 443 + protocol: TCP + asserts: + - equal: + path: spec.policyTypes + value: + - Ingress + - Egress + - equal: + path: spec.egress + value: + - to: + - ipBlock: + cidr: 0.0.0.0/0 + except: + - 10.0.0.0/8 + ports: + - port: 443 + protocol: TCP + - isEmpty: + path: spec.ingress diff --git a/values.schema.json b/values.schema.json index fa68fc3..9675f0f 100644 --- a/values.schema.json +++ b/values.schema.json @@ -514,9 +514,19 @@ } } }, + "runtimeClassName": { + "type": "string", + "default": "", + "description": "Pod RuntimeClass, e.g. gvisor. Empty uses the node default." + }, + "automountServiceAccountToken": { + "type": ["boolean", "null"], + "default": null, + "description": "Set false to keep the API token out of the pod. Null leaves the Kubernetes default." + }, "networkPolicy": { "type": "object", - "description": "NetworkPolicy configuration for restricting ingress traffic to the pod", + "description": "NetworkPolicy configuration for restricting ingress and, optionally, egress traffic of the pod", "properties": { "enabled": { "type": "boolean", @@ -589,6 +599,18 @@ } } } + }, + "egress": { + "type": "array", + "default": [], + "description": "Egress rules (NetworkPolicy spec.egress). Empty leaves egress unrestricted; non-empty adds Egress to policyTypes and denies everything else.", + "items": { + "type": "object", + "properties": { + "ports": { "type": "array", "items": { "type": "object" } }, + "to": { "type": "array", "items": { "type": "object" } } + } + } } } }, diff --git a/values.yaml b/values.yaml index f9032e7..7479b71 100644 --- a/values.yaml +++ b/values.yaml @@ -185,6 +185,12 @@ health: hostNetwork: enabled: false +# Pod RuntimeClass, e.g. "gvisor". Empty uses the node default. +runtimeClassName: "" + +# Set false to keep the API token out of the pod. Null leaves the Kubernetes default. +automountServiceAccountToken: null + networkPolicy: enabled: false # Automatically allow ingress on all ports defined in .Values.ports from anywhere. @@ -202,6 +208,13 @@ networkPolicy: # - podSelector: # matchLabels: # app: frontend + # Egress rules, rendered as spec.egress. Empty leaves egress unrestricted; + # non-empty adds Egress to policyTypes, so anything not listed is denied. + egress: [] + # - to: + # - ipBlock: + # cidr: 0.0.0.0/0 + # except: [10.0.0.0/8] addons: init: