Skip to content
Open
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
88 changes: 88 additions & 0 deletions .github/test_apparmor_images.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion charts/retool/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions charts/retool/templates/apparmor_nsjail_daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" .) }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Private image pulls fail

The installer now uses initImage, but its pod never receives image.pullSecrets. If an operator points initImage.repository at a registry that requires login and supplies credentials through image.pullSecrets, the executors can pull the image but the installer cannot. On a fresh node, the AppArmor profile never loads and wait-for-apparmor waits forever.

Add the same pod-level imagePullSecrets block used by the executor deployments, and cover it in the new render test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6ee5acb: the installer DaemonSet now renders image.pullSecrets the same way as the executors, and test_apparmor_images.py checks it reaches the installer and both executors (and is absent by default).

securityContext:
privileged: true
command:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion charts/retool/templates/deployment_code_executor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion charts/retool/templates/deployment_js_executor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions charts/retool/values.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions values.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.