Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set ReadOnlyRootFilesystem and AllowPrivilegeEscalation to false #3498

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ func (w *MeshWebhook) consulDataplaneSidecar(namespace corev1.Namespace, pod cor
}
}
container.SecurityContext = &corev1.SecurityContext{
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
ReadOnlyRootFilesystem: pointer.Bool(true),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,20 +803,22 @@ func TestHandlerConsulDataplaneSidecar_withSecurityContext(t *testing.T) {
tproxyEnabled: false,
openShiftEnabled: false,
expSecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
},
},
"tproxy enabled; openshift disabled": {
tproxyEnabled: true,
openShiftEnabled: false,
expSecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
},
},
"tproxy disabled; openshift enabled": {
Expand All @@ -828,10 +830,11 @@ func TestHandlerConsulDataplaneSidecar_withSecurityContext(t *testing.T) {
tproxyEnabled: true,
openShiftEnabled: true,
expSecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions control-plane/connect-inject/webhook/container_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ func (w *MeshWebhook) containerInit(namespace corev1.Namespace, pod corev1.Pod,
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions control-plane/connect-inject/webhook/container_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ func TestHandlerContainerInit_transparentProxy(t *testing.T) {
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
}
} else if c.expTproxyEnabled {
expectedSecurityContext = &corev1.SecurityContext{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,11 @@ func (w *MeshWebhook) consulDataplaneSidecar(namespace corev1.Namespace, pod cor
}
}
container.SecurityContext = &corev1.SecurityContext{
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,22 @@ func TestHandlerConsulDataplaneSidecar_withSecurityContext(t *testing.T) {
tproxyEnabled: false,
openShiftEnabled: false,
expSecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
},
},
"tproxy enabled; openshift disabled": {
tproxyEnabled: true,
openShiftEnabled: false,
expSecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
},
},
"tproxy disabled; openshift enabled": {
Expand All @@ -492,10 +494,11 @@ func TestHandlerConsulDataplaneSidecar_withSecurityContext(t *testing.T) {
tproxyEnabled: true,
openShiftEnabled: true,
expSecurityContext: &corev1.SecurityContext{
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
RunAsUser: pointer.Int64(sidecarUserAndGroupID),
RunAsGroup: pointer.Int64(sidecarUserAndGroupID),
RunAsNonRoot: pointer.Bool(true),
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions control-plane/connect-inject/webhookv2/container_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ func (w *MeshWebhook) containerInit(namespace corev1.Namespace, pod corev1.Pod)
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions control-plane/connect-inject/webhookv2/container_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ func TestHandlerContainerInit_transparentProxy(t *testing.T) {
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
ReadOnlyRootFilesystem: pointer.Bool(true),
AllowPrivilegeEscalation: pointer.Bool(false),
}
} else if c.expTproxyEnabled {
expectedSecurityContext = &corev1.SecurityContext{
Expand Down