Repository navigation
[feat] Use initImage for the AppArmor wait and installer containers #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cameronattard
wants to merge
1
commit into
tryretool:main
Choose a base branch
from
cameronattard:feat/apparmor-wait-image
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The installer now uses
initImage, but its pod never receivesimage.pullSecrets. If an operator pointsinitImage.repositoryat a registry that requires login and supplies credentials throughimage.pullSecrets, the executors can pull the image but the installer cannot. On a fresh node, the AppArmor profile never loads andwait-for-apparmorwaits forever.Add the same pod-level
imagePullSecretsblock used by the executor deployments, and cover it in the new render test.There was a problem hiding this comment.
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.pullSecretsthe same way as the executors, andtest_apparmor_images.pychecks it reaches the installer and both executors (and is absent by default).