Skip to content

RFC: Allow running the agent container without additional capabilities through a separate binary #1273

Open
@nadiamoe

Description

@nadiamoe

Note

This issue is a RFC, which means it lays out a problem, a potential solution, and requests comments on it.

Problem

There's a use case for running the synthetic monitoring agent on a container on environments that do not allow granting additional capabilities to the container. This may happen, for example, by enforcing the Baseline pod security standard.

Currently, this poses a problem, as attempting to run the synthetic-monitoring-agent container without the NET_RAW capability will prevent the container from starting. The reason for this is that the binary that acts as the container entrypoint has this capability added:

RUN setcap cap_net_raw=+ep /usr/local/bin/synthetic-monitoring-agent

As a security precaution, the linux kernel will refuse to run a binary requesting a capability that is not part of the permitted set, and it results on an error like the following:

sh: /usr/local/bin/synthetic-monitoring-agent: Operation not permitted

The reason for the synthetic-monitoring-agent binary to request NET_RAW is to be able to perform ICMP-based checks, such as ping or traceroute, which require forging raw ICMP packets. While there's a way to perform a subset of these checks using UDP packets, these do not have complete feature parity with ICMP.

Proposed solution

I suggest that we add a second binary to the same container image, which is a build-time copy of the original binary, but without the NET_RAW capability added. This is a Dockerfile-only change, which would look like this:

diff --git a/Dockerfile b/Dockerfile
index 93f8b46..2ad16f6 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -25,6 +25,7 @@ RUN adduser -D -u 12345 -g 12345 sm
 
 ADD --chown=sm:sm --chmod=0500 https://github.com/grafana/xk6-sm/releases/download/v0.0.3-pre/sm-k6-${TARGETOS}-${TARGETARCH} /usr/local/bin/sm-k6
 COPY --chown=sm:sm --chmod=0500 --from=setcapper /usr/local/bin/synthetic-monitoring-agent /usr/local/bin/synthetic-monitoring-agent
+COPY --chown=sm:sm --chmod=0500 dist/${HOST_DIST}/synthetic-monitoring-agent /usr/local/bin/synthetic-monitoring-agent-unprivileged
 COPY --chown=sm:sm scripts/pre-stop.sh /usr/local/lib/synthetic-monitoring-agent/pre-stop.sh
 COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt

With the difference being that synthetic-monitoring-agent-unprivileged is not granted any file-based capability, unlike synthetic-monitoring-agent which is:

RUN setcap cap_net_raw=+ep /usr/local/bin/synthetic-monitoring-agent

This second binary allows users who do not want or can add the NET_RAW capability to the container to still run the container, acknowledging that functionality related to ICMP checks may not work correctly. They would be able to do that by overriding the default entrypoint, which is something universally supported by container runtimes. We would document this in the repo readme and in the grafana docs website.

  • ➕ Pros:
    • Low maintenance cost: This second binary is identical to the main one, it does not need to be built separately.
  • ➖ Cons:
    • The size of the container image will increase

Alternative solutions

  1. Do nothing, the use case remains unsupported.
  2. Same "two binaries" approach as above, but making unprivileged the default.
  3. Creating an -unprivileged container flavor.
  4. Granting the NET_RAW capability in runtime.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions