From 9e984b107ac26486863b7ae721453d76d58600d9 Mon Sep 17 00:00:00 2001 From: Moep90 Date: Sun, 15 Nov 2026 17:22:11 +0100 Subject: [PATCH 1/2] compile: hold python-box below 8 in the kadet environment kapitan 0.36.3 requires python-box>=7.2.0,<8; krab's managed venv installed whatever kadet pulled in, which is python-box 8. From 8 on, BoxList copies the dicts it is built from, so `a + b` and `a += [x]` no longer hold the original elements, and a component's write to such an element is lost. The kubernetes generator's _apply_security_profile does exactly that with pod_spec.containers + pod_spec.initContainers. The baseline now carries the same range, and a python-box named in .kapitan or KRAB_PYTHON_REQUIREMENTS replaces it like kadet and jinja2 do. Closes #320 Signed-off-by: Moep90 <3042152+Moep90@users.noreply.github.com> --- .github/workflows/ci.yml | 8 ++-- CONTRIBUTING.md | 2 +- crates/krab-compile/src/pyenv.rs | 38 ++++++++++++++----- crates/krab-compile/tests/kadet_runner.rs | 4 ++ docs/GETTING-STARTED.md | 7 +++- docs/specs/compile.md | 21 +++++++--- .../kadet/components/greeter/__init__.py | 7 ++++ 7 files changed, 65 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 678a6d8f..0fef6db6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,13 +115,13 @@ jobs: save-if: ${{ github.ref == 'refs/heads/main' }} # The Python resolver tests run a user resolvers.py in python3; PyYAML # and omegaconf make the fixture parity test run against the real package. - # kadet and jinja2 let the kadet evaluator test run. omegaconf is held - # at the version the reference implementation needs, so this job and the - # parity job exercise the same one. + # kadet and jinja2 let the kadet evaluator test run. omegaconf and + # python-box are held at the versions the reference implementation + # needs, so this job and the parity job exercise the same ones. - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 with: python-version: ${{ matrix.python }} - - run: pip install pyyaml "omegaconf==2.4.0.dev3" kadet jinja2 + - run: pip install pyyaml "omegaconf==2.4.0.dev3" kadet jinja2 "python-box>=7.2.0,<8" - run: cargo test --locked parity: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bce04efc..37b64a98 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -83,7 +83,7 @@ and network access for pip. `python3` with ```sh - pip install pyyaml "omegaconf==2.4.0.dev3" kadet jinja2 + pip install pyyaml "omegaconf==2.4.0.dev3" kadet jinja2 "python-box>=7.2.0,<8" ``` Without them the tests pass without running and say why on stderr, which diff --git a/crates/krab-compile/src/pyenv.rs b/crates/krab-compile/src/pyenv.rs index 602b0373..aa127b35 100644 --- a/crates/krab-compile/src/pyenv.rs +++ b/crates/krab-compile/src/pyenv.rs @@ -20,8 +20,9 @@ //! `KRAB_PYTHON_REQUIREMENTS` adds specifiers for this machine only, one //! per line (`kadet==0.3.1`, `kadet @ file:///home/me/kadet`, or //! `-e /home/me/kadet` for an editable checkout), without touching the -//! shared `.kapitan`. A `kadet` or `jinja2` named by either source replaces -//! the baseline entry, so a pin or a checkout is the only one installed. +//! shared `.kapitan`. A `kadet`, `jinja2` or `python-box` named by either +//! source replaces the baseline entry, so a pin or a checkout is the only +//! one installed. //! //! `--python` / `KRAB_PYTHON` bypass all of this: that interpreter is //! used as it is, and nothing else is ever tried (in particular not a @@ -33,7 +34,10 @@ use std::process::Command; use krab_inventory::python::{PythonCmd, cache_dir, which}; /// What every kadet evaluation needs, whatever the repository declares. -pub const BASELINE: &[&str] = &["kadet", "jinja2"]; +/// python-box is held to the range kapitan 0.36.3 requires: from 8 on, +/// `BoxList` copies the dicts it is built from, so a component's write to an +/// element of `a + b` no longer reaches `a` (#320). +pub const BASELINE: &[&str] = &["kadet", "jinja2", "python-box>=7.2.0,<8"]; const MARKER: &str = ".krab-env.json"; @@ -124,7 +128,7 @@ impl PythonEnv { .collect(); let mut out: Vec = BASELINE .iter() - .filter(|b| !named.contains(&b.to_string())) + .filter(|b| project_name(b).is_none_or(|n| !named.contains(&n))) .map(|s| s.to_string()) .collect(); for r in self.requirements.iter().chain(&self.extra) { @@ -332,7 +336,13 @@ mod tests { assert!(env.declared); assert_eq!( env.specifiers(), - vec!["kadet", "jinja2", "jmespath", "jsonpath-ng"] + vec![ + "kadet", + "jinja2", + "python-box>=7.2.0,<8", + "jmespath", + "jsonpath-ng" + ] ); assert!(env.requirements_file.is_none()); } @@ -356,18 +366,28 @@ mod tests { #[test] fn a_named_baseline_package_replaces_the_baseline_entry() { - let env = spec(Some(vec!["Kadet==0.3.1", "jinja2>=3"])); - assert_eq!(env.specifiers(), vec!["Kadet==0.3.1", "jinja2>=3"]); + let env = spec(Some(vec!["Kadet==0.3.1", "jinja2>=3", "python_box==7.4.1"])); + assert_eq!( + env.specifiers(), + vec!["Kadet==0.3.1", "jinja2>=3", "python_box==7.4.1"] + ); let mut env = spec(None); env.extra = vec!["-e /home/me/kadet/".into()]; - assert_eq!(env.specifiers(), vec!["jinja2", "-e /home/me/kadet/"]); + assert_eq!( + env.specifiers(), + vec!["jinja2", "python-box>=7.2.0,<8", "-e /home/me/kadet/"] + ); let mut env = spec(None); env.extra = vec!["kadet @ file:///home/me/kadet".into()]; assert_eq!( env.specifiers(), - vec!["jinja2", "kadet @ file:///home/me/kadet"] + vec![ + "jinja2", + "python-box>=7.2.0,<8", + "kadet @ file:///home/me/kadet" + ] ); } diff --git a/crates/krab-compile/tests/kadet_runner.rs b/crates/krab-compile/tests/kadet_runner.rs index e5213ab6..f9864343 100644 --- a/crates/krab-compile/tests/kadet_runner.rs +++ b/crates/krab-compile/tests/kadet_runner.rs @@ -94,6 +94,10 @@ fn evaluates_a_component_without_the_python_kapitan() { assert_eq!(output["pruned"], json!({ "keep": 1, "nested": {} })); assert_eq!(output["targets"], json!(["app.api", "app.web"])); assert_eq!(output["params"], "plain"); + assert_eq!( + output["pod"]["containers"], + json!([{ "name": "app", "securityContext": { "readOnlyRootFilesystem": true } }]) + ); let modules: Vec<&str> = output["kapitan_modules"] .as_array() .unwrap() diff --git a/docs/GETTING-STARTED.md b/docs/GETTING-STARTED.md index 62f46b98..aef8ba34 100644 --- a/docs/GETTING-STARTED.md +++ b/docs/GETTING-STARTED.md @@ -163,7 +163,8 @@ templates and whatever the components themselves import); the Python kapitan itself is not. krab builds that environment for you: declare the components' own packages in `.kapitan` and the first compile creates a venv under `~/.cache/krab/python/` (with `uv` when installed, else `python3 --m venv` and pip) holding `kadet`, `jinja2` and them: +-m venv` and pip) holding `kadet`, `jinja2`, `python-box` (in the range kapitan +requires) and them: ```yaml compile: @@ -177,7 +178,9 @@ alone. To try another kadet, or your own checkout, without touching the shared file, set `KRAB_PYTHON_REQUIREMENTS` (one specifier per line, for example `kadet==0.3.1` or `-e /home/me/kadet`); a `kadet` named there or in `.kapitan` replaces krab's own entry. `--python` / `$KRAB_PYTHON` name -an interpreter to use as it is instead (nothing is installed into it). Nothing else is tried: an installed +an interpreter to use as it is instead (nothing is installed into it). With a +python-box newer than kapitan allows there, kadet output can differ from +kapitan's (#320). Nothing else is tried: an installed Python kapitan plays no part in kadet evaluation. The component's `main()` runs in that Python with krab's own `kapitan` package on the path, which provides the API components import (`kapitan.inputs.kadet`, diff --git a/docs/specs/compile.md b/docs/specs/compile.md index 94198c16..61363983 100644 --- a/docs/specs/compile.md +++ b/docs/specs/compile.md @@ -354,14 +354,23 @@ CMP-43 Without one, kadet evaluation MUST use krab's managed environment: a Test: none Since: #91 -CMP-44 The managed environment MUST install `kadet` and `jinja2`, then the - entries of `compile.python-requirements`, then the lines of - `$KRAB_PYTHON_REQUIREMENTS`. A `kadet` or `jinja2` named in either - list replaces the baseline entry. A single +CMP-44 The managed environment MUST install `kadet`, `jinja2` and + `python-box>=7.2.0,<8`, then the entries of + `compile.python-requirements`, then the lines of + `$KRAB_PYTHON_REQUIREMENTS`. A `kadet`, `jinja2` or `python-box` named + in either list replaces the baseline entry. A single `compile.python-requirements` value that is an existing file or ends in `.txt` is a requirements file. - Test: crates/krab-compile/src/pyenv.rs::tests::a_named_baseline_package_replaces_the_baseline_entry - Since: #91 + Test: crates/krab-compile/src/pyenv.rs::tests::a_named_baseline_package_replaces_the_baseline_entry, + crates/krab-compile/tests/kadet_runner.rs::evaluates_a_component_without_the_python_kapitan + (the write to an element of `a + b`) + Since: #91, python-box range #321 + + The python-box range is the one kapitan 0.36.3 declares. python-box 8 + copies the dicts a `BoxList` is built from, so a component that writes + to an element of `a + b` (the kubernetes generator's + `pod_spec.containers + pod_spec.initContainers`) loses the write, and + its output differs from kapitan's. CMP-45 `--backend python` MUST try, in order, `--python`/`$KRAB_PYTHON`, a kapitan PEX on PATH run with PEX_INTERPRETER=1, and `python3`, and diff --git a/tests/fixtures/kadet/components/greeter/__init__.py b/tests/fixtures/kadet/components/greeter/__init__.py index cf64301f..6d8e27a6 100644 --- a/tests/fixtures/kadet/components/greeter/__init__.py +++ b/tests/fixtures/kadet/components/greeter/__init__.py @@ -20,6 +20,13 @@ def main(input_params): out.root.pruned = greetlib.prune_empty({"keep": 1, "drop": [], "nested": {"drop": {}}}) out.root.targets = sorted(all_documents(None).keys()) out.root.params = input_params.get("flavour") + # A write to an element of `a + b` lands in `a`, as with kapitan's python-box (#320). + pod = BaseObj().root + pod.containers = [{"name": "app"}] + pod.initContainers = [] + for container in pod.containers + pod.initContainers: + container["securityContext"] = {"readOnlyRootFilesystem": True} + out.root.pod = pod # Nothing from an installed kapitan may have been imported. out.root.kapitan_modules = sorted(m for m in sys.modules if m == "kapitan" or m.startswith("kapitan.")) return out From bf2c9b40939a8901c2554eb7a941a07481543c61 Mon Sep 17 00:00:00 2001 From: Moep90 Date: Tue, 17 Nov 2026 21:35:30 +0100 Subject: [PATCH 2/2] ci: bump pypa/gh-action-pypi-publish to v1.14.3 (GHSA-5xjx-3w67-w9x9) zizmor's known-vulnerable-actions audit fails every run of the Workflow lint job since the advisory was published on 2026-10-30, main included. v1.14.3 is the first patched release. The change is the same line as #314, so whichever lands first leaves the other a no-op for this file. Signed-off-by: Moep90 <3042152+Moep90@users.noreply.github.com> --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c8f35a7..7d08111e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -230,4 +230,4 @@ jobs: pattern: wheel-* path: dist merge-multiple: true - - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2 + - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3