Skip to content

Commit 20b5f93

Browse files
feat(container, pod): default runAsNonRoot to true (#1143) (#1154)
# Backport This will backport the following commits from `k8s-24/main` to `k8s-22/main`: - [feat(container, pod): default `runAsNonRoot` to true (#1143)](#1143) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
1 parent c98fac0 commit 20b5f93

11 files changed

+253
-253
lines changed

src/container.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface ContainerSecurityContextProps {
3535
* If true, the Kubelet will validate the image at runtime to ensure that it does
3636
* not run as UID 0 (root) and fail to start the container if it does.
3737
*
38-
* @default false
38+
* @default true
3939
*/
4040
readonly ensureNonRoot?: boolean;
4141

@@ -132,7 +132,7 @@ export class ContainerSecurityContext {
132132
public readonly group?: number;
133133

134134
constructor(props: ContainerSecurityContextProps = {}) {
135-
this.ensureNonRoot = props.ensureNonRoot ?? false;
135+
this.ensureNonRoot = props.ensureNonRoot ?? true;
136136
this.privileged = props.privileged ?? false;
137137
this.readOnlyRootFilesystem = props.readOnlyRootFilesystem ?? true;
138138
this.user = props.user ?? 25000;
@@ -636,7 +636,7 @@ export interface ContainerProps {
636636
* @see https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
637637
* @default
638638
*
639-
* ensureNonRoot: false
639+
* ensureNonRoot: true
640640
* privileged: false
641641
* readOnlyRootFilesystem: true
642642
*/

src/pod.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ export interface PodSecurityContextProps {
288288
* If true, the Kubelet will validate the image at runtime to ensure that it does
289289
* not run as UID 0 (root) and fail to start the container if it does.
290290
*
291-
* @default false
291+
* @default true
292292
*/
293293
readonly ensureNonRoot?: boolean;
294294

@@ -375,7 +375,7 @@ export interface AbstractPodProps extends base.ResourceProps {
375375
* @default
376376
*
377377
* fsGroupChangePolicy: FsGroupChangePolicy.FsGroupChangePolicy.ALWAYS
378-
* ensureNonRoot: false
378+
* ensureNonRoot: true
379379
*/
380380
readonly securityContext?: PodSecurityContextProps;
381381

@@ -743,7 +743,7 @@ export class PodSecurityContext {
743743
private readonly _sysctls: Sysctl[] = [];
744744

745745
constructor(props: PodSecurityContextProps = {}) {
746-
this.ensureNonRoot = props.ensureNonRoot ?? false;
746+
this.ensureNonRoot = props.ensureNonRoot ?? true;
747747
this.fsGroupChangePolicy = props.fsGroupChangePolicy ?? FsGroupChangePolicy.ALWAYS;
748748
this.user = props.user;
749749
this.group = props.group;

test/__snapshots__/container.test.ts.snap

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/__snapshots__/cron-job.test.ts.snap

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/__snapshots__/daemon-set.test.ts.snap

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)