Skip to content

Commit 60007ef

Browse files
dd-octo-sts[bot]matt-dzclaudetbavelierlevan-m
authored
Add host volume mounts and NET_RAW capability to PAR container (#2799) (#2828)
* Add host volume mounts to Private Action Runner container Mount /var/log, /etc/os-release, and /proc from the host into the PAR container under /host as read-only volumes. This enables the PAR to inspect host-level logs, OS information, and process data. * Add PAR host volumes only when PAR container is required Move host-varlog and host-osrelease volumes from the base volumesForAgent list into a conditional block gated on PrivateActionRunnerContainerName, mirroring the existing SystemProbe pattern. This prevents unused HostPath volumes from being added to every Agent pod, which can cause admission failures in environments enforcing HostPath allowlists. * style: format files * Add NET_RAW capability to PAR container The Private Action Runner container needs the NET_RAW capability to perform network operations on the host. * Move PAR host volumes, mounts, and NET_RAW to feature code Volumes, mounts, and capabilities should be managed by the feature system, not hardcoded in component defaults. This moves host volume mounts (/proc, /etc/os-release, /var/log) and the NET_RAW capability from default.go into the PAR feature's ManageNodeAgent(), following the same pattern used by logcollection, npm, and other features. * Add generic HostOSRelease aliases for os-release volume constants The SystemProbeOSReleaseDirVolumeName constants are semantically tied to system-probe despite being general-purpose. Add generic aliases (HostOSReleaseVolumeName, HostOSReleaseHostPath, HostOSReleaseMountPath) and use them in PAR feature code and volume helpers so that privateactionrunner does not reference system-probe constants. * Use standalone values for HostOSRelease constants Define HostOSRelease constants with their own literal values instead of aliasing the SystemProbe variants. * Move host volume constants to PAR package, remove unused common helpers Host volume constants (varlog, os-release, proc) are only used by the PAR feature, so they belong in the PAR package as unexported constants. Remove the now-unused GetVolumeForHostVarLog, GetVolumeMountForHostVarLog, GetVolumeForOSRelease, GetVolumeMountForOSRelease helpers and their corresponding exported constants from common. * revert const.go * Reuse existing common constants for procdir and os-release volumes The procdir and os-release volume constants already exist in common/const.go. Remove the duplicates from PAR's const.go and reference the common ones directly. * Add host volumes individually instead of loop Replace loop-based volume addition with individual volume.GetVolumes() calls per volume, matching the pattern used by npm and other features for better readability. --------- (cherry picked from commit 8c060c4) Co-authored-by: Matthew DeGuzman <91019033+matt-dz@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Timothée Bavelier <97530782+tbavelier@users.noreply.github.com> Co-authored-by: levan-m <116471169+levan-m@users.noreply.github.com>
1 parent c7eb86e commit 60007ef

3 files changed

Lines changed: 61 additions & 8 deletions

File tree

internal/controller/datadogagent/feature/privateactionrunner/const.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ const (
1111
privateActionRunnerVolumeNameSuffix = "privateactionrunner-config"
1212
privateActionRunnerFileName = "privateactionrunner.yaml"
1313
privateActionRunnerSuffix = "private-action-runner"
14+
15+
hostVarLogVolumeName = "host-varlog"
16+
hostVarLogHostPath = "/var/log"
17+
hostVarLogMountPath = "/host/var/log"
1418
)

internal/controller/datadogagent/feature/privateactionrunner/feature.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common"
1616
"github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1"
1717
apiutils "github.com/DataDog/datadog-operator/api/utils"
18+
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/common"
1819
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature"
1920
featureutils "github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/utils"
2021
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/object"
@@ -293,6 +294,27 @@ func (f *privateActionRunnerFeature) ManageNodeAgent(managers feature.PodTemplat
293294
}
294295
managers.Annotation().AddAnnotation(checksumKey, checksumValue)
295296

297+
// procdir volume mount
298+
procdirVol, procdirVolMount := volume.GetVolumes(common.ProcdirVolumeName, common.ProcdirHostPath, common.ProcdirMountPath, true)
299+
managers.Volume().AddVolume(&procdirVol)
300+
managers.VolumeMount().AddVolumeMountToContainer(&procdirVolMount, apicommon.PrivateActionRunnerContainerName)
301+
302+
// os-release volume mount
303+
osReleaseVol, osReleaseVolMount := volume.GetVolumes(common.SystemProbeOSReleaseDirVolumeName, common.SystemProbeOSReleaseDirVolumePath, common.SystemProbeOSReleaseDirMountPath, true)
304+
managers.Volume().AddVolume(&osReleaseVol)
305+
managers.VolumeMount().AddVolumeMountToContainer(&osReleaseVolMount, apicommon.PrivateActionRunnerContainerName)
306+
307+
// host var log volume mount
308+
varLogVol, varLogVolMount := volume.GetVolumes(hostVarLogVolumeName, hostVarLogHostPath, hostVarLogMountPath, true)
309+
managers.Volume().AddVolume(&varLogVol)
310+
managers.VolumeMount().AddVolumeMountToContainer(&varLogVolMount, apicommon.PrivateActionRunnerContainerName)
311+
312+
// Add NET_RAW capability for network operations
313+
managers.SecurityContext().AddCapabilitiesToContainer(
314+
[]corev1.Capability{"NET_RAW"},
315+
apicommon.PrivateActionRunnerContainerName,
316+
)
317+
296318
return nil
297319
}
298320

internal/controller/datadogagent/feature/privateactionrunner/feature_test.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
apicommon "github.com/DataDog/datadog-operator/api/datadoghq/common"
1818
"github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1"
19+
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/common"
1920
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature"
2021
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/feature/fake"
2122
"github.com/DataDog/datadog-operator/internal/controller/datadogagent/object"
@@ -105,23 +106,49 @@ func Test_privateActionRunnerFeature_ManageNodeAgent(t *testing.T) {
105106
err := f.ManageNodeAgent(managers, "")
106107
assert.NoError(t, err)
107108

108-
// Verify volume is mounted
109+
// Verify volumes (1 configmap + 3 host volumes)
109110
volumes := managers.VolumeMgr.Volumes
110-
assert.Len(t, volumes, 1, "Should have exactly one volume")
111-
vol := volumes[0]
112-
assert.Equal(t, "test-dda-privateactionrunner-config", vol.Name, "Volume name should match")
113-
assert.NotNil(t, vol.VolumeSource.ConfigMap, "Volume should be a ConfigMap volume")
114-
assert.Equal(t, "test-dda-privateactionrunner", vol.VolumeSource.ConfigMap.Name, "ConfigMap name should match")
111+
assert.Len(t, volumes, 4)
112+
assert.Equal(t, "test-dda-privateactionrunner-config", volumes[0].Name, "Volume name should match")
113+
assert.NotNil(t, volumes[0].VolumeSource.ConfigMap, "Volume should be a ConfigMap volume")
114+
assert.Equal(t, "test-dda-privateactionrunner", volumes[0].VolumeSource.ConfigMap.Name, "ConfigMap name should match")
115+
116+
volumeNames := make(map[string]bool)
117+
for _, v := range volumes {
118+
volumeNames[v.Name] = true
119+
}
120+
assert.True(t, volumeNames[common.ProcdirVolumeName])
121+
assert.True(t, volumeNames[common.SystemProbeOSReleaseDirVolumeName])
122+
assert.True(t, volumeNames[hostVarLogVolumeName])
115123

116-
// Verify volume mount
124+
// Verify volume mounts (1 configmap + 3 host mounts)
117125
volumeMounts := managers.VolumeMountMgr.VolumeMountsByC[apicommon.PrivateActionRunnerContainerName]
118-
assert.Len(t, volumeMounts, 1, "Should have exactly one volume mount")
126+
assert.Len(t, volumeMounts, 4)
119127
mount := volumeMounts[0]
120128
assert.Equal(t, "test-dda-privateactionrunner-config", mount.Name, "Mount name should match")
121129
assert.Equal(t, "/etc/datadog-agent/privateactionrunner.yaml", mount.MountPath, "Mount path should be the hardcoded path")
122130
assert.Equal(t, "privateactionrunner.yaml", mount.SubPath, "SubPath should mount the file directly")
123131
assert.True(t, mount.ReadOnly, "Mount should be read-only")
124132

133+
mountNames := make(map[string]bool)
134+
for _, m := range volumeMounts {
135+
mountNames[m.Name] = true
136+
}
137+
assert.True(t, mountNames[common.ProcdirVolumeName])
138+
assert.True(t, mountNames[common.SystemProbeOSReleaseDirVolumeName])
139+
assert.True(t, mountNames[hostVarLogVolumeName])
140+
141+
// Verify host mounts are read-only
142+
for _, m := range volumeMounts {
143+
if m.Name == common.ProcdirVolumeName || m.Name == common.SystemProbeOSReleaseDirVolumeName || m.Name == hostVarLogVolumeName {
144+
assert.True(t, m.ReadOnly, "mount %s should be read-only", m.Name)
145+
}
146+
}
147+
148+
// Verify NET_RAW capability
149+
capabilities := managers.SecurityContextMgr.CapabilitiesByC[apicommon.PrivateActionRunnerContainerName]
150+
assert.Contains(t, capabilities, corev1.Capability("NET_RAW"))
151+
125152
// Verify hash
126153
assert.NotEmpty(t, managers.AnnotationMgr.Annotations)
127154
assert.NotEmpty(t, managers.AnnotationMgr.Annotations["checksum/private_action_runner-custom-config"])

0 commit comments

Comments
 (0)