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>
(cherry picked from commit df6d7af355)
This commit is contained in:
3 files changed
+21
-6
No files matched your search
@@ -258,11 +258,13 @@ func getCrashDaemonContainer(cephCluster cephv1.CephCluster, cephVersion cephver
|
||||
Command: []string{
|
||||
"ceph-crash",
|
||||
},
|
||||
Image: cephImage,
|
||||
Env: envVars,
|
||||
VolumeMounts: volumeMounts,
|
||||
Resources: cephv1.GetCrashCollectorResources(cephCluster.Spec.Resources),
|
||||
SecurityContext: controller.PodSecurityContext(),
|
||||
Image: cephImage,
|
||||
Env: envVars,
|
||||
VolumeMounts: volumeMounts,
|
||||
Resources: cephv1.GetCrashCollectorResources(cephCluster.Spec.Resources),
|
||||
// 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"
|
||||
@@ -152,6 +153,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,7 +54,8 @@ const (
|
||||
daemonTypeLabel = "ceph_daemon_type"
|
||||
ExternalMgrAppName = "rook-ceph-mgr-external"
|
||||
ServiceExternalMetricName = "http-external-metrics"
|
||||
livenessProbeTimeoutSeconds int32 = 2
|
||||
CephUserID = 167
|
||||
livenessProbeTimeoutSeconds int32 = 5
|
||||
livenessProbeInitialDelaySeconds int32 = 10
|
||||
startupProbeFailuresDaemonDefault int32 = 6 // multiply by 10 = effective startup timeout
|
||||
// The OSD requires a long timeout in case the OSD is taking extra time to
|
||||
@@ -660,6 +662,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