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

heartbeat - move seccomp customization to InitializeModule #39763

Merged

Conversation

andrewkroh
Copy link
Member

@andrewkroh andrewkroh commented May 29, 2024

Proposed commit message

Move the overwriting of the arm64 seccomp policy out of the Go init() phase and into a function call that is specific to Heartbeat. This will prevent Heartbeat's policy from affecting all other Beats that run as part of Agentbeat.

Note that other customizations from all Beats that use seccomp.ModifyDefaultPolicy within init() are still being combined in Agentbeat to create a policy that is the aggregation of all seccomp customizations. So the allow-list type policies are likely more permissive than expected.

Fixes #39754

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

  • Run Hearbeat and observe the seccomp policy that is loaded by enabling debug logging.
cd x-pack/heartbeat
go build
./heartbeat run -e -d "seccomp"

Related issues

Logs

Heartbeat on arm64:

{
  "@timestamp": "2024-05-29T19:17:59.332Z",
  "ecs.version": "1.6.0",
  "log.level": "debug",
  "log.logger": "seccomp",
  "log.origin": {
    "file.line": 118,
    "file.name": "seccomp/seccomp.go",
    "function": "github.com/elastic/beats/v7/libbeat/common/seccomp.loadFilter"
  },
  "message": "Loading syscall filter",
  "seccomp_filter": {
    "flag": "tsync",
    "no_new_privs": true,
    "policy": {
      "default_action": "errno",
      "syscalls": [
        {
          "action": "allow",
          "names": [
            "accept",
            "accept4",
            "bind",
            "brk",
            "capget",
            "capset",
            "chdir",
            "clock_gettime",
            "clone",
            "clone3",
            "close",
            "connect",
            "dup",
            "dup3",
            "epoll_create1",
            "epoll_ctl",
            "epoll_pwait",
            "eventfd2",
            "execve",
            "exit",
            "exit_group",
            "faccessat",
            "fadvise64",
            "fallocate",
            "fchdir",
            "fchmod",
            "fchmodat",
            "fchown",
            "fchownat",
            "fcntl",
            "fdatasync",
            "flock",
            "fstat",
            "fstatat",
            "fstatfs",
            "fsync",
            "ftruncate",
            "futex",
            "getcwd",
            "getdents64",
            "getegid",
            "geteuid",
            "getgid",
            "getgroups",
            "getpeername",
            "getpgid",
            "getpid",
            "getppid",
            "getpriority",
            "getrandom",
            "getresgid",
            "getresuid",
            "getrlimit",
            "getrusage",
            "getsockname",
            "getsockopt",
            "gettid",
            "gettimeofday",
            "getuid",
            "inotify_add_watch",
            "inotify_init1",
            "inotify_rm_watch",
            "ioctl",
            "kill",
            "linkat",
            "listen",
            "lseek",
            "madvise",
            "memfd_create",
            "mincore",
            "mkdirat",
            "mlock",
            "mmap",
            "mprotect",
            "munmap",
            "name_to_handle_at",
            "nanosleep",
            "openat",
            "pipe2",
            "ppoll",
            "prctl",
            "pread64",
            "prlimit64",
            "pselect6",
            "pwrite64",
            "read",
            "readlinkat",
            "recvfrom",
            "recvmmsg",
            "recvmsg",
            "renameat",
            "rseq",
            "rt_sigaction",
            "rt_sigprocmask",
            "rt_sigreturn",
            "sched_getaffinity",
            "sched_getattr",
            "sched_getparam",
            "sched_getscheduler",
            "sched_setaffinity",
            "sched_setattr",
            "sched_yield",
            "seccomp",
            "sendfile",
            "sendmmsg",
            "sendmsg",
            "sendto",
            "set_robust_list",
            "set_tid_address",
            "setgid",
            "setgroups",
            "setitimer",
            "setpriority",
            "setsid",
            "setsockopt",
            "setuid",
            "shutdown",
            "sigaltstack",
            "socket",
            "socketpair",
            "splice",
            "statfs",
            "statx",
            "symlinkat",
            "sysinfo",
            "tgkill",
            "tkill",
            "umask",
            "uname",
            "unlinkat",
            "utimensat",
            "wait4",
            "waitid",
            "write",
            "writev"
          ],
          "names_with_args": null
        }
      ]
    }
  },
  "service.name": "heartbeat"
}

Move the overwriting of the arm64 seccomp policy out of the Go
init() phase and into a function call that is specific to Heartbeat. This
will prevent Heartbeat's policy from affecting all other Beats that run
as part of Agentbeat.

Note that other customizations from all Beats that use seccomp.ModifyDefaultPolicy
within init() are being combined in Agentbeat to create a policy that is the aggregation of
all seccomp customizations. So the allow-list type policies are likely more permissive than
expected.

Fixes elastic#39754
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label May 29, 2024
Copy link
Contributor

mergify bot commented May 29, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @andrewkroh? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

@andrewkroh andrewkroh added the backport-v8.14.0 Automated backport with mergify label May 29, 2024
@cmacknz cmacknz requested a review from emilioalvap May 29, 2024 19:20
@andrewkroh andrewkroh marked this pull request as ready for review May 29, 2024 19:22
@andrewkroh andrewkroh requested a review from a team as a code owner May 29, 2024 19:22
@andrewkroh andrewkroh added the Team:obs-ds-hosted-services Label for the Observability Hosted Services team label May 29, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label May 29, 2024
Copy link
Collaborator

@emilioalvap emilioalvap left a comment

Choose a reason for hiding this comment

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

LGTM

@andrewkroh andrewkroh merged commit 48a9901 into elastic:main May 29, 2024
18 of 19 checks passed
mergify bot pushed a commit that referenced this pull request May 29, 2024
Move the overwriting of the arm64 seccomp policy out of the Go
init() phase and into a function call that is specific to Heartbeat. This
will prevent Heartbeat's policy from affecting all other Beats that run
as part of Agentbeat.

Note that other customizations from all Beats that use seccomp.ModifyDefaultPolicy
within init() are still being combined in Agentbeat to create a policy that is the aggregation of
all seccomp customizations. So the allow-list type policies are likely more permissive than
expected.

Fixes #39754

(cherry picked from commit 48a9901)
andrewkroh added a commit that referenced this pull request May 31, 2024
…39764)

Move the overwriting of the arm64 seccomp policy out of the Go
init() phase and into a function call that is specific to Heartbeat. This
will prevent Heartbeat's policy from affecting all other Beats that run
as part of Agentbeat.

Note that other customizations from all Beats that use seccomp.ModifyDefaultPolicy
within init() are still being combined in Agentbeat to create a policy that is the aggregation of
all seccomp customizations. So the allow-list type policies are likely more permissive than
expected.

Fixes #39754

(cherry picked from commit 48a9901)

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.14.0 Automated backport with mergify Heartbeat Team:obs-ds-hosted-services Label for the Observability Hosted Services team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Agentbeat] incorrect seccomp policy
4 participants