From 1e2e92215797dc14ad8baaea07864d78503142e1 Mon Sep 17 00:00:00 2001 From: Sylvain Baubeau Date: Thu, 12 Nov 2026 16:16:00 +0100 Subject: [PATCH] Enable DD_NO_SECURITY_AGENT_INSTALL by default Run CWS and CSPM in system-probe instead of the security Agent by default when installing Agent 7.77.0 or later, or the latest version. 7.77.0 is the first version where the security Agent stops when both CWS and CSPM run in system-probe. - DD_NO_SECURITY_AGENT_INSTALL=false keeps the security Agent - any other value forces it, even for older versions - the default is resolved after the minor version may have been lowered for old distributions (7.51 / 7.35) CSPM enabled by a previous installation is usually only configured in security-agent.yaml, which is now told to stop running it. Detect it there and enable it in datadog.yaml so that system-probe runs it, even when DD_COMPLIANCE_CONFIG_ENABLED is not set again. The security Agent e2e tests now set DD_NO_SECURITY_AGENT_INSTALL=false, and the no security Agent e2e test relies on the default. Also fix shellcheck SC2329 in localtest.sh, reported by shellcheck 0.11. --- README.md | 6 +-- install_script.sh.template | 47 ++++++++++++++++++--- test/e2e/install_compliance_agent_test.go | 2 +- test/e2e/install_maximal_and_replay_test.go | 4 +- test/e2e/install_no_security_agent_test.go | 2 +- test/e2e/install_security_agent_test.go | 2 +- test/localtest.sh | 2 +- unit_tests/test_install_script.sh | 41 ++++++++++++++++++ 8 files changed, 91 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index e3095f13..83090316 100644 --- a/README.md +++ b/README.md @@ -34,9 +34,9 @@ The install script allows installation of different flavors of the Agent binarie |`DD_APM_INSTRUMENTATION_LIBRARIES`|Specify the APM library to be installed. Possible values are `all`, `java`, `js`, `python`, `dotnet` and `ruby`. Does not run the APM injection script, which is triggered by `DD_APM_INSTRUMENTATION_ENABLED` or `DD_APM_INSTRUMENTATION_STRICT`.| |`DD_APM_ERROR_TRACKING_STANDALONE`|Enable Error Tracking standalone for backend services.| |`DD_SYSTEM_PROBE_ENSURE_CONFIG`|Create the system probe configuration file from a template if it does not already exist.| -|`DD_RUNTIME_SECURITY_CONFIG_ENABLED`|If set to `true`, ensure creation of security Agent and system probe configuration file (if they don't already exist), and enable Cloud Workload Security (CWS).| -|`DD_COMPLIANCE_CONFIG_ENABLED`|If set to `true`, ensures the creation of a security Agent configuration file if one doesn't already exist, and enables Cloud Security Posture Management (CSPM).| -|`DD_NO_SECURITY_AGENT_INSTALL`|Set to any value to run Cloud Workload Security (CWS) and Cloud Security Posture Management (CSPM) in the system probe instead of the security Agent. With `DD_RUNTIME_SECURITY_CONFIG_ENABLED=true`, CWS is enabled in the system probe configuration file, which also sends the events directly. With `DD_COMPLIANCE_CONFIG_ENABLED=true`, CSPM is enabled in the Agent configuration file and runs in the system probe. The security Agent configuration file is never created, but if it already exists it is updated to tell the security Agent that CWS and CSPM run in the system probe, so that it stops. These settings are applied even when the configuration files are kept from a previous installation.| +|`DD_RUNTIME_SECURITY_CONFIG_ENABLED`|If set to `true`, ensure creation of security Agent and system probe configuration file (if they don't already exist), and enable Cloud Workload Security (CWS). The security Agent configuration file is not created when CWS runs in the system probe, see `DD_NO_SECURITY_AGENT_INSTALL`.| +|`DD_COMPLIANCE_CONFIG_ENABLED`|If set to `true`, ensures the creation of a security Agent configuration file if one doesn't already exist, and enables Cloud Security Posture Management (CSPM). The security Agent configuration file is not created when CSPM runs in the system probe, see `DD_NO_SECURITY_AGENT_INSTALL`.| +|`DD_NO_SECURITY_AGENT_INSTALL`|Run Cloud Workload Security (CWS) and Cloud Security Posture Management (CSPM) in the system probe instead of the security Agent. Enabled by default when installing Agent 7.77.0 or later (including the latest version). Set to `false` to keep running CWS and CSPM in the security Agent, or to any other value to force it for older versions. With `DD_RUNTIME_SECURITY_CONFIG_ENABLED=true`, CWS is enabled in the system probe configuration file, which also sends the events directly. With `DD_COMPLIANCE_CONFIG_ENABLED=true`, CSPM is enabled in the Agent configuration file and runs in the system probe. The security Agent configuration file is never created, but if it already exists it is updated to tell the security Agent that CWS and CSPM run in the system probe, so that it stops. These settings are applied even when the configuration files are kept from a previous installation.| |`DD_DISCOVERY_ENABLED`|If set to `true`, and a system probe configuration file does not already exist, creates a system probe configuration file and enables Service Discovery. |`DD_PRIVILEGED_LOGS_ENABLED`|If set to `true`, and a system probe configuration file does not already exist, creates a system probe configuration file and enables Privileged Logs. |`DD_SYSTEM_PROBE_SERVICE_MONITORING_ENABLED`|If set to `true`, and a system probe configuration file does not already exist, creates a system probe configuration file and enables Universal Service Monitoring (USM). diff --git a/install_script.sh.template b/install_script.sh.template index 354f57b4..2f79c5da 100644 --- a/install_script.sh.template +++ b/install_script.sh.template @@ -964,11 +964,6 @@ if [ -n "$DD_NO_AGENT_INSTALL" ]; then no_agent=true fi -no_security_agent= -if [ -n "$DD_NO_SECURITY_AGENT_INSTALL" ]; then - no_security_agent=true -fi - infrastructure_mode= if [ -n "$DD_INFRASTRUCTURE_MODE" ]; then infrastructure_mode=$DD_INFRASTRUCTURE_MODE @@ -2382,12 +2377,47 @@ EOF printf "\033[34m\n* Setting $section.$option to $value in $config_file\n\033[0m\n" $sudo_cmd sh -c "sed -i '0,/^$section:/s//$section:\n${indent:- }$option: $value/' $config_file" } +function is_config_option_true(){ + local sudo_cmd="$1" + local config_file="$2" + local section="$3" + local option="$4" + $sudo_cmd test -e "$config_file" || return 1 + # Only consider the keys at the first indentation level of the section, see set_config_option + local section_content indent + section_content=$($sudo_cmd sed -n "/^$section:/,/^[^[:space:]#]/p" "$config_file") + indent=$(echo "$section_content" | grep -E "^[[:space:]]+[^[:space:]#]" | head -n 1 | sed -E "s/^([[:space:]]+).*/\1/") + [ -n "$indent" ] && echo "$section_content" | grep -qiE "^${indent}${option}:[[:space:]]*true[[:space:]]*(#.*)?$" +} +function resolve_no_security_agent(){ + local no_security_agent_install="$1" + local agent_major_version="$2" + local agent_minor_version="$3" + # Explicitly set: "false" keeps the security Agent, any other value runs CWS and CSPM in system-probe + if [ "$no_security_agent_install" == "false" ]; then + return + elif [ -n "$no_security_agent_install" ]; then + echo "true" + return + fi + # By default, CWS and CSPM run in system-probe when the Agent supports it, starting with 7.77.0 + local minor_without_patch="${agent_minor_version%%.*}" + if [ "$agent_major_version" == "7" ] && { [ -z "$minor_without_patch" ] || [ "$minor_without_patch" -ge 77 ] 2>/dev/null; }; then + echo "true" + fi +} function run_security_in_system_probe(){ local sudo_cmd="$1" local core_config_file="$2" local security_config_file="$3" local probe_config_file="$4" local enable_compliance="$5" + # CSPM enabled by a previous installation is usually only configured in the security Agent + # configuration file, which stops running it below, so it has to be enabled in the Agent + # configuration file for system-probe to run it + if is_config_option_true "$sudo_cmd" "$security_config_file" "compliance_config" "enabled"; then + enable_compliance="true" + fi # The security Agent service starts as soon as its configuration file exists, so it needs to # know that both CWS and CSPM run in system-probe to stop right away. The file is only updated # when it already exists, it must never be created. @@ -2496,6 +2526,11 @@ function manage_otel_config(){ $sudo_cmd sh -c "sed -i -e 's/\${env:DD_API_KEY}/$apikey/' -e 's/\${env:DD_SITE}/$site/' $otel_config_file" fi } +# Run CWS and CSPM in system-probe instead of the security Agent, unless +# DD_NO_SECURITY_AGENT_INSTALL=false or the installed Agent doesn't support it. +# Resolved here because the minor version may be lowered on old distributions. +no_security_agent=$(resolve_no_security_agent "$DD_NO_SECURITY_AGENT_INSTALL" "$agent_major_version" "$clean_agent_minor_version") + # "Main" configuration update if [ -e "$config_file" ] && [ -z "$upgrade" ]; then printf "\033[34m\n* Keeping old $config_file configuration file\n\033[0m\n" @@ -2565,7 +2600,7 @@ if [ -n "$system_probe_ensure_config" ]; then ensure_config_file_exists "$sudo_cmd" "$system_probe_config_file" "root" fi -# Make sure the security Agent doesn't run when DD_NO_SECURITY_AGENT_INSTALL is set, even when +# Make sure the security Agent doesn't run when CWS and CSPM run in system-probe, even when # the configuration files were kept from a previous installation if [ -n "$no_security_agent" ]; then run_security_in_system_probe "$sudo_cmd" "$config_file" "$security_agent_config_file" "$system_probe_config_file" "$DD_COMPLIANCE_CONFIG_ENABLED" diff --git a/test/e2e/install_compliance_agent_test.go b/test/e2e/install_compliance_agent_test.go index e449180e..9d9acb7d 100644 --- a/test/e2e/install_compliance_agent_test.go +++ b/test/e2e/install_compliance_agent_test.go @@ -35,7 +35,7 @@ func TestInstallComplianceAgentSuite(t *testing.T) { } func (s *installComplianceAgentTestSuite) TestInstallComplianceAgent() { - s.InstallAgent(7, "DD_COMPLIANCE_CONFIG_ENABLED=true DD_SITE=\"datadoghq.com\"", "Install latest Agent 7") + s.InstallAgent(7, "DD_NO_SECURITY_AGENT_INSTALL=false DD_COMPLIANCE_CONFIG_ENABLED=true DD_SITE=\"datadoghq.com\"", "Install latest Agent 7") s.assertInstallScript() diff --git a/test/e2e/install_maximal_and_replay_test.go b/test/e2e/install_maximal_and_replay_test.go index 92cca0c7..012270a1 100644 --- a/test/e2e/install_maximal_and_replay_test.go +++ b/test/e2e/install_maximal_and_replay_test.go @@ -52,13 +52,13 @@ func TestInstallMaximalAndRetrySuite(t *testing.T) { } func (s *installMaximalAndRetryTestSuite) TestInstallMaximalAndReplayScript() { - output := s.InstallAgent(7, "DD_TAGS=\"foo:bar,baz:toto\" DD_ENV=kiki DD_HOSTNAME=totoro DD_RUNTIME_SECURITY_CONFIG_ENABLED=true DD_COMPLIANCE_CONFIG_ENABLED=true DD_SITE=\"mysite.com\" DD_URL=myintake.com", "install agent 7 with maximal environment variables") + output := s.InstallAgent(7, "DD_TAGS=\"foo:bar,baz:toto\" DD_ENV=kiki DD_HOSTNAME=totoro DD_NO_SECURITY_AGENT_INSTALL=false DD_RUNTIME_SECURITY_CONFIG_ENABLED=true DD_COMPLIANCE_CONFIG_ENABLED=true DD_SITE=\"mysite.com\" DD_URL=myintake.com", "install agent 7 with maximal environment variables") s.assertInstallMaximal(output) s.addExtraIntegration() - output = s.InstallAgent(7, "DD_TAGS=\"john:doe,john:lennon\" DD_ENV=totoro DD_HOSTNAME=kiki DD_RUNTIME_SECURITY_CONFIG_ENABLED=true DD_COMPLIANCE_CONFIG_ENABLED=true DD_SITE=darthmaul.com DD_URL=otherintake.com", "install Agent 7 RC again with new environment variables") + output = s.InstallAgent(7, "DD_TAGS=\"john:doe,john:lennon\" DD_ENV=totoro DD_HOSTNAME=kiki DD_NO_SECURITY_AGENT_INSTALL=false DD_RUNTIME_SECURITY_CONFIG_ENABLED=true DD_COMPLIANCE_CONFIG_ENABLED=true DD_SITE=darthmaul.com DD_URL=otherintake.com", "install Agent 7 RC again with new environment variables") s.assertRetryInstall(output) diff --git a/test/e2e/install_no_security_agent_test.go b/test/e2e/install_no_security_agent_test.go index e647a21c..4a0b6aaf 100644 --- a/test/e2e/install_no_security_agent_test.go +++ b/test/e2e/install_no_security_agent_test.go @@ -35,7 +35,7 @@ func TestInstallNoSecurityAgentSuite(t *testing.T) { } func (s *installNoSecurityAgentTestSuite) TestInstallNoSecurityAgent() { - s.InstallAgent(7, "DD_NO_SECURITY_AGENT_INSTALL=true DD_RUNTIME_SECURITY_CONFIG_ENABLED=true DD_COMPLIANCE_CONFIG_ENABLED=true DD_SITE=\"datadoghq.com\"", "Install latest Agent 7 without the security agent") + s.InstallAgent(7, "DD_RUNTIME_SECURITY_CONFIG_ENABLED=true DD_COMPLIANCE_CONFIG_ENABLED=true DD_SITE=\"datadoghq.com\"", "Install latest Agent 7, without the security agent by default") s.assertInstallScript() diff --git a/test/e2e/install_security_agent_test.go b/test/e2e/install_security_agent_test.go index 181a947a..2baf4d1f 100644 --- a/test/e2e/install_security_agent_test.go +++ b/test/e2e/install_security_agent_test.go @@ -35,7 +35,7 @@ func TestInstallSecurityAgentSuite(t *testing.T) { } func (s *installSecurityAgentTestSuite) TestInstallSecurityAgent() { - s.InstallAgent(7, "DD_RUNTIME_SECURITY_CONFIG_ENABLED=true DD_SITE=\"datadoghq.com\"", "Install latest Agent 7 ") + s.InstallAgent(7, "DD_NO_SECURITY_AGENT_INSTALL=false DD_RUNTIME_SECURITY_CONFIG_ENABLED=true DD_SITE=\"datadoghq.com\"", "Install latest Agent 7 ") s.assertInstallScript() diff --git a/test/localtest.sh b/test/localtest.sh index 5f78ec8a..71d754f2 100755 --- a/test/localtest.sh +++ b/test/localtest.sh @@ -33,7 +33,7 @@ fi # Override curl to capture trace payloads (only if SHOW_TRACE is enabled) if [[ "${SHOW_TRACE}" == "1" ]]; then - # shellcheck disable=SC2317 + # shellcheck disable=SC2317,SC2329 curl() { if [[ "$*" == *"instrumentation-telemetry-intake"* ]]; then echo "[TRACE CAPTURE] Intercepting telemetry submission" >&2 diff --git a/unit_tests/test_install_script.sh b/unit_tests/test_install_script.sh index 9a26a37b..598121e1 100755 --- a/unit_tests/test_install_script.sh +++ b/unit_tests/test_install_script.sh @@ -353,6 +353,26 @@ testSystemProbeConfigNetworkAlreadyConfigured(){ } ### DD_NO_SECURITY_AGENT_INSTALL +testResolveNoSecurityAgentDefault(){ + assertEquals "true" "$(resolve_no_security_agent "" 7 "")" + assertEquals "true" "$(resolve_no_security_agent "" 7 "77")" + assertEquals "true" "$(resolve_no_security_agent "" 7 "77.0")" + assertEquals "true" "$(resolve_no_security_agent "" 7 "78.1")" + assertEquals "true" "$(resolve_no_security_agent "" 7 "100.0")" +} +testResolveNoSecurityAgentDefaultUnsupportedVersion(){ + assertEquals "" "$(resolve_no_security_agent "" 7 "76.3")" + assertEquals "" "$(resolve_no_security_agent "" 7 "51")" + assertEquals "" "$(resolve_no_security_agent "" 6 "")" + assertEquals "" "$(resolve_no_security_agent "" 6 "77.0")" +} +testResolveNoSecurityAgentExplicit(){ + assertEquals "" "$(resolve_no_security_agent "false" 7 "")" + assertEquals "" "$(resolve_no_security_agent "false" 7 "78.0")" + assertEquals "true" "$(resolve_no_security_agent "true" 7 "")" + assertEquals "true" "$(resolve_no_security_agent "1" 7 "76.0")" + assertEquals "true" "$(resolve_no_security_agent "true" 6 "")" +} testNoSecurityAgentDoesNotCreateSecurityAgentConfig(){ sudo rm $security_agent_config_file 2> /dev/null manage_security_config "sudo" $security_agent_config_file true true true @@ -403,6 +423,27 @@ testRunSecurityInSystemProbeExistingSecurityAgentConfig(){ # CSPM is not enabled, the Agent configuration file must not be updated assertEquals "$(sudo yq eval '.compliance_config' $config_file)" "null" } +testRunSecurityInSystemProbeKeptSecurityAgentCompliance(){ + # CSPM enabled by a previous installation only in the security Agent configuration file must + # be enabled in the Agent configuration file, even without DD_COMPLIANCE_CONFIG_ENABLED + sudo cp ${config_file}.example $config_file + sudo rm $system_probe_config_file 2> /dev/null + printf 'compliance_config:\n enabled: true\n' | sudo tee $security_agent_config_file > /dev/null + run_security_in_system_probe "sudo" $config_file $security_agent_config_file $system_probe_config_file "" + yamllint -c "$yaml_config" --no-warnings $config_file + assertEquals 0 $? + assertEquals "$(sudo yq eval '.compliance_config.enabled' $config_file)" "true" + assertEquals "$(sudo yq eval '.compliance_config.run_in_system_probe' $config_file)" "true" + assertEquals "$(sudo yq eval '.compliance_config.run_in_system_probe' $security_agent_config_file)" "true" +} +testRunSecurityInSystemProbeKeptSecurityAgentComplianceDisabled(){ + # CSPM disabled, or only enabled in a nested section, must not be enabled + sudo cp ${config_file}.example $config_file + sudo rm $system_probe_config_file 2> /dev/null + printf 'compliance_config:\n enabled: false\n database_benchmarks:\n enabled: true\n' | sudo tee $security_agent_config_file > /dev/null + run_security_in_system_probe "sudo" $config_file $security_agent_config_file $system_probe_config_file "" + assertEquals "$(sudo yq eval '.compliance_config' $config_file)" "null" +} testRunSecurityInSystemProbeKeptConfiguration(){ # CWS and CSPM enabled by a previous installation must now run in system-probe printf 'apm_config:\n enabled: true\n' | sudo tee $config_file > /dev/null