Skip to content

compile: hold python-box below 8 in the kadet environment - #321

Open
Moep90 wants to merge 2 commits into
kapicorp:mainfrom
Moep90:fix/kadet-container-security-context
Open

Moep90 wants to merge 2 commits into
kapicorp:mainfrom
Moep90:fix/kadet-container-security-context

Conversation

@Moep90

@Moep90 Moep90 commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Summary

krab's managed kadet environment now installs python-box>=7.2.0,<8, the range kapitan 0.36.3 declares. With python-box 8 a component's write to an element of a concatenated list is lost, which is why the container securityContext from the kubernetes generator went missing.

Closes #320

Motivation

My guess in #320 was wrong: krab hands components references just like kapitan does. The difference is the python-box major version. kapitan 0.36.3 requires python-box<8, while krab's venv baseline was just kadet jinja2, and kadet allows any python-box above 6, so the venv got 8.0.1. In python-box 8, BoxList.__add__ builds a new BoxList and extend/+= convert every dict element into a new Box. pod_spec.containers + pod_spec.initContainers therefore iterates over copies, and container["securityContext"] = context writes into a copy. With 7.4.1, + returns a plain list of the original elements.

I checked this against the generator (kubernetes, base.py _apply_security_profile) on a one-component target with security_profile: restricted and read_only_root_filesystem: true:

Run Container securityContext filled
kapitan 0.36.3, python-box 7.4.1 (what pip resolves) yes
kapitan 0.36.3 with python-box 8.0.1 forced in no, the same diff as in #320
krab main, managed venv (python-box 8.0.1) no
krab main, KRAB_PYTHON on a python-box 8.0.1 venv no
krab this branch, managed venv (python-box 7.4.1) yes, byte-identical to kapitan

The issue says the kapitan side also had python-box 8.0.1. I could not check that image. kapitan 0.36.3 and kapitan's current pyproject.toml both pin <8, and 0.36.3 with 8.0.1 drops the fields too.

Changes:

  • pyenv.rs: python-box>=7.2.0,<8 joins the baseline. The baseline filter now compares project names, so a python-box named in .kapitan or KRAB_PYTHON_REQUIREMENTS replaces the pinned entry the way kadet and jinja2 already do.
  • The kadet fixture component writes to an element of a + b, and kadet_runner.rs asserts that the write lands.
  • CI and CONTRIBUTING install python-box in the same range, so the test runs against what the reference uses.
  • CMP-44 in docs/specs/compile.md and GETTING-STARTED describe the pin.

Test plan

  • cargo fmt --all --check
  • cargo clippy --all-targets --locked
  • cargo test --release --locked with CI=1, python3 on a python-box 7.4.1 venv: all pass
  • The new kadet_runner assertion fails on python-box 8.0.1 and passes on 7.4.1. The pyenv unit tests now assert the pinned baseline entry and that a named python_box replaces it.
  • Fixture case: the kadet fixture component was extended. Inventory expected output is unaffected since no engine code changed.
  • Checked against a real compile: the target above, krab compile with the managed venv against kapitan compile 0.36.3, diff is empty

Risk assessment

Every existing managed venv gets a new digest and is rebuilt once on the next compile. A project that depends on python-box 8 features in its own generator code would now get 7.x. It can name python-box under compile.python-requirements to override the pin, at the cost of this parity issue. Reverting means dropping the baseline entry.

Left out on purpose

  • --python / KRAB_PYTHON interpreters are still used as they are (CMP-42), so a python-box 8 there still shows the bug. GETTING-STARTED now says so. I did not add a version check or warning.
  • The baseline kadet stays unpinned, although kapitan requires kadet>=0.3.0,<0.4.

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 kapicorp#320

Signed-off-by: Moep90 <3042152+Moep90@users.noreply.github.com>
@github-actions github-actions Bot added documentation Improvements or additions to documentation area: compile Compile, input and output types, manifest area: packaging Crates, release binaries, CI labels Nov 15, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 16, 2026
Moep90 added a commit to kadet-hub/krab that referenced this pull request Nov 16, 2026
Signed-off-by: Moep90 <3042152+Moep90@users.noreply.github.com>
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 16, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 16, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 16, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 17, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 17, 2026
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
kapicorp#314, so whichever lands first leaves the other a no-op for this file.

Signed-off-by: Moep90 <3042152+Moep90@users.noreply.github.com>
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 17, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 18, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 18, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 18, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 19, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 19, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 19, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 20, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 20, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 20, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 20, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 21, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 21, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 21, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 22, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 22, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 22, 2026
kadet-hub-kapitan-next Bot pushed a commit to kadet-hub/krab that referenced this pull request Nov 22, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compile Compile, input and output types, manifest area: packaging Crates, release binaries, CI documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[parity]: kadet output loses a container securityContext that the generator writes into pod_spec.containers

1 participant