Skip to content

Commit

Permalink
Merge pull request #1802 from tjkirch/api-exec
Browse files Browse the repository at this point in the history
Add 'apiclient exec' for running commands in host containers
  • Loading branch information
tjkirch authored Nov 10, 2021
2 parents 0f2ccc8 + 4b9a4b9 commit 2b61ad2
Show file tree
Hide file tree
Showing 24 changed files with 2,556 additions and 35 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ aws ssm start-session --target INSTANCE_ID

With the [default control container](https://github.com/bottlerocket-os/bottlerocket-control-container), you can make [API calls](#api) to configure and manage your Bottlerocket host.
To do even more, read the next section about the [admin container](#admin-container).
If you've enabled the admin container, you can access it from the control container like this:

```
apiclient exec admin bash
```

### Admin container

Expand Down Expand Up @@ -159,6 +164,12 @@ If you're using a custom control container, or want to make the API calls direct
apiclient set host-containers.admin.enabled=true
```

Once you've enabled the admin container, you can either access it through SSH or from the control container like this:

```
apiclient exec admin bash
```

Once you're in the admin container, you can run `sheltie` to get a full root shell in the Bottlerocket host.
Be careful; while you can inspect and change even more as root, Bottlerocket's filesystem and dm-verity setup will prevent most changes from persisting over a restart - see [Security](#security).

Expand Down Expand Up @@ -556,6 +567,12 @@ superpowered = false
If the `enabled` flag is `true`, it will be started automatically.

All host containers will have the `apiclient` binary available at `/usr/local/bin/apiclient` so they're able to [interact with the API](#using-the-api-client).
You can also use `apiclient` to run programs in other host containers.
For example, to access the admin container:

```
apiclient exec admin bash
```

In addition, all host containers come with persistent storage that survives reboots and container start/stop cycles.
It's available at `/.bottlerocket/host-containers/$HOST_CONTAINER_NAME` and (since Bottlerocket v1.0.8) `/.bottlerocket/host-containers/current`.
Expand Down Expand Up @@ -634,7 +651,7 @@ AWS-specific settings are automatically set based on calls to the Instance MetaD
### Logs

You can use `logdog` through the [admin container](#admin-container) to obtain an archive of log files from your Bottlerocket host.
SSH to the Bottlerocket host, then run:
SSH to the Bottlerocket host or `apiclient exec admin bash` to access the admin container, then run:

```bash
sudo sheltie
Expand All @@ -651,6 +668,8 @@ ssh -i YOUR_KEY_FILE \
"cat /.bottlerocket/rootfs/var/log/support/bottlerocket-logs.tar.gz" > bottlerocket-logs.tar.gz
```

(If your instance isn't accessible through SSH, you can use [SSH over SSM](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started-enable-ssh-connections.html).)

For a list of what is collected, see the logdog [command list](sources/logdog/src/log_request.rs).

### Kdump Support
Expand Down Expand Up @@ -732,6 +751,8 @@ This way, you can configure your Bottlerocket instance without having to make AP

See [Settings](#settings) above for examples and to understand what you can configure.

You can also access host containers through the API using [apiclient exec](sources/api/apiclient/README.md#exec-mode).

The server and client are the user-facing components of the API system, but there are a number of other components that work together to make sure your settings are applied, and that they survive upgrades of Bottlerocket.

For more details, see the [API system documentation](sources/api/).
Expand Down
102 changes: 102 additions & 0 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions sources/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,32 @@ Now you can inspect settings in the API or do any other testing you like.

You won't have dynamic settings generated by [sundog](#sundog) during a normal Bottlerocket launch, but you're probably not locally running the software that needs those, like Kubernetes.
If you are, you can set them manually; see the top-level README for descriptions of those settings.

#### Testing apiclient exec

When you use `apiclient exec`, the server needs to know the containerd socket it can use to run the requested command, and it needs root access to talk to containerd.
Here's how you can test the feature locally.

Follow the [setup steps above](#Setup) if you haven't already, then stop the apiserver, because we'll need to run it a different way.

First, run a task in containerd locally. Here's an example:
```
sudo ctr i pull public.ecr.aws/amazonlinux/amazonlinux:latest
sudo ctr run --rm -t public.ecr.aws/amazonlinux/amazonlinux:latest al bash
```

If you use a containerd socket other than the default `/run/containerd/containerd.sock` then pass it to ctr with `-a PATH` on each of those commands.

Next, run apiserver as root so it can talk to containerd.
From the `sources` directory:
```
sudo target/debug/apiserver --datastore-path /tmp/data-store/current --socket-path /tmp/bottlerocket-api.sock
```

If you use a containerd socket other than the default `/run/containerd/containerd.sock` then pass it to apiserver with `--exec-socket-path PATH` on that command.

Finally, use apiclient to start another program in your container task.
From the `sources/api/apiclient` directory:
```
cargo run -- --socket-path /tmp/bottlerocket-api.sock exec al bash
```
1 change: 1 addition & 0 deletions sources/api/api-exec.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="Electron" modified="2021-11-01T16:42:43.754Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/15.4.0 Chrome/91.0.4472.164 Electron/13.5.0 Safari/537.36" etag="7qaOFmb267Qq1O5nCDpU" version="15.4.0" type="device"><diagram id="WwR_IrcpEeUXiprJ6851" name="Page-1">7V3bcqO4Fv2aVM15MIUQ4vLYSd/SZ3rSM+nrvJwioNhMMLgxTpz++iNhZGNJgGwjm2SSmao24r7W0t5bWxfO4MV0+S4PZpOPWYSTM8uMlmfw9ZllAeQD8g8teVyV+MBaFYzzOKoO2hRcx79wVWhWpYs4wvOtA4ssS4p4tl0YZmmKw2KrLMjz7GH7sNss2b7rLBhjoeA6DBKx9FscFZOqFJjmZsd7HI8n1a09VO2YBuzgqmA+CaLsoVYE35zBizzLitWv6fICJxQ8hsvqvLcNe9cPluO0UDnhL/jP989vvrz++xzjxZdPn0dfwOUIotVl7oNkUb1x9bTFI4MgzxZphOlVzDN4/jCJC3w9C0K694GQTsomxTQhW4D8nBd5docvsiTLy7OhWf6RPbdZWtTKPZP+R89guNCNMJvGYfVbfMHqne9xXuBlrah64Xc4m+IifySHLLdVVIkPeNX2w4ZKxAib1Fi0/aowqOQzXl96gzD5UYEsB/xL9OfPBP145b9dPuLs7WK5CO0R8LsBHxPEZ+pvvxZ/cMOuYLaiYm2jghwRFeBIUAFAGyoyGToJue95FN/TOybxOC13OD8XtMacJ/i22GyRX+Pq3/Ksm5wvIc9VXoqVHiJy9jTlM8iE2k59t3w7mTC1MeH0zETMCt6kIfEOK7USI0GfZIrnc2I/562sxTsySbAt2mxSmqWY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