security: run the crash collector as ceph user
The crash collector does not have the command line arguments to run as ceph user id 167, so we set the security context to run as the ceph user in the main crash collector container. Signed-off-by: Travis Nielsen <tnielsen@redhat.com>
This commit is contained in:
3 files changed
+16
-1
No files matched your search
@@ -265,7 +265,9 @@ func getCrashDaemonContainer(cephCluster cephv1.CephCluster, cephVersion cephver
|
||||
Env: envVars,
|
||||
VolumeMounts: volumeMounts,
|
||||
Resources: cephv1.GetCrashCollectorResources(cephCluster.Spec.Resources),
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
// Initialize the security context with the ceph user since the ceph-crash script does not have an argument
|
||||
// to run as the ceph user
|
||||
SecurityContext: controller.CephSecurityContext(),
|
||||
}
|
||||
|
||||
return container
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
rookclient "github.com/rook/rook/pkg/client/clientset/versioned/fake"
|
||||
"github.com/rook/rook/pkg/client/clientset/versioned/scheme"
|
||||
"github.com/rook/rook/pkg/clusterd"
|
||||
"github.com/rook/rook/pkg/operator/ceph/controller"
|
||||
cephver "github.com/rook/rook/pkg/operator/ceph/version"
|
||||
"github.com/rook/rook/pkg/operator/k8sutil"
|
||||
"github.com/rook/rook/pkg/operator/test"
|
||||
@@ -151,6 +152,8 @@ func TestCreateOrUpdateCephCrash(t *testing.T) {
|
||||
assert.Equal(t, tolerations, podSpec.Spec.Tolerations)
|
||||
assert.Equal(t, false, podSpec.Spec.HostNetwork)
|
||||
assert.Equal(t, "", podSpec.Spec.PriorityClassName)
|
||||
assert.Equal(t, int64(controller.CephUserID), *podSpec.Spec.Containers[0].SecurityContext.RunAsUser)
|
||||
assert.Equal(t, int64(controller.CephUserID), *podSpec.Spec.Containers[0].SecurityContext.RunAsGroup)
|
||||
|
||||
cephCluster.Spec.Labels[cephv1.KeyCrashCollector] = map[string]string{"foo": "bar"}
|
||||
cephCluster.Spec.Network.HostNetwork = true
|
||||
|
||||
@@ -38,6 +38,7 @@ import (
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -53,6 +54,7 @@ const (
|
||||
daemonTypeLabel = "ceph_daemon_type"
|
||||
ExternalMgrAppName = "rook-ceph-mgr-external"
|
||||
ServiceExternalMetricName = "http-external-metrics"
|
||||
CephUserID = 167
|
||||
livenessProbeTimeoutSeconds int32 = 5
|
||||
livenessProbeInitialDelaySeconds int32 = 10
|
||||
startupProbeFailuresDaemonDefault int32 = 6 // multiply by 10 = effective startup timeout
|
||||
@@ -656,6 +658,14 @@ func PodSecurityContext() *v1.SecurityContext {
|
||||
}
|
||||
}
|
||||
|
||||
// PodSecurityContext detects if the pod needs privileges to run
|
||||
func CephSecurityContext() *v1.SecurityContext {
|
||||
context := PodSecurityContext()
|
||||
context.RunAsUser = pointer.Int64(CephUserID)
|
||||
context.RunAsGroup = pointer.Int64(CephUserID)
|
||||
return context
|
||||
}
|
||||
|
||||
// PrivilegedContext returns a privileged Pod security context
|
||||
func PrivilegedContext(runAsRoot bool) *v1.SecurityContext {
|
||||
privileged := true
|
||||
|
||||
Reference in new issue
Block a user