Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CSPM] Add support for XCCDF benchmarks #15537

Merged
merged 13 commits into from
Apr 13, 2023
Merged

[CSPM] Add support for XCCDF benchmarks #15537

merged 13 commits into from
Apr 13, 2023

Conversation

0intro
Copy link
Member

@0intro 0intro commented Feb 10, 2023

What does this PR do?

This change adds support for XCCDF benchmarks in the pkg/compliance package.

XCCDF is an XML format specifying security benchmarks, which is part of the SCAP standards.

The XCCDF support relies on the OpenSCAP library.

Motivation

The goal was to implement support of CIS benchmarks for Linux operating systems into the Datadog Agent.

Instead of writing the checks ourselves, we chose to rely on the automated checks available as part of the ComplianceAsCode project. The checks are written in SCAP format and can be executed with the OpenSCAP library and tools.

Additional Notes

Possible Drawbacks / Trade-offs

The major drawback of including the OpenSCAP library is that it requires its own set of dependencies, adding 25 new software definitions to omnibus.

However, we tried to limit the size of the new dependencies, by removing the unnecessary files from the Agent installation, like documentation and static libraries. The total size of the newly installed shared libraries approximates 20 MB.

Describe how to test/QA your changes

Build for RHEL:

cd datadog-agent
docker run -v "$PWD:/go/src/github.com/DataDog/datadog-agent" -v "/tmp/omnibus:/omnibus" -v "/tmp/opt/datadog-agent:/opt/datadog-agent" -v"/tmp/gems:/gems" --workdir=/go/src/github.com/DataDog/datadog-agent datadog/agent-buildimages:deb-x64 inv -e agent.omnibus-build --base-dir=/omnibus --gem-path=/gems

Or build for Ubuntu:

cd datadog-agent
docker run -v "$PWD:/go/src/github.com/DataDog/datadog-agent" -v "/tmp/omnibus:/omnibus" -v "/tmp/opt/datadog-agent:/opt/datadog-agent" -v"/tmp/gems:/gems" --workdir=/go/src/github.com/DataDog/datadog-agent datadog-agent-buildimages:rpm-x64 inv -e agent.omnibus-build --base-dir=/omnibus --gem-path=/gems

Run RHEL 7, 8 or 9:

docker run -v "/tmp/opt:/opt" -v "/:/host" -it registry.access.redhat.com/ubi7/ubi /bin/bash

Or run Ubuntu 20.04 or 22.04:

docker run -v "/tmp/opt:/opt" -v "/:/host" -it ubuntu:22.04 /bin/bash

Remove the /.dockerenv file, so OpenSCAP doesn't know it's running in a container:

rm -f /.dockerenv

Install curl (on RHEL):

yum install curl -y

Or install curl (on Ubuntu):

apt update && apt install curl -y

Install CSPM rules:

mkdir -p /etc/datadog-agent/compliance.d
curl -Ls https://github.com/DataDog/security-agent-policies/archive/refs/heads/jinroh/cspm-scap-rules.tar.gz | tar xz --strip-components=3 -C /etc/datadog-agent/compliance.d -f - security-agent-policies-jinroh-cspm-scap-rules/compliance

Configure datadog-agent:

cat << EOF >/etc/datadog-agent/datadog.yaml
api_key: <api_key>
site: datad0g.com
hostname: test-xccdf

security_agent:
  remote_tagger: false

compliance_config:
  enabled: true
  dir: /etc/datadog-agent/compliance.d
  xccdf:
      enabled: true
EOF

Run the compliance checks from the security-agent, on docker:

/opt/datadog-agent/embedded/bin/security-agent -c /etc/datadog-agent/datadog.yaml start

Run the compliance checks from the security-agent, on the host's operating system:

DOCKER_DD_AGENT=true /opt/datadog-agent/embedded/bin/security-agent -c /etc/datadog-agent/datadog.yaml start

Go to the CSPM web page and verify that you can see the check results.

Reviewer's Checklist

  • If known, an appropriate milestone has been selected; otherwise the Triage milestone is set.
  • Use the major_change label if your change either has a major impact on the code base, is impacting multiple teams or is changing important well-established internals of the Agent. This label will be use during QA to make sure each team pay extra attention to the changed behavior. For any customer facing change use a releasenote.
  • A release note has been added or the changelog/no-changelog label has been applied.
  • Changed code has automated tests for its functionality.
  • Adequate QA/testing plan information is provided if the qa/skip-qa label is not applied.
  • At least one team/.. label has been applied, indicating the team(s) that should QA this change.
  • If applicable, docs team has been notified or an issue has been opened on the documentation repo.
  • If applicable, the need-change/operator and need-change/helm labels have been applied.
  • If applicable, the k8s/<min-version> label, indicating the lowest Kubernetes version compatible with this feature.
  • If applicable, the config template has been updated.

@0intro 0intro added this to the 7.44.0 milestone Feb 10, 2023
@0intro 0intro requested review from lebauce and jinroh February 10, 2023 14:09
@0intro 0intro requested review from a team as code owners February 10, 2023 14:09
@0intro 0intro force-pushed the ducolombier/cspm-xccdf branch 6 times, most recently from 533f5bc to f110a46 Compare February 13, 2023 12:42
@0intro 0intro requested a review from a team as a code owner February 13, 2023 12:42
@0intro 0intro force-pushed the ducolombier/cspm-xccdf branch 4 times, most recently from d510083 to e287995 Compare February 13, 2023 14:46
Copy link
Contributor

@maycmlee maycmlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion

releasenotes/notes/cspm-xccdf-3d6cefbaaaa117b5.yaml Outdated Show resolved Hide resolved
@0intro 0intro force-pushed the ducolombier/cspm-xccdf branch 5 times, most recently from ed31b76 to 102b219 Compare February 20, 2023 08:56
@0intro 0intro changed the title [CSPM] Add XCCDF based rule [CSPM] Add support for XCCDF benchmarks Feb 20, 2023
@0intro 0intro force-pushed the ducolombier/cspm-xccdf branch from 6937e1e to 12b27e4 Compare February 20, 2023 13:14
@jinroh jinroh force-pushed the ducolombier/cspm-xccdf branch from d351708 to a68ca04 Compare February 21, 2023 14:40
@0intro 0intro force-pushed the ducolombier/cspm-xccdf branch 2 times, most recently from b48e453 to de15e83 Compare February 22, 2023 08:21
Copy link
Contributor

@bkabrda bkabrda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 the PR mostly looks good, I left couple points inline to address/talk about. In addition, we need to add the ship_source_offer true line to all the new GPL/LGPL software.

omnibus/config/software/apt.rb Outdated Show resolved Hide resolved
patch source: "disable_systemd.patch", env: env
patch source: "cmake-bindir.patch", env: env

if (!File.exist? '/usr/bin/triehash') && (!File.exist? '/usr/local/bin/triehash')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the triehash file something that we should add to our buildimages longer term? Again, this is not something I see as a blocker, but it looks like a build dependency that won't change (often) and could live there - it's not part of the distributed agent, correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

triehash is a build time dependency for building APT.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, so eventually it would be great to move it to buildimages, rather than have it in this repository.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question was raised at some point, but I finally preferred to install triehash as part of the apt build, since it's only used to build apt. My feeling was that the build images had a more general purpose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reopened the PR with only the triehash relevant bits : DataDog/datadog-agent-buildimages#378

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening the PR! Because we're a bit short on time, I'll approve this PR with triehash file included and ask you to, later on, upgrade the buildimages and remove the file from here in a followup PR.

omnibus/config/software/datadog-agent.rb Outdated Show resolved Hide resolved
@0intro 0intro force-pushed the ducolombier/cspm-xccdf branch 2 times, most recently from e013b3a to 8b80ad0 Compare April 12, 2023 12:42
@lebauce lebauce force-pushed the ducolombier/cspm-xccdf branch from a2236d8 to 61f7b31 Compare April 12, 2023 15:48
@0intro 0intro force-pushed the ducolombier/cspm-xccdf branch from 12679c4 to 173ec29 Compare April 13, 2023 08:48
@0intro 0intro force-pushed the ducolombier/cspm-xccdf branch from 173ec29 to 989fb4d Compare April 13, 2023 12:24
@pr-commenter
Copy link

pr-commenter bot commented Apr 13, 2023

Bloop Bleep... Dogbot Here

Regression Detector Results

Run ID: 348b99dc-ceaf-418d-bd8a-387a7fca4d83
Baseline: c7f38ca
Comparison: 40d433c
Total datadog-agent CPUs: 7

Explanation

A regression test is an integrated performance test for datadog- agent in a repeatable rig, with varying configuration for datadog- agent. What follows is a statistical summary of a brief datadog- agent run for each configuration across SHAs given above. The goal of these tests are to determine quickly if datadog-agent performance is changed and to what degree by a pull request.

The table below, if present, lists those experiments that have experienced a statistically significant change in mean optimization goal performance between baseline and comparison SHAs with 90.00% confidence OR have been detected as newly erratic. Negative values mean that baseline is faster, positive comparison. Results that do not exhibit more than a ±5.00% change in their mean optimization goal are discarded. An experiment is erratic if its coefficient of variation is greater than 0.1. The abbreviated table will be omitted if no interesting change is observed.

No interesting changes in experiment optimization goals with confidence ≥ 90.00% and |Δ mean %| ≥ 5.00%.

Fine details of change detection per experiment.
experiment goal Δ mean Δ mean % confidence baseline mean baseline stdev baseline stderr baseline outlier % baseline CoV comparison mean comparison stdev comparison stderr comparison outlier % comparison CoV erratic declared erratic
uds_dogstatsd_to_api ingress throughput 3.02KiB/CPU-s 2.06 97.81% 146.88KiB/CPU-s 70.05KiB/CPU-s 923.05B/CPU-s 0.0 0.47688 149.9KiB/CPU-s 74.83KiB/CPU-s 986.26B/CPU-s 0.0 0.499134 True False
tcp_syslog_to_blackhole ingress throughput 37.59KiB/CPU-s 0.49 100.00% 7.43MiB/CPU-s 281.34KiB/CPU-s 3.63KiB/CPU-s 0.0 0.036988 7.46MiB/CPU-s 307.96KiB/CPU-s 3.97KiB/CPU-s 0.0 0.040289 False False
file_to_blackhole egress throughput 2.5B/CPU-s 0.24 32.96% 1.01KiB/CPU-s 121.19B/CPU-s 4.25B/CPU-s 0.0 0.117668 1.01KiB/CPU-s 115.48B/CPU-s 4.06B/CPU-s 0.0 0.111855 True False
tcp_dd_logs_filter_exclude ingress throughput 34.06KiB/CPU-s 0.12 86.04% 27.92MiB/CPU-s 1.31MiB/CPU-s 17.36KiB/CPU-s 0.0 0.047065 27.95MiB/CPU-s 1.15MiB/CPU-s 15.17KiB/CPU-s 0.0 0.041066 False False
otel_to_otel_logs ingress throughput -8.19MiB/CPU-s -2.38 100.00% 343.41MiB/CPU-s 17.67MiB/CPU-s 233.37KiB/CPU-s 0.0 0.051438 335.23MiB/CPU-s 18.94MiB/CPU-s 250.19KiB/CPU-s 0.0 0.056489 False False

@lebauce lebauce force-pushed the ducolombier/cspm-xccdf branch 3 times, most recently from 3366def to 76a6746 Compare April 13, 2023 17:14
@0intro 0intro force-pushed the ducolombier/cspm-xccdf branch from 76a6746 to 8ab82b8 Compare April 13, 2023 19:14
lebauce and others added 13 commits April 13, 2023 22:44
OpenSCSAP is an implementation of the SCAP standards.
It provides tools and libraries to handle SCAP documents.

This change adds the following software definitions:

 - apt
 - attr
 - elfutils
 - file
 - glib
 - gmp
 - gnutls
 - libacl
 - libdb
 - libgcrypt
 - libgpg-error
 - liblz4
 - libselinux
 - libsepol
 - libtasn1
 - libxxhash
 - lua
 - m4
 - nettle
 - openscap
 - pcre2
 - popt
 - rpm
 - sqlite
 - util-linux
 - xmlsec
 - zstd

Some patches were required:

 - apt/cmake-bindir.patch: allow to update BIN_DIR CMake CACHE entry
 - apt/disable_arch_check.patch: disable architecture check
 - apt/disable_systemd.patch: remove dependency on udev and systemd
 - apt/no_doc.patch: don't install documentation
 - apt/triehash.patch: add the triehash tool, needed at build time
 - libselinux/fcntl_o_path.patch: fix build with old glibc
 - libselinux/ln_no_relative.patch: don't use relative symlink on installed libraries
 - libsepol/ln_no_relative.patch: don't use relative symlink on installed libraries
 - lua/nodoc.patch: don't install documentation
 - nettle/install_to_lib.patch: omit lib directory suffix
 - rpm/0001-Include-fcntl.patch: fix build

OpenSCAP includes a number of fixes, backported from maint-1.3
branch and also some fixes which are currently being reviewed.

We added -I. before -I#{install_dir}/embedded/include in CGO_CFLAGS,
so the Go zstd package use its own zstd.h instead of using the one
provided by the newly added zstd software.

This change is the result of a collaborative work between
Sylvain Baubeau, Pierre Guilleminot and David du Colombier.

Co-authored-by: Sylvain Baubeau <[email protected]>
Co-authored-by: Pierre Guilleminot <[email protected]>
This change adds support for XCCDF benchmarks in the pkg/compliance
package.

XCCDF is an XML format specifying security benchmarks, which is part
of the SCAP standards.

The XCCDF support relies on the OpenSCAP library, which is provided
as part of a previous change.

The XCCDF files should be located into the compliance directory,
specified by the "compliance_config.dir" configuration option.

Support of XCCDF benchmark is disabled by default, and can be
enabled by setting the new "compliance_config.xccdf.enabled"
configuration option.

This change is the result of a collaborative work between
Sylvain Baubeau, Pierre Guilleminot and David du Colombier.

Co-authored-by: Pierre Guilleminot <[email protected]>
Co-authored-by: David du Colombier <[email protected]>
This change removes the implementation of XCCDF which relies
on the OpenSCAP library. Instead we use xccdf_no_cgo.go,
which relies on the OpenSCAP tool. This prevents the Agent
to link with OpenSCAP and its dependencies.
@0intro 0intro force-pushed the ducolombier/cspm-xccdf branch from 8ab82b8 to 40d433c Compare April 13, 2023 20:44
@0intro
Copy link
Member Author

0intro commented Apr 13, 2023

The macos_test job is failing on:

 # github.com/DataDog/datadog-agent/pkg/network/encoding [github.com/DataDog/datadog-agent/pkg/network/encoding.test]
pkg/network/encoding/http.go:87:31: undefined: network.ConnectionKeysFromConnectionStats
pkg/network/encoding/http.go:102:28: undefined: network.ConnectionKeysFromConnectionStats
pkg/network/encoding/http2.go:45:28: undefined: network.ConnectionKeysFromConnectionStats
pkg/network/encoding/http2.go:101:31: undefined: network.ConnectionKeysFromConnectionStats
pkg/network/encoding/kafka.go:80:31: undefined: network.ConnectionKeysFromConnectionStats
pkg/network/encoding/kafka.go:94:28: undefined: network.ConnectionKeysFromConnectionStats

Which seems to be related to PR #16220.

@0intro 0intro merged commit fd11023 into main Apr 13, 2023
@0intro 0intro deleted the ducolombier/cspm-xccdf branch April 13, 2023 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants