Skip to content

Commit

Permalink
Add SecCompCustomProfileConfigMap for system-probe (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
L3n41c committed Apr 17, 2020
1 parent 500f53d commit 17f2aec
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
4 changes: 4 additions & 0 deletions deploy/crds/datadoghq.com_datadogagents_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,10 @@ spec:
https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/'
type: object
type: object
secCompCustomProfileConfigMap:
description: SecCompCustomProfileConfigMap specify a pre-existing
ConfigMap containing a custom SecComp profile
type: string
secCompProfileName:
description: SecCompProfileName specify a seccomp profile
type: string
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/datadoghq/v1alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ type SystemProbeSpec struct {
// +optional
SecCompRootPath string `json:"secCompRootPath,omitempty"`

// SecCompCustomProfileConfigMap specify a pre-existing ConfigMap containing a custom SecComp profile
// +optional
SecCompCustomProfileConfigMap string `json:"secCompCustomProfileConfigMap,omitempty"`

// SecCompProfileName specify a seccomp profile
// +optional
SecCompProfileName string `json:"secCompProfileName,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/datadoghq/v1alpha1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions pkg/controller/datadogagent/systemprobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ func (r *ReconcileDatadogAgent) manageSystemProbeDependencies(logger logr.Logger
return result, err
}

result, err = r.manageConfigMap(logger, dda, getSecCompConfigMapName(dda.Name), buildSystemProbeSecCompConfigMap)
if shouldReturn(result, err) {
return result, err
if getSeccompProfileName(&dda.Spec.Agent.SystemProbe) == datadoghqv1alpha1.DefaultSeccompProfileName && dda.Spec.Agent.SystemProbe.SecCompCustomProfileConfigMap == "" {
result, err = r.manageConfigMap(logger, dda, getSecCompConfigMapName(dda.Name), buildSystemProbeSecCompConfigMap)
if shouldReturn(result, err) {
return result, err
}
}

return reconcile.Result{}, nil
Expand Down
46 changes: 26 additions & 20 deletions pkg/controller/datadogagent/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,30 @@ func getInitContainers(dda *datadoghqv1alpha1.DatadogAgent) ([]corev1.Container,
},
}
if isSystemProbeEnabled(dda) {
systemProbeInit := corev1.Container{
Name: "seccomp-setup",
Image: spec.Agent.Image.Name,
ImagePullPolicy: *spec.Agent.Image.PullPolicy,
Resources: *spec.Agent.Config.Resources,
Command: []string{
"cp",
fmt.Sprintf("%s/system-probe-seccomp.json", datadoghqv1alpha1.SystemProbeAgentSecurityVolumePath),
fmt.Sprintf("%s/system-probe", datadoghqv1alpha1.SystemProbeSecCompRootVolumePath),
},
VolumeMounts: []corev1.VolumeMount{
{
Name: datadoghqv1alpha1.SystemProbeAgentSecurityVolumeName,
MountPath: datadoghqv1alpha1.SystemProbeAgentSecurityVolumePath,
if getSeccompProfileName(&dda.Spec.Agent.SystemProbe) == datadoghqv1alpha1.DefaultSeccompProfileName || dda.Spec.Agent.SystemProbe.SecCompCustomProfileConfigMap != "" {
systemProbeInit := corev1.Container{
Name: "seccomp-setup",
Image: spec.Agent.Image.Name,
ImagePullPolicy: *spec.Agent.Image.PullPolicy,
Resources: *spec.Agent.Config.Resources,
Command: []string{
"cp",
fmt.Sprintf("%s/system-probe-seccomp.json", datadoghqv1alpha1.SystemProbeAgentSecurityVolumePath),
fmt.Sprintf("%s/system-probe", datadoghqv1alpha1.SystemProbeSecCompRootVolumePath),
},
{
Name: datadoghqv1alpha1.SystemProbeSecCompRootVolumeName,
MountPath: datadoghqv1alpha1.SystemProbeSecCompRootVolumePath,
VolumeMounts: []corev1.VolumeMount{
{
Name: datadoghqv1alpha1.SystemProbeAgentSecurityVolumeName,
MountPath: datadoghqv1alpha1.SystemProbeAgentSecurityVolumePath,
},
{
Name: datadoghqv1alpha1.SystemProbeSecCompRootVolumeName,
MountPath: datadoghqv1alpha1.SystemProbeSecCompRootVolumePath,
},
},
},
}
containers = append(containers, systemProbeInit)
}
containers = append(containers, systemProbeInit)
}

return containers, nil
Expand Down Expand Up @@ -655,13 +657,17 @@ func getVolumesForAgent(dda *datadoghqv1alpha1.DatadogAgent) []corev1.Volume {
volumes = append(volumes, passwdVolume)
}
if datadoghqv1alpha1.BoolValue(dda.Spec.Agent.SystemProbe.Enabled) {
seccompConfigMapName := getSecCompConfigMapName(dda.Name)
if dda.Spec.Agent.SystemProbe.SecCompCustomProfileConfigMap != "" {
seccompConfigMapName = dda.Spec.Agent.SystemProbe.SecCompCustomProfileConfigMap
}
systemProbeVolumes := []corev1.Volume{
{
Name: datadoghqv1alpha1.SystemProbeAgentSecurityVolumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: getSecCompConfigMapName(dda.Name),
Name: seccompConfigMapName,
},
},
},
Expand Down

0 comments on commit 17f2aec

Please sign in to comment.