Skip to content

Commit

Permalink
Allow setting ReadOnlyRootFilesystem (#10560)
Browse files Browse the repository at this point in the history
* Allow setting ReadOnlyRootFilesystem

* Fixed formatting.
  • Loading branch information
senthilnathan authored Jan 18, 2021
1 parent 5fbe2f1 commit da1db84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/serving/fieldmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ func SecurityContextMask(ctx context.Context, in *corev1.SecurityContext) *corev

// Allowed fields
out.RunAsUser = in.RunAsUser
out.ReadOnlyRootFilesystem = in.ReadOnlyRootFilesystem

if config.FromContextOrDefaults(ctx).Features.PodSpecSecurityContext != config.Disabled {
out.RunAsGroup = in.RunAsGroup
Expand All @@ -603,7 +604,6 @@ func SecurityContextMask(ctx context.Context, in *corev1.SecurityContext) *corev
out.Capabilities = nil
out.Privileged = nil
out.SELinuxOptions = nil
out.ReadOnlyRootFilesystem = nil
out.AllowPrivilegeEscalation = nil
out.ProcMount = nil

Expand Down
10 changes: 6 additions & 4 deletions pkg/apis/serving/fieldmask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ func TestPodSecurityContextMask_FeatureEnabled(t *testing.T) {
func TestSecurityContextMask(t *testing.T) {
mtype := corev1.UnmaskedProcMount
want := &corev1.SecurityContext{
RunAsUser: ptr.Int64(1),
RunAsUser: ptr.Int64(1),
ReadOnlyRootFilesystem: ptr.Bool(true),
}
in := &corev1.SecurityContext{
RunAsUser: ptr.Int64(1),
Expand Down Expand Up @@ -754,9 +755,10 @@ func TestSecurityContextMask(t *testing.T) {
func TestSecurityContextMask_FeatureEnabled(t *testing.T) {
mtype := corev1.UnmaskedProcMount
want := &corev1.SecurityContext{
RunAsGroup: ptr.Int64(2),
RunAsNonRoot: ptr.Bool(true),
RunAsUser: ptr.Int64(1),
RunAsGroup: ptr.Int64(2),
RunAsNonRoot: ptr.Bool(true),
RunAsUser: ptr.Int64(1),
ReadOnlyRootFilesystem: ptr.Bool(true),
}
in := &corev1.SecurityContext{
AllowPrivilegeEscalation: ptr.Bool(true),
Expand Down

0 comments on commit da1db84

Please sign in to comment.