Skip to content

Commit 77291e7

Browse files
committed
Do the same thing for SecurityContextBuilder
1 parent c6e34bc commit 77291e7

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

crates/stackable-operator/CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ All notable changes to this project will be documented in this file.
66

77
### Changed
88

9-
- BREAKING: `PodSecurityContextBuilder::new` was removed in favor of `PodSecurityContextBuilder::with_stackable_defaults` ([#XXXX]).
9+
- BREAKING: `PodSecurityContextBuilder::new` was removed in favor of `PodSecurityContextBuilder::with_stackable_defaults`
10+
(same for `SecurityContextBuilder`) ([#1205]).
1011
This function already sets up some defaults we want to use across the platform.
1112
Currently this is `runAsNonRoot: true`, which might cause product Pods to crash and require changes.
12-
- BREAKING: `PodSecurityContextBuilder::run_as_non_root` now takes a `bool` instead of assuming consumers always want to set it to `true` ([#XXXX]).
13+
- BREAKING: `PodSecurityContextBuilder::run_as_non_root` now takes a `bool` instead of assuming consumers always want to set it to `true` ([#1205]).
1314
This is needed to allow users setting it to `false` in case the new `with_stackable_defaults` functions set's it to `true`.
1415

15-
[#XXXX]: https://github.com/stackabletech/operator-rs/pull/XXXX
16+
[#1205]: https://github.com/stackabletech/operator-rs/pull/1205
1617

1718
## [0.113.0] - 2026-06-22
1819

crates/stackable-operator/src/builder/pod/security.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,29 @@ pub struct SecurityContextBuilder {
1010
}
1111

1212
impl SecurityContextBuilder {
13-
/// Convenience function for a wide use-case.
14-
pub fn run_as_root() -> SecurityContext {
15-
SecurityContext {
16-
run_as_user: Some(0),
17-
..SecurityContext::default()
18-
}
13+
/// Construct a new [`SecurityContextBuilder`] that is pre-filled with Stackable's defaults.
14+
///
15+
/// Currently the defaults are:
16+
///
17+
/// * `runAsNonRoot: true`
18+
pub fn with_stackable_defaults() -> Self {
19+
// We are using the builder functions to ensure that builder functions exist to override these settings.
20+
let mut builder = Self {
21+
security_context: SecurityContext::default(),
22+
};
23+
24+
// Reason: Running as root is bad
25+
builder.run_as_non_root(true);
26+
27+
builder
1928
}
2029

21-
pub fn new() -> Self {
22-
Self::default()
30+
/// Convenience function for a wide use-case.
31+
///
32+
/// Please only use this is really needed.
33+
pub fn run_as_root(&mut self) {
34+
self.run_as_user(0);
35+
self.run_as_non_root(false);
2336
}
2437

2538
pub fn allow_privilege_escalation(&mut self, value: bool) -> &mut Self {

0 commit comments

Comments
 (0)