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

[NPM-3662] Add sestatus to agent flare #32068

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions cmd/system-probe/api/debug/handlers_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

//go:build linux

// Package debug contains handlers for debug information global to all of system-probe
package debug

import (
"errors"
"fmt"
"net/http"
"os/exec"
)

// HandleSelinuxSestatus reports the output of sestatus as an http result
func HandleSelinuxSestatus(w http.ResponseWriter, _ *http.Request) {
cmd := exec.Command("sestatus")
output, err := cmd.CombinedOutput()
// don't report ExitErrors since we are using the combined output which will already include stderr
if err != nil && !errors.Is(err, &exec.ExitError{}) {
fmt.Fprintf(w, "sestatus command failed: %s", err)
return
}

w.Write(output)
}
20 changes: 20 additions & 0 deletions cmd/system-probe/api/debug/handlers_nolinux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2024-present Datadog, Inc.

//go:build !linux

// Package debug contains handlers for debug information global to all of system-probe
package debug

import (
"io"
"net/http"
)

// HandleSelinuxSestatus is not supported
func HandleSelinuxSestatus(w http.ResponseWriter, _ *http.Request) {
io.WriteString(w, "HandleSelinuxSestatus is not supported on this platform")
w.WriteHeader(500)
}
2 changes: 2 additions & 0 deletions cmd/system-probe/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

gorilla "github.com/gorilla/mux"

"github.com/DataDog/datadog-agent/cmd/system-probe/api/debug"
"github.com/DataDog/datadog-agent/cmd/system-probe/api/module"
"github.com/DataDog/datadog-agent/cmd/system-probe/api/server"
sysconfigtypes "github.com/DataDog/datadog-agent/cmd/system-probe/config/types"
Expand Down Expand Up @@ -58,6 +59,7 @@ func StartServer(cfg *sysconfigtypes.Config, telemetry telemetry.Component, wmet

if runtime.GOOS == "linux" {
mux.HandleFunc("/debug/ebpf_btf_loader_info", ebpf.HandleBTFLoaderInfo)
mux.HandleFunc("/debug/selinux_sestatus", debug.HandleSelinuxSestatus)
}

go func() {
Expand Down
5 changes: 2 additions & 3 deletions pkg/ebpf/debug_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
package ebpf

import (
"fmt"
"io"
"net/http"

"github.com/DataDog/datadog-agent/pkg/util/log"
)

// HandleBTFLoaderInfo responds with where the system-probe found BTF data (and
// if it was in a pre-bundled tarball, where within that tarball it came from)
func HandleBTFLoaderInfo(w http.ResponseWriter, _ *http.Request) {
info, err := GetBTFLoaderInfo()
if err != nil {
log.Errorf("unable to get ebpf_btf_loader info: %s", err)
fmt.Fprintf(w, "unable to get ebpf_btf_loader info: %s", err)
w.WriteHeader(500)
return
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/flare/archive_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func addSystemProbePlatformSpecificEntries(fb flaretypes.FlareBuilder) {
_ = fb.AddFileFromFunc(filepath.Join("system-probe", "conntrack_cached.log"), getSystemProbeConntrackCached)
_ = fb.AddFileFromFunc(filepath.Join("system-probe", "conntrack_host.log"), getSystemProbeConntrackHost)
_ = fb.AddFileFromFunc(filepath.Join("system-probe", "ebpf_btf_loader.log"), getSystemProbeBTFLoaderInfo)
_ = fb.AddFileFromFunc(filepath.Join("system-probe", "selinux_sestatus.log"), getSystemProbeSelinuxSestatus)
}
}

Expand Down Expand Up @@ -148,3 +149,9 @@ func getSystemProbeBTFLoaderInfo() ([]byte, error) {
url := sysprobeclient.DebugURL("/ebpf_btf_loader_info")
return getHTTPData(sysProbeClient, url)
}

func getSystemProbeSelinuxSestatus() ([]byte, error) {
sysProbeClient := sysprobeclient.Get(getSystemProbeSocketPath())
url := sysprobeclient.DebugURL("/debug/selinux_sestatus")
return getHTTPData(sysProbeClient, url)
}
11 changes: 11 additions & 0 deletions releasenotes/notes/agent-flare-sestatus-5820cfc79ec91d1f.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Each section from every release note are combined when the
# CHANGELOG.rst is rendered. So the text needs to be worded so that
# it does not depend on any information only available in another
# section. This may mean repeating some details, but each section
# must be readable independently of the other.
#
# Each section note must be formatted as reStructuredText.
---
enhancements:
- |
Added the output of ``sestatus`` into the Agent flare. This information will appear in ``system-probe/selinux_sestatus.log``.
Loading