From 6ee5acb399c6c5dca5ee29e3c17cbe1c0be332f8 Mon Sep 17 00:00:00 2001 From: Cameron Attard Date: Mon, 23 Nov 2026 14:14:27 +1100 Subject: [PATCH] [feat] Use initImage for the AppArmor wait and installer containers The wait-for-apparmor init containers on the code executor and JS executor hardcoded busybox from Docker Hub, and the AppArmor installer DaemonSet defaulted to an unpinned busybox:1.37, so installs that mirror every image couldn't run them. Both now use initImage (codeExecutor.appArmorInstallerImage still overrides the DaemonSet). Defaults render the same pinned busybox. The installer DaemonSet also gets image.pullSecrets, like the executors, so an initImage in a registry that needs credentials can be pulled on every node. --- .github/test_apparmor_images.py | 88 +++++++++++++++++++ .github/workflows/ci.yaml | 2 + charts/retool/Chart.yaml | 2 +- .../templates/apparmor_nsjail_daemonset.yaml | 8 +- .../templates/deployment_code_executor.yaml | 2 +- .../templates/deployment_js_executor.yaml | 2 +- charts/retool/values.yaml | 6 +- values.yaml | 6 +- 8 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 .github/test_apparmor_images.py diff --git a/.github/test_apparmor_images.py b/.github/test_apparmor_images.py new file mode 100644 index 00000000..6ef357b9 --- /dev/null +++ b/.github/test_apparmor_images.py @@ -0,0 +1,88 @@ +"""Check that every AppArmor-related container honours the initImage override. + +The wait-for-apparmor init containers on the code executor and JS executor, +and the AppArmor profile installer DaemonSet, used to hardcode busybox from +Docker Hub, so installs that mirror every image (private registries, +air-gapped clusters, GCP Marketplace) couldn't run them. +""" + +import subprocess +import unittest +from pathlib import Path + + +ROOT = Path(__file__).resolve().parents[1] +PINNED = "busybox:1.37.0@sha256:b3255e7dfbcd10cb367af0d409747d511aeb66dfac98cf30e97e87e4207dd76f" + + +def render(*settings): + command = [ + "helm", "template", "aa", "charts/retool", + "--values", "charts/retool/ci/test-install-values.yaml", + "--set", "workflows.enabled=true", + "--set", "codeExecutor.useSeccompProfile=true", + "--set", "codeExecutor.appArmorProfileInstaller=cos", + "--set", "rr.enabled=true", + "--set", "rr.gitServer.skipBlobStorageValidation=true", + "--set", "rr.agentSandbox.externalSecret.name=sandbox-keys", + ] + for setting in settings: + command.extend(("--set", setting)) + return subprocess.check_output(command, cwd=ROOT, text=True) + + +def images(output, source, container=None): + found = [] + for document in output.split("\n---\n"): + if f"# Source: retool/templates/{source}" not in document[:200]: + continue + lines = document.splitlines() + for i, line in enumerate(lines): + if container and line.strip() == f"- name: {container}": + found.append(lines[i + 1].split("image:", 1)[1].strip()) + elif not container and line.strip().startswith("image:"): + found.append(line.split("image:", 1)[1].strip()) + return found + + +class AppArmorImagesTest(unittest.TestCase): + def test_defaults_stay_pinned(self): + out = render() + for source in ("deployment_code_executor.yaml", "deployment_js_executor.yaml"): + self.assertEqual(images(out, source, "wait-for-apparmor"), [PINNED], source) + self.assertTrue(images(out, "apparmor_nsjail_daemonset.yaml")) + for image in images(out, "apparmor_nsjail_daemonset.yaml"): + self.assertEqual(image, PINNED) + + def test_init_image_override_reaches_every_apparmor_container(self): + out = render("initImage.repository=mirror.example/busybox", "initImage.digest=sha256:" + "c" * 64) + expected = "mirror.example/busybox:1.37.0@sha256:" + "c" * 64 + for source in ("deployment_code_executor.yaml", "deployment_js_executor.yaml"): + self.assertEqual(images(out, source, "wait-for-apparmor"), [expected], source) + for image in images(out, "apparmor_nsjail_daemonset.yaml"): + self.assertEqual(image, expected) + + def test_installer_image_still_overrides_the_daemonset(self): + out = render("codeExecutor.appArmorInstallerImage=registry.example/tools:1") + for image in images(out, "apparmor_nsjail_daemonset.yaml"): + self.assertEqual(image, "registry.example/tools:1") + + def test_installer_gets_the_image_pull_secrets(self): + # initImage may point at a registry that needs credentials; the installer + # must get the same pullSecrets as the executors or it never starts. + installer = "# Source: retool/templates/apparmor_nsjail_daemonset.yaml" + default = [d for d in render().split("\n---\n") if installer in d] + self.assertEqual(len(default), 1) + self.assertNotIn("imagePullSecrets", default[0]) + out = render("image.pullSecrets[0].name=regcred") + docs = [d for d in out.split("\n---\n") if installer in d] + self.assertEqual(len(docs), 1) + self.assertIn(" imagePullSecrets:\n - name: regcred\n", docs[0]) + for source in ("deployment_code_executor.yaml", "deployment_js_executor.yaml"): + (doc,) = [d for d in out.split("\n---\n") + if f"# Source: retool/templates/{source}" in d and "\nkind: Deployment\n" in d] + self.assertIn(" imagePullSecrets:\n - name: regcred\n", doc, source) + + +if __name__ == "__main__": + unittest.main() diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 823a66de..66616105 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -104,6 +104,8 @@ jobs: run: python3 .github/test_values_schema.py - name: Verify telemetry ClusterRole names are unique per namespace run: python3 .github/test_telemetry_rbac.py + - name: Verify AppArmor containers honour the initImage override + run: python3 .github/test_apparmor_images.py - name: Verify every pod inherits the top-level nodeSelector and tolerations run: | python3 -m pip install pyyaml diff --git a/charts/retool/Chart.yaml b/charts/retool/Chart.yaml index 224769fa..af622cf9 100644 --- a/charts/retool/Chart.yaml +++ b/charts/retool/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: retool description: Deploy self-hosted Retool on Kubernetes. type: application -version: 6.14.2 +version: 6.14.3 maintainers: - name: Retool Engineering email: engineering+helm@retool.com diff --git a/charts/retool/templates/apparmor_nsjail_daemonset.yaml b/charts/retool/templates/apparmor_nsjail_daemonset.yaml index ed94e1a0..b79ca1a6 100644 --- a/charts/retool/templates/apparmor_nsjail_daemonset.yaml +++ b/charts/retool/templates/apparmor_nsjail_daemonset.yaml @@ -40,7 +40,7 @@ spec: hostPID: true initContainers: - name: install - image: {{ .Values.codeExecutor.appArmorInstallerImage | default "busybox:1.37" }} + image: {{ .Values.codeExecutor.appArmorInstallerImage | default (include "retool.initImage" .) }} securityContext: privileged: true command: @@ -71,7 +71,7 @@ spec: mountPath: /host-run containers: - name: pause - image: {{ .Values.codeExecutor.appArmorInstallerImage | default "busybox:1.37" }} + image: {{ .Values.codeExecutor.appArmorInstallerImage | default (include "retool.initImage" .) }} command: ["sleep", "infinity"] securityContext: allowPrivilegeEscalation: false @@ -85,6 +85,10 @@ spec: limits: cpu: 10m memory: 16Mi +{{- if .Values.image.pullSecrets }} + imagePullSecrets: +{{ toYaml .Values.image.pullSecrets | indent 8 }} +{{- end }} volumes: - name: apparmor-profiles configMap: diff --git a/charts/retool/templates/deployment_code_executor.yaml b/charts/retool/templates/deployment_code_executor.yaml index a89aace2..0e19e792 100644 --- a/charts/retool/templates/deployment_code_executor.yaml +++ b/charts/retool/templates/deployment_code_executor.yaml @@ -90,7 +90,7 @@ spec: mountPath: /host-seccomp {{- if .Values.codeExecutor.appArmorProfileInstaller }} - name: wait-for-apparmor - image: busybox:1.37.0@sha256:b3255e7dfbcd10cb367af0d409747d511aeb66dfac98cf30e97e87e4207dd76f + image: {{ include "retool.initImage" . }} securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true diff --git a/charts/retool/templates/deployment_js_executor.yaml b/charts/retool/templates/deployment_js_executor.yaml index 72187999..6b6aa9e7 100644 --- a/charts/retool/templates/deployment_js_executor.yaml +++ b/charts/retool/templates/deployment_js_executor.yaml @@ -85,7 +85,7 @@ spec: mountPath: /host-seccomp {{- if .Values.codeExecutor.appArmorProfileInstaller }} - name: wait-for-apparmor - image: busybox:1.37.0@sha256:b3255e7dfbcd10cb367af0d409747d511aeb66dfac98cf30e97e87e4207dd76f + image: {{ include "retool.initImage" . }} securityContext: allowPrivilegeEscalation: false readOnlyRootFilesystem: true diff --git a/charts/retool/values.yaml b/charts/retool/values.yaml index 5b46beee..5a5a3272 100644 --- a/charts/retool/values.yaml +++ b/charts/retool/values.yaml @@ -73,8 +73,10 @@ image: # @schema required pullSecrets: # Small utility image for the initContainers that install the nsjail seccomp -# profile onto the host, on the code executor and JS executor. Only used when -# seccomp is in play. +# profile onto the host and wait for the AppArmor profile to load, on the code +# executor and JS executor, and for the AppArmor profile installer DaemonSet +# unless codeExecutor.appArmorInstallerImage is set. Only used when seccomp or +# AppArmor is in play. # # Override repository if every image has to come from one registry -- a private # mirror, an air-gapped install, or GCP Marketplace, which rejects any artifact diff --git a/values.yaml b/values.yaml index 5b46beee..5a5a3272 100644 --- a/values.yaml +++ b/values.yaml @@ -73,8 +73,10 @@ image: # @schema required pullSecrets: # Small utility image for the initContainers that install the nsjail seccomp -# profile onto the host, on the code executor and JS executor. Only used when -# seccomp is in play. +# profile onto the host and wait for the AppArmor profile to load, on the code +# executor and JS executor, and for the AppArmor profile installer DaemonSet +# unless codeExecutor.appArmorInstallerImage is set. Only used when seccomp or +# AppArmor is in play. # # Override repository if every image has to come from one registry -- a private # mirror, an air-gapped install, or GCP Marketplace, which rejects any artifact