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

Tweak docker base image, approval script, and sudoers file; add Docker section to README #124

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1

FROM rust:latest AS base
FROM rust:1.52.1 AS base
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sometime between the last update and now, rust:latest started building the plugin in such a way that it causes a segfault when added to sudo.conf. Looking at bisecting that.


ARG DEBIAN_FRONTEND=noninteractive

Expand Down
2 changes: 1 addition & 1 deletion sample/etc/sudo_pair.prompt.user
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ Due to security and compliance requirements, this `sudo` session will require ap

To continue, another human must run:

docker exec -it %h '%B %u %p'
docker exec -it %h %B %u %p
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Having the command and its params in quotes causes Docker to look for a file of that exact name, which then can't be found.


If a suitable human is not available and you have an immediate and urgent need to run this command, you may run the above command to approve your own session. Note that doing so will immediately page an oncall security engineer, so this capability should only be used in the event of an emergency.
2 changes: 1 addition & 1 deletion sample/etc/sudoers.d/sudo_pair
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nobody ALL = (: games) NOPASSWD: LOG_OUTPUT: ALL
games ALL = (nobody) NOPASSWD:LOG_OUTPUT:ALL
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This might be wrong—I kind of reverse-engineered this from what seemed like the expected behavior for the environment; nogroup is the restricted-access group which triggers sudo_pair, and nobody is the member of that group that we want to sudo as. Doing it as root just automatically succeeds, so we need to do it with a different user (presumably games, although most users would work).

50 changes: 50 additions & 0 deletions sudo_pair/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,56 @@ goal to have a minimal set of dependencies. Currently, those are:
* [rust-lang-nursery/failure][failure]
* [dtolnay/thiserror][thiserror]

## Manual Testing in Docker

The behavior of `sudo_pair` can be tested using the included Docker image.

First, build and launch the image. It does not have an entrypoint, so using
the `-i` flag ensures it stays open, and the `-d` flag detaches from it.

```
docker build -t sudo-pair . && docker run -id --name sudo-pair sudo-pair
```

Now, you can attach to the image as the `games` user. In the configuration generated for
this Docker image, `games` is granted the right to passwordlessly sudo as the `nobody` user;
in turn, the `nobody` user is a member of the `nogroup` group, which triggers the `sudo_pair`
enforcement mechanism:

```
docker exec -u games -it sudo-pair /bin/bash
```

Now that you're logged in as `games`, you can attempt to sudo as `nobody`, and see the `sudo_pair`
flow:

```
sudo -u nobody /bin/bash
```

You'll be given a prompt like the one below explaining that another user must approve your sudo action:

```
Due to security and compliance requirements, this `sudo` session will require approval and monitoring.

To continue, another human must run:

docker exec -it d263b8d24076 /usr/bin/sudo_approve 5 112

If a suitable human is not available and you have an immediate and urgent need to run this command,
you may run the above command to approve your own session. Note that doing so will immediately page
an oncall security engineer, so this capability should only be used in the event of an emergency.
```

In another terminal, you can copy and paste the given command (which will implicitly run as root
inside the container), and your session as `nobody` will be mirrored to both terminals once approved.

To clean up the existing Docker environment before creating a new build, stop and remove the container:

```
docker stop sudo-pair && docker rm sudo-pair
```

## Contributions

Contributions are welcome! This project should hopefully be small
Expand Down