Skip to content

feat: Harden every container by default - #1347

Open
lfrancke wants to merge 4 commits into
mainfrom
feat/harden-containers-by-default
Open

lfrancke wants to merge 4 commits into
mainfrom
feat/harden-containers-by-default

Conversation

@lfrancke

@lfrancke lfrancke commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Description

Part of stackabletech/issues#645

ContainerBuilder::new and ContainerBuilder::default are removed in favour of ContainerBuilder::with_stackable_defaults, consistent with PodSecurityContextBuilder::with_stackable_defaults (#1205).
It starts every container with SecurityContextBuilder::with_stackable_defaults(): allowPrivilegeEscalation: false and capabilities.drop: [ALL]. Vector, git-sync and v2::builder::pod::container::new_container_builder go through it, so the operators need no code change: all of them build their containers via new_container_builder (I actually tested this, see below).

Together with the pod-level runAsNonRoot and seccompProfile: RuntimeDefault from #1205 and #1292, Pods built by the operators meet the restricted Pod Security Standard. 🥳 (So far this was only the case for our operator pods)

Important

Spark drivers and executors and Airflow KubernetesExecutor workers are "affected" by this as well if they are built from our pod templates. So, this'd be a breaking change for anyone relying on these elevated privileges.

I ran all 16 operater suites on main (using jig) built against this change with Pod Security audit=restricted

  • 515 of 526 pass in both runs. The only failure that comes from this change is spark-k8s product-config-compat, which needs a comparison file to be updated.
  • restricted violations in Pods the operators create: 377 without this change, 0 with it.
    Spark drivers and executors and Airflow workers: 246 and 0.

Definition of Done Checklist

Author

  • Changes are OpenShift compatible
  • Integration tests passed (for non trivial changes)
  • Changes need to be "offline" compatible

Reviewer

  • Code contains useful comments
  • (Integration-)Test cases added
  • Changelog updated

Acceptance

  • Proper release label has been added

Definition of Done Checklist

  • Not all of these items are applicable to all PRs, the author should update this template to only leave the boxes in that are relevant
  • Please make sure all these things are done and tick the boxes

Author

  • Changes are OpenShift compatible
  • CRD changes approved
  • CRD documentation for all fields, following the style guide.
  • Integration tests passed (for non trivial changes)
  • Changes need to be "offline" compatible

Reviewer

  • Code contains useful comments
  • Code contains useful logging statements
  • (Integration-)Test cases added
  • Documentation added or updated. Follows the style guide.
  • Changelog updated
  • Cargo.toml only contains references to git tags (not specific commits or branches)

Acceptance

  • Feature Tracker has been updated
  • Proper release label has been added

@lfrancke lfrancke self-assigned this Dec 3, 2026
@lfrancke
lfrancke force-pushed the feat/harden-containers-by-default branch from 4dbde7c to d57a5a0 Compare December 3, 2026 08:25
@lfrancke
lfrancke marked this pull request as ready for review December 3, 2026 08:30
@lfrancke lfrancke moved this to Development: Waiting for Review in Stackable Engineering Dec 3, 2026
@lfrancke
lfrancke enabled auto-merge December 3, 2026 08:33
@sbernauer
sbernauer self-requested a review December 4, 2026 07:50
@sbernauer sbernauer moved this from Development: Waiting for Review to Development: In Review in Stackable Engineering Dec 4, 2026
@sbernauer

Copy link
Copy Markdown
Member

Thanks for running the extensive test suite!

I see a few potential things to improve:

  • ContainerBuilder::default is there. Not your fault, but it doesn't "enforce" any Stackable defaults this way. Actually, it defaults the name to "" as well, so it must go
  • I would prefer renaming ContainerBuilder::new to ContainerBuilder::with_stackable_defaults to be consitent with feat!: Add (Pod)SecurityContextBuilder::with_stackable_defaults #1205
  • In ContainerBuilder::with_stackable_defaults we should call the builder functions (instead of fields), to make sure they are sett-able by the caller, so they always have an escape hatch
  • Some developers recently had a chat that AI-generated changelog entries are too verbose and people stop reading it. Regardless if this one was AI or not, I feel like it's a bit too long for us developers. podOverrides setting root IMHO is not a thing we need to consider, users doing that a.) know what they are doing and b.) are on their own. If your platform test-run didn't uncover a problem, I don't think we need to explicitly call out how to replace the context, it's pretty clear from the function signatures. Anyway, I therefore propose to have them less verbose. User-relevant information can totally go into the release notes.

I pushed a branch where I addressed the feedback, happy for you to take it or copy it over to your PR: https://github.com/stackabletech/operator-rs/tree/chore/container-builder-stackable-defaults

@lfrancke

lfrancke commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Thanks. I'm only on the phone now so will look in detail later. The CHANGELOG entry actually is already a shortened version and I kept it in mostly for Spark to consider again if any "user pods" could be affected but I don't care too much about it.

@lfrancke

lfrancke commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Thanks. Looked at it now. I took your entire branch as is. So now you get to review your own code :)

@lfrancke
lfrancke requested review from sbernauer and removed request for sbernauer December 4, 2026 15:11
@lfrancke

lfrancke commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Release notes

* All containers the operators create now set `allowPrivilegeEscalation: false` and drop all capabilities, so product Pods meet the `restricted` Pod Security Standard.
  Containers you add through `podOverrides` are not changed.
+
[#container-security-defaults-27_3_0.breaking-keyword]**Breaking**
`podOverrides` that set `privileged: true` or add the capability `CAP_SYS_ADMIN` now produce a Pod template that Kubernetes rejects, and the operator stops reconciling the stacklet.
Add `allowPrivilegeEscalation: true` to these overrides before upgrading the operators.
Containers that run as root (`runAsUser: 0` or `runAsNonRoot: false`) lose the runtime's default capabilities. They can be restored with `capabilities.drop: []` .
+
Implemented in https://github.com/stackabletech/operator-rs/pull/1347[operator-rs#1347].

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

None yet

Projects

Status: Development: In Review

Development

Successfully merging this pull request may close these issues.

2 participants