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

Defense in Depth - Prevent attacker from becoming root within the container #224

Closed
Tracked by #221
apyrgio opened this issue Oct 17, 2022 · 3 comments · Fixed by #590
Closed
Tracked by #221

Defense in Depth - Prevent attacker from becoming root within the container #224

apyrgio opened this issue Oct 17, 2022 · 3 comments · Fixed by #590

Comments

@apyrgio
Copy link
Contributor

apyrgio commented Oct 17, 2022

Parent issue: #221

Once an attacker has found a flaw that allows them to take control of a process (see #222), they will probably attempt to become root within the container. Currently, this is not easy for two reasons:

  1. The user within the container is a regular user (dangerzone, UID 1000).
  2. We use --security-opt=no-new-privileges, so the kernel does not allow a process to elevate their privileges.

However, it may be worth ensureing that it's not easy to become root in the container, even if this safeguard does not manage to work. For an extra layer of security, we could follow the latest CIS Docker advisories (official link, mirror).

Because the advisories are numerous, there are tools that check if a container image/runtime complies with the advisories:

I have already ran these two tools on Windows and Linux, and the noteworthy sections that were reported are the following:

  • 4.3 - Ensure that unnecessary packages are not installed in the container
  • 4.8 - Ensure setuid and setgid permissions are removed
    • The flagged binary was sudo, which is not used and can be removed.
  • 5.12 - Ensure that the container's root filesystem is mounted as read only

We can easily placate section 4.8 by removing sudo, and section 5.12 by running the podman / docker command with the --read-only flag. The 4.3 section requires a bit more digging and is tracked in #232.

@deeplow
Copy link
Contributor

deeplow commented Oct 19, 2022

4.3 can be considered part of the scope of #232.

@apyrgio apyrgio added this to the 0.4.0 milestone Oct 19, 2022
@apyrgio
Copy link
Contributor Author

apyrgio commented Oct 20, 2022

I agree and I updated the issue description. This issue should not close as long as #232 is open.

@eloquence eloquence modified the milestones: 0.4.0, 0.5.0 Nov 23, 2022
@apyrgio apyrgio modified the milestones: 0.5.0, 0.5.1 Jun 13, 2023
@apyrgio
Copy link
Contributor Author

apyrgio commented Jun 10, 2024

With the integration of Dangerzone with gVisor, we can now close this issue. Some requirements are not yet satisfied (such as the removal of the sudo binary), but due to the fact that we run the code in a nested gVisor container, we have gone above and beyond reducing the attacker's privileges.

apyrgio pushed a commit that referenced this issue Jun 10, 2024
This wraps the existing container image inside a gVisor-based sandbox.

gVisor is an open-source OCI-compliant container runtime.
It is a userspace reimplementation of the Linux kernel in a
memory-safe language.

It works by creating a sandboxed environment in which regular Linux
applications run, but their system calls are intercepted by gVisor.
gVisor then redirects these system calls and reinterprets them in
its own kernel. This means the host Linux kernel is isolated
from the sandboxed application, thereby providing protection against
Linux container escape attacks.

It also uses `seccomp-bpf` to provide a secondary layer of defense
against container escapes. Even if its userspace kernel gets
compromised, attackers would have to additionally have a Linux
container escape vector, and that exploit would have to fit within
the restricted `seccomp-bpf` rules that gVisor adds on itself.

Fixes #126
Fixes #224
Fixes #225
Fixes #228
EtiennePerot added a commit to EtiennePerot/dangerzone that referenced this issue Jun 12, 2024
This wraps the existing container image inside a gVisor-based sandbox.

gVisor is an open-source OCI-compliant container runtime.
It is a userspace reimplementation of the Linux kernel in a
memory-safe language.

It works by creating a sandboxed environment in which regular Linux
applications run, but their system calls are intercepted by gVisor.
gVisor then redirects these system calls and reinterprets them in
its own kernel. This means the host Linux kernel is isolated
from the sandboxed application, thereby providing protection against
Linux container escape attacks.

It also uses `seccomp-bpf` to provide a secondary layer of defense
against container escapes. Even if its userspace kernel gets
compromised, attackers would have to additionally have a Linux
container escape vector, and that exploit would have to fit within
the restricted `seccomp-bpf` rules that gVisor adds on itself.

Fixes freedomofpress#126
Fixes freedomofpress#224
Fixes freedomofpress#225
Fixes freedomofpress#228
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants