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

Introduce documentation about required capabilities #1587

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rafaelroquetto
Copy link
Contributor

First iteration of the documentation that talks about the required capabilities to run Beyla. Whilst it could have been nice, a per-kernel list is out of the scope for this PR and could be added later.

I've also removed the mentions to mounting file systems, since Beyla no longer does that.

It would be good to get feedback on whether we still require container.apparmor.security.beta.kubernetes.io/beyla: "unconfined".

Resolves #1404

@rafaelroquetto rafaelroquetto added the documentation Improvements or additions to documentation label Jan 29, 2025
@rafaelroquetto rafaelroquetto requested a review from a team January 29, 2025 19:58
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/_index.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.02%. Comparing base (ab3c784) to head (021918b).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1587      +/-   ##
==========================================
- Coverage   71.05%   71.02%   -0.04%     
==========================================
  Files         197      197              
  Lines       19753    19792      +39     
==========================================
+ Hits        14036    14057      +21     
- Misses       5041     5057      +16     
- Partials      676      678       +2     
Flag Coverage Δ
integration-test 52.81% <ø> (-0.14%) ⬇️
k8s-integration-test 53.04% <ø> (-0.83%) ⬇️
oats-test 34.67% <ø> (-0.01%) ⬇️
unittests 46.95% <ø> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
- Set a modified AppArmour policy which allows Beyla to perform `mount`.

**Note** Since the `beyla` container does not have the privileges required to mount or un-mount the BPF filesystem, this sample leaves the BPF filesystem mounted on the host, even after the sample is deleted. This samples uses a unique path for each namespace to ensure re-use the same mount if Beyla is re-deployed, but to avoid collisions if multiple instances of Beyla is run in different namespaces.
Because of the AppArmour restriction, to run Beyla as unprivileged container, you may need to set `container.apparmor.security.beta.kubernetes.io/beyla: "unconfined"` in your Kubernetes deployment files in case you run into issues.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [vale] reported by reviewdog 🐶
[Grafana.Kubernetes] Use 'Kubernetes Deployment' instead of 'Kubernetes deployment'.

For more information, refer to https://grafana.com/docs/writers-toolkit/write/style-guide/capitalization-punctuation/#kubernetes-objects.

If the rule is incorrect or needs improving, report an issue.

If you have reason to diverge from the style guidance, to skip a rule, refer to Skip rules.


## Beyla operation modes

Beyla can operate in two distinct modes: _application observability_ and _network observability_. These modes are not mutually exclusive and can be used together as needed. The former is typically enabled using the `BEYLA_OPEN_PORT` or `BEYLA_EXECUTABLE_NAME` options, while the latter is controlled via the `BEYLA_NETWORK_METRICS` option. For more details on enabling these modes, refer to the [configuration documentation](/docs/beyla/latest/configure/options/).
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of namig BEYLA_OPEN_PORT ... can we please refer to the docs on the discovery section.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea

| Capability | Usage in Beyla |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| `CAP_BPF` | enables general BPF functionality and `BPF_PROG_TYPE_SOCK_FILTER` programs |
| `CAP_NET_RAW` | used to create `AF_PACKET` raw sockets |
Copy link
Contributor

Choose a reason for hiding this comment

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

This one is needed for the socket filter program. I think we need to be more descriptive here about how the capabilities relate to Beyla features, I don't think our users would know what AF_PACKET means in terms of Beyla. Same for NET_ADMIN, we need to say network observability and context propagation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, I will reshuffle this.

docs/sources/security.md Outdated Show resolved Hide resolved
* `CAP_DAC_READ_SEARCH`
* `CAP_CHECKPOINT_RESTORE`
* `CAP_PERFMON`
* `CAP_NET_RAW`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think NET_ADMIN assumes NET_RAW, maybe we don't need that one but it's fine to keep it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I double checked the kernel sources, they are orthogonal to each other.


### Flow fetcher (tc)
- `CAP_BPF`
- `CAP_NET_ADMIN` -> for `PROG_TYPE_SCHED_CLS`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to say what PROG_TYPE_SCHE... does, rather than saying it's for that.

### Flow fetcher (tc)
- `CAP_BPF`
- `CAP_NET_ADMIN` -> for `PROG_TYPE_SCHED_CLS`
- `CAP_PERFMON` -> direct access to `struct __sk_buff::data` and pointer arithmetic
Copy link
Contributor

Choose a reason for hiding this comment

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

Again we need to say what this means for our end users.

docs/sources/security.md Outdated Show resolved Hide resolved
docs/sources/security.md Outdated Show resolved Hide resolved
@@ -251,24 +251,13 @@ In all of the examples so far, `privileged:true` or the `SYS_ADMIN` Linux capabi

The following guide is based on tests performed mainly by running `containerd` with `GKE`, `kubeadm`, `k3s`, `microk8s` and `kind`.

To run Beyla unprivileged, you need to run a `privileged` init container which performs setup tasks which require elevated privileges. Then you need to replace the `privileged:true` setting with a set of Linux [capabilities](https://www.man7.org/linux/man-pages/man7/capabilities.7.html).
To run Beyla unprivileged, you need to run a `privileged` init container which performs setup tasks which require elevated privileges. Then you need to replace the `privileged:true` setting with a set of Linux [capabilities](https://www.man7.org/linux/man-pages/man7/capabilities.7.html). A comprehensive list of capabilities required by Beyla can be found in [Security, permissions and capabilities]({{< relref "../security" >}}).
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to run a privileged init container anymore, it should be removed as well.

- `CAP_DAC_READ_SEARCH` is required to open ELF files.
- `CAP_PERFMON` is required to load BPF programs, i.e. be able to perform `perf_event_open()`.
- `CAP_SYS_RESOURCE` is required only on kernels **< 5.11** so that Beyla can increase the amount of locked memory available.
In addition to these Linux capabilities, many Kubernetes versions include [AppArmour](https://kubernetes.io/docs/tutorials/security/apparmor/), which tough policies adds additional restrictions to unprivileged containers. By [default](https://github.com/moby/moby/blob/master/profiles/apparmor/template.go), the AppArmour policy restricts the use of `mount` and the access to `/sys/fs/` directories. Beyla requires access to `/sys/fs/cgroup/`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on what we saw, I think /cgroup is not restricted by the app armour default config. We need to confirm and remove this section too.


## Linux kernel capabilities

Linux kernel capabilities are a fine-grained system for controlling access to privileged operations on the system. They allow you to grant specific permissions to processes without giving them full root (superuser) access, which helps improve security by adhering to the principle of least privilege. Instead of relying on the traditional all-or-nothing root model, capabilities split the powerful privileges typically associated with root into smaller, more manageable units.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add link some here to some official docs or so?

docs/sources/security.md Outdated Show resolved Hide resolved
@grafsean grafsean self-assigned this Feb 3, 2025

# Beyla security, permissions, and capabilities

Beyla needs access to various Linux interfaces to instrument applications, such as reading from the `/proc` filesystem, loading eBPF programs, and managing network interface filters. Many of these operations require elevated permissions. The simplest solution is to run Beyla as `root`, however this might not work well in setups where full `root` access isn’t ideal. To address this, Beyla is designed to use only the specific Linux kernel capabilities needed for its current configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [vale] reported by reviewdog 🐶
[Grafana.SmartQuotes] Avoid smart quotes in the source file, especially in code blocks. Replace all smart double quotes like or with ". Replace all smart single quotes like , , or ʼ with '. In some contexts, Unicode characters aren't supported and break configurations. The website renders paired quotes using smart quotes in paragraphs.

If the rule is incorrect or needs improving, report an issue.

If you have reason to diverge from the style guidance, to skip a rule, refer to Skip rules.

@grafsean
Copy link
Contributor

grafsean commented Feb 3, 2025

@rafaelroquetto I pushed a copy edit and addressed some of the non-technical feedback. It's ready for you to review and address the remaining technical feedback.


# Beyla security, permissions, and capabilities

Beyla needs access to various Linux interfaces to instrument applications, such as reading from the `/proc` filesystem, loading eBPF programs, and managing network interface filters. Many of these operations require elevated permissions. The simplest solution is to run Beyla as root, however this might not work well in setups where full root access isn’t ideal. To address this, Beyla is designed to use only the specific Linux kernel capabilities needed for its current configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ [vale] reported by reviewdog 🐶
[Grafana.SmartQuotes] Avoid smart quotes in the source file, especially in code blocks. Replace all smart double quotes like or with ". Replace all smart single quotes like , , or ʼ with '. In some contexts, Unicode characters aren't supported and break configurations. The website renders paired quotes using smart quotes in paragraphs.

If the rule is incorrect or needs improving, report an issue.

If you have reason to diverge from the style guidance, to skip a rule, refer to Skip rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Docs] Security (root access, privileged mode, Linux capabilities)
4 participants