Skip to content

Commit

Permalink
Fix runtime security volumes creation (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
clamoriniere committed Aug 25, 2021
1 parent 084c010 commit aa76649
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 8 additions & 2 deletions api/v1alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,12 +622,18 @@ func DefaultDatadogAgentSpecAgentApmUDS(apm *APMSpec) *APMUnixDomainSocketSpec {
// DefaultDatadogAgentSpecAgentSystemProbe defaults the System Probe
// This method can be re-run as part of the FeatureOverride
func DefaultDatadogAgentSpecAgentSystemProbe(agent *DatadogAgentSpecAgentSpec) *SystemProbeSpec {
sysOverride := &SystemProbeSpec{}

if agent.SystemProbe == nil {
agent.SystemProbe = &SystemProbeSpec{Enabled: NewBoolPointer(defaultSystemProbeEnabled)}
return agent.SystemProbe
sysOverride = agent.SystemProbe
}

if agent.Security != nil && BoolValue(agent.Security.Runtime.Enabled) {
agent.SystemProbe.Enabled = agent.Security.Runtime.Enabled
sysOverride = agent.SystemProbe
}

sysOverride := &SystemProbeSpec{}
if agent.SystemProbe.Enabled == nil {
agent.SystemProbe.Enabled = NewBoolPointer(defaultSystemProbeEnabled)
sysOverride.Enabled = agent.SystemProbe.Enabled
Expand Down
11 changes: 8 additions & 3 deletions controllers/datadogagent/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1237,15 +1237,20 @@ func getVolumesForAgent(dda *datadoghqv1alpha1.DatadogAgent) []corev1.Volume {
}
}

if isRuntimeSecurityEnabled(&dda.Spec) && dda.Spec.Agent.Security.Runtime.PoliciesDir != nil {
if isRuntimeSecurityEnabled(&dda.Spec) {
volumes = append(volumes,
getVolumeFromConfigDirSpec(datadoghqv1alpha1.SecurityAgentRuntimeCustomPoliciesVolumeName, dda.Spec.Agent.Security.Runtime.PoliciesDir),
corev1.Volume{
Name: datadoghqv1alpha1.SecurityAgentRuntimePoliciesDirVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
})

if dda.Spec.Agent.Security.Runtime.PoliciesDir != nil {
volumes = append(volumes,
getVolumeFromConfigDirSpec(datadoghqv1alpha1.SecurityAgentRuntimeCustomPoliciesVolumeName, dda.Spec.Agent.Security.Runtime.PoliciesDir),
)
}
}

volumes = append(volumes, dda.Spec.Agent.Config.Volumes...)
Expand Down Expand Up @@ -1768,7 +1773,7 @@ func getVolumeMountsForSecurityAgent(dda *datadoghqv1alpha1.DatadogAgent) []core
})
}

if runtimeEnabled {
if runtimeEnabled && isSystemProbeEnabled(&dda.Spec) {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: datadoghqv1alpha1.SystemProbeSocketVolumeName,
MountPath: datadoghqv1alpha1.SystemProbeSocketVolumePath,
Expand Down
2 changes: 2 additions & 0 deletions controllers/testutils/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func NewDatadogAgent(ns, name, image string, options *NewDatadogAgentOptions) *d

ad.Spec.Features.OrchestratorExplorer.Enabled = datadoghqv1alpha1.NewBoolPointer(false)
}
// options can have an impact on the defaulting
_ = datadoghqv1alpha1.DefaultDatadogAgent(ad)
}

return ad
Expand Down

0 comments on commit aa76649

Please sign in to comment.