Commit Graph
108 Commits
Author SHA1 Message Date
Andrei VaginandgVisor bot f556917137 vfs: MountNamespace.Root() has to return a top mount of /
A few mounts can be mounted on top of `/`.

PiperOrigin-RevId: 558264274
2023-08-18 15:35:47 -07:00
Nayana BidariandgVisor bot 3995928c06 Add GetMemoryUsage() API to the gVisor sandbox.
Adds GetMemoryUsage() API to get the memory usage of the containers.

PiperOrigin-RevId: 557923509
2023-08-17 13:43:56 -07:00
Etienne PerotandgVisor bot f3f2d61a9e Usage.Reduce RPC: Add option to avoid Go garbage collection.
PiperOrigin-RevId: 547942962
2023-07-13 15:32:27 -07:00
Etienne PerotandgVisor bot b0d7484ec9 Also run Go garbage collection as part of Usage.Reduce.
The `Usage.Reduce` RPC's promise is to reclaim as much Sentry memory as
possible and to give it back to the host.
Seems like running Go GC should be part of that.

PiperOrigin-RevId: 547312564
2023-07-11 15:22:27 -07:00
Shambhavi SrivastavaandgVisor bot feda939749 Enabling container to be initialized to it's initial cgroups
Currently there's no implementation to enable the container to be
initialized to it's cgroups and hence the `EnterInitialCgroups` would
inherit all the root's cgroups when the container would start.

With this implementation we make sure that when the container starts
it enter's into the cgroups that is passed down it to from the sandbox.

PiperOrigin-RevId: 540650868
2023-06-15 12:07:05 -07:00
Nicolas LacasseandgVisor bot db610e9690 Unlock lifecycle.mu in StartContainer error path.
PiperOrigin-RevId: 526132558
2023-04-21 14:13:28 -07:00
gVisor bot cb43102dcb Merge pull request #8783 from blechschmidt:execfd
PiperOrigin-RevId: 522673803
2023-04-07 13:42:12 -07:00
B. Blechschmidt fbcb22b5c8 Add support for execution via host file descriptor
This commit adds support for program execution via a host file
descriptor. To make use of this feature, the host file descriptor must
be provided to the --exec-fd argument. For example,

    exec 3</usr/bin/echo
    runsc exec --exec-fd=3 mycontainer hello world

will run the host's echo binary inside gVisor. In this case, "hello" is
supplied to echo as argv[0]. As a result, the output of the above
command is "world".

This feature is useful for bootstrapping unknown guest environments and
allows static executables to perform setup actions inside the container
while they need not be part of the guest file system.
2023-04-02 01:27:19 +02:00
Etienne PerotandgVisor bot 508e63fbee runsc metric-server: Add query parameter to only export a subset of metrics.
This adds an optional `GET` parameter `runsc-sandbox-metrics-filter` which can
be used to filter the set of sandbox metrics requested from each sandbox. In
cases where the metric client isn't interested in learning everything about
the sandboxes, this saves on RPC cost and latency.

This also has the benefit of reducing memory usage of the `metric-server`
further, as it does not need to hold onto data that it will not export.

As the sandbox process is untrusted, the metrics returned are double-checked
on the `metric-server` side to ensure that the filter was respected.

PiperOrigin-RevId: 521055953
2023-03-31 18:11:38 -07:00
gVisor bot 1f331d133c Merge pull request #8634 from blechschmidt:passfd
PiperOrigin-RevId: 516362077
2023-03-13 17:02:22 -07:00
B. Blechschmidt 9f521bdeba Add --pass-fd flag to runsc run and exec
This commit implements file descriptor passing from the host to the
guest. It implements a --pass-fd flag that can be specified multiple
times with FD numbers from the host that will be inserted into the file
descriptor table of the guest.
2023-03-10 00:30:44 +01:00
Adin ScannellandgVisor bot 2911d8c3b8 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Etienne PerotandgVisor bot 8bc7f36f7b metric.go: Use an atomic boolean for initialized.
Addresses gotsan-found data race when reading metric registration data over
urpc vs during initialization.

In practice, this can never happen, because the urpc call for metric
registration only happens after the boot sync file descriptor has been
written to, but there's no way for gotsan to know that. So this change just
switches it to an atomic boolean for good measure.

Also verified in `metric.GetSnapshot`, because why not.

PiperOrigin-RevId: 500210642
2023-01-06 15:02:41 -08:00
Etienne PerotandgVisor bot 471ae30d19 gVisor: Add control command to get metric registration information.
This metric registration information contains the metadata of all the metrics
that the Sentry is expected to produce during its lifetime, including all
possible field combinations, the types, distribution bucket boundaries, etc.

This will be called during sandbox startup, before starting any container, in
order to save this information in the metrics server so that it can verify the
validity of instrumentation data from the Sentry once the container is
started.

This change has no tests, but coverage is provided in a later change that
provides an end-to-end container tests that the metric server works and
exports data faithfully.

This change is part of a series of changes to support Prometheus-style metrics
in `runsc`. Doing so requires making several seemingly-odd design decisions,
due to the following architectural constraints:

- Prometheus requires an HTTP server serving the `/metrics` endpoint.
- For performance reasons, the `runsc boot` process cannot run the `netpoller`
  goroutine.
  - Since we don't want to write our own HTTP server implementation, this
    means the HTTP endpoint has to be served by a separate process that
    remains running during the lifetime of the container.
- The `runsc boot` process is untrusted.
  - This means we cannot trust metrics data that comes out of the Sentry.
    Therefore, there needs to be an elaborate dance where we pre-register
    metric metadata before starting any untrusted workload. Then, the server
    relaying the metric data must verify the validity of metric values against
    this metric metadata. This avoids leaking metrics, cardinality blow-ups,
    and other such DoS vectors.
- This feature needs to be easy-to-use in a typical Docker setting.
  - This means having the ability to just say
    `--metrics-server=localhost:1337` in the `runsc` runtime entry in
    `/etc/docker/daemon.json` and have that Just Work(TM), even when multiple
    containers are running.
  - Since only one process may listen on a port at a given time, this means
    the metric server needs to be able to multiplex requests out to multiple
    running sandboxes, and remain alive for the entire duration of either of
    these sandboxes. However, it should also die when there are no sandboxes,
    so that we don't end up with leftover metric servers lying around.
  - For this reason, the metrics server runs *outside* of the usual
    per-container cgroups.
  - This also saves system resources by not running one server per sandbox.
- The metrics server must be exposed to the outside world, and cannot assume
  that its clients are trustworthy.
  - For this reason, a metrics server is bound to a runtime root directory,
    and double-checks all that the sandboxes it is asked to follow actually
    exist in this root directory.

PiperOrigin-RevId: 498076197
2022-12-27 19:04:58 -08:00
Etienne PerotandgVisor bot 592faca601 gVisor: Add runsc metrics-export subcommand.
This subcommand prints a sandbox's instrumentation data in Prometheus format
to stdout.

This change is part of a series of changes to support Prometheus-style metrics
in `runsc`. Doing so requires making several seemingly-odd design decisions,
due to the following architectural constraints:

- Prometheus requires an HTTP server serving the `/metrics` endpoint.
- For performance reasons, the `runsc boot` process cannot run the `netpoller`
  goroutine.
  - Since we don't want to write our own HTTP server implementation, this
    means the HTTP endpoint has to be served by a separate process that
    remains running during the lifetime of the container.
- The `runsc boot` process is untrusted.
  - This means we cannot trust metrics data that comes out of the Sentry.
    Therefore, there needs to be an elaborate dance where we pre-register
    metric metadata before starting any untrusted workload. Then, the server
    relaying the metric data must verify the validity of metric values against
    this metric metadata. This avoids leaking metrics, cardinality blow-ups,
    and other such DoS vectors.
- This feature needs to be easy-to-use in a typical Docker setting.
  - This means having the ability to just say
    `--metrics-server=localhost:1337` in the `runsc` runtime entry in
    `/etc/docker/daemon.json` and have that Just Work(TM), even when multiple
    containers are running.
  - Since only one process may listen on a port at a given time, this means
    the metric server needs to be able to multiplex requests out to multiple
    running sandboxes, and remain alive for the entire duration of either of
    these sandboxes. However, it should also die when there are no sandboxes,
    so that we don't end up with leftover metric servers lying around.
  - For this reason, the metrics server runs *outside* of the usual
    per-container cgroups.
  - This also saves system resources by not running one server per sandbox.
- The metrics server must be exposed to the outside world, and cannot assume
  that its clients are trustworthy.
  - For this reason, a metrics server is bound to a runtime root directory,
    and double-checks all that the sandboxes it is asked to follow actually
    exist in this root directory.

PiperOrigin-RevId: 498067941
2022-12-27 18:11:57 -08:00
Shambhavi SrivastavaandgVisor bot 04b311dbb2 Adding container_start_duration metric for container multi-container mode.
Including the time when a container start request is
received and the time it is completed in the
ContainerStartedEvent proto message.

PiperOrigin-RevId: 495390114
2022-12-14 12:46:49 -08:00
Shambhavi SrivastavaandgVisor bot 384b6d4c5c Adding metrics for exit_status of container in multi-container mode.
PiperOrigin-RevId: 493671987
2022-12-07 12:10:50 -08:00
Shambhavi SrivastavaandgVisor bot 63f47604a5 Adding metrics for start container in multi-container mode.
PiperOrigin-RevId: 493655449
2022-12-07 11:11:41 -08:00
Ayush RanjanandgVisor bot 1003ae8e93 Delete VFS1 completely.
- Delete pkg/sentry/fs/*.
- Move pkg/sentry/fs/fsutil out of VFS1 directory and remove VFS1 components.
- Remove remaining unused references to VFS1 from remaining codebase.
- Rename/refactor code to avoid even referencing VFS2, unless necessary.
- Rewrite VFS1-only tests to VFS2.

Updates #1624

PiperOrigin-RevId: 490064269
2022-11-21 13:57:52 -08:00
Shambhavi SrivastavaandgVisor bot 994281d2ef Adding check to ensure containerIDs are unique in multi-container mode.
PiperOrigin-RevId: 489073573
2022-11-16 16:49:15 -08:00
Ayush RanjanandgVisor bot ee523cfbc7 Delete VFS1 filesystem implementations.
Updates #1624

PiperOrigin-RevId: 488986080
2022-11-16 11:05:10 -08:00
Ayush RanjanandgVisor bot 7cac4e2732 Start cleaning up VFS1.
PiperOrigin-RevId: 486586072
2022-11-07 00:39:54 -08:00
Rahat MahmoodandgVisor bot 126144d6ce Add container exit event.
PiperOrigin-RevId: 479651998
2022-10-07 13:11:13 -07:00
Nicolas LacasseandgVisor bot 3d12a1361f Initialize MountNamespace before calling methods that depend on it.
PiperOrigin-RevId: 477281632
2022-09-27 14:56:09 -07:00
Nicolas LacasseandgVisor bot 35968e7409 Split SignalContainerArgs out of ContainerArgs.
The signal-specific logic is only needed for SignalContainer.

PiperOrigin-RevId: 477268167
2022-09-27 14:02:24 -07:00
Nicolas LacasseandgVisor bot 9144c1fe0b Handle more arguments in StartContainer.
PiperOrigin-RevId: 477234682
2022-09-27 11:58:04 -07:00
Rahat MahmoodandgVisor bot d0c5abcfea Implement sentry control commands for cgroupfs.
Add sentry control commands to read and write cgroup control
values.

PiperOrigin-RevId: 474663678
2022-09-15 14:55:45 -07:00
Shambhavi SrivastavaandgVisor bot 54711bf5f9 Add SignalContainer() to GvisorContainer for multi-containers.
SignalContainer() sends control message to signal
the container in multi-container mode.

PiperOrigin-RevId: 465975679
2022-08-08 00:55:32 -07:00
Nayana BidariandgVisor bot 87c5075ceb Multi Container: Add IsRunning() control message for the container.
- Adds IsRunning() control message which returns true if the container is
running.
- Adds a test to verify the result of IsRunning().

PiperOrigin-RevId: 461759652
2022-07-18 18:04:54 -07:00
Nayana BidariandgVisor bot fcbc66ef13 Multi-Container: Add GetExitStatus() control message to get the exit status.
- Adds a new control message GetExitStatus() which blocks until the container
has finished execution and returns the exit status.
- Tests to verify that the GetExitStatus() works correctly.

PiperOrigin-RevId: 459333916
2022-07-06 13:51:16 -07:00
Nayana BidariandgVisor bot 73fc503a3e Add a new control message for destroying sandbox in multi-container mode.
- Adds SandboxShutdown() control message to destroy sandbox manually.
- Adds a new gVisor API for destroying the sandbox in multi container mode.
- Test to verify the API and the control message works correctly.

PiperOrigin-RevId: 459290099
2022-07-06 10:48:29 -07:00
Nayana BidariandgVisor bot f25c88c673 Run two containers
This change will allow the gVisor sandbox to run multiple containers.
- Added new functions to validate the SentryMultiContainerSpec and the
container mounts.
- Changes to set the target path in container mounts for eg: root target will
be "/container0" and the submounts target will be "/container0/dev".. etc in
multi-container mode.
- Added new fields in the protos: container name in ContainerSpec and
MultiContainerConfig in SentryConfig.
- Updated the sentry to create the mount namespaces for all the containers
during the sentry start as we have all the container mount configs. These
mount namespaces are passed to the control server in a map with the container
name as the key.
- Updated changes in StartContainer():
    - Use ContainerSpec instead of SandboxRunSpec.
    - No longer create the mount namespaces here and use the ones created by
      the sentry.
- Added test to run two containers in multi-container mode using the
SentryMultiContainerSpec.

PiperOrigin-RevId: 454649646
2022-06-13 10:59:24 -07:00
Nicolas LacasseandgVisor bot 3be9c205b4 Port sentry control Cat method to VFS2.
And re-enable the cat container_test.

Updates #6742

PiperOrigin-RevId: 449578758
2022-05-18 14:34:18 -07:00
Ayush RanjanandgVisor bot 2026e1f078 Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
Nayana BidariandgVisor bot c3365a1ef3 Allow sandbox to start without any tasks.
This is the first set of changes to allow multiple containers in a sandbox.
- Changes to allow kernel.Start() without any tasks.
- New control message to StartContainer() in root namespaces.
- Added new function StartSandbox() to keep the existing behavior separate from
when the multi-containers is enabled.
- Test to verify the new control message with one container.

PiperOrigin-RevId: 446792577
2022-05-05 12:59:36 -07:00
Kevin KrakauerandgVisor bot 6a5677d52e netstack: switch from sync/atomic to atomicbitops for 32 bit values
PiperOrigin-RevId: 444446109
2022-04-25 20:41:26 -07:00
Kevin KrakauerandgVisor bot b8dd528b97 prohibit direct use of sync/atomic (u)int64 functions
All atomic 64 bit ints are changed to atomicbitops.(Ui|I)nt64. A nogo checker
enforces that sync/atomic 64 bit functions are not called.

For reviewers: the interesting changes are in the atomicbitops and checkaligned
packages.

Why do this?
- It is very easy to accidentally use atomic values without sync/atomic funcs.
- We have checkatomics, but this is optional and is forgotten in several places.
  - Using a type+checker to enforce this seems less error prone and simpler.
- We get NoCopy protection.
- Use of 64 bit atomics can break 32 bit builds. We have types to handle this
  without any runtime cost, so we might as well use them.

PiperOrigin-RevId: 440473398
2022-04-08 16:06:26 -07:00
gVisor bot 8e49f53bcc Create a usage command that outputs the read wait times from the sentry.
PiperOrigin-RevId: 413167721
2021-11-30 09:20:41 -08:00
Michael Pratt 2db63f8d16 runsc: add global profile collection flags
Add global flags -profile-{block,cpu,heap,mutex} and -trace which
enable collection of the specified profile for the entire duration of a
container execution. This provides a way to definitively start profiling
before that application starts, rather than attempting to race with an
out-of-band `runsc debug`.

Note that only the main boot process is profiled.

This exposed a bug in Task.traceExecEvent: a crash when tracing and
-race are enabled. traceExecEvent is called off of the task goroutine,
but uses the Task as a context, which is a violation of the Task
contract. Switching to the AsyncContext fixes the issue.

Fixes #220
2021-09-16 11:20:37 -04:00
Chong CaiandgVisor bot 689c04f730 Add control configs
Also plumber the controls through runsc

PiperOrigin-RevId: 391594318
2021-08-18 13:13:49 -07:00
Chong CaiandgVisor bot b1d3aea2ea Add Event controls
Add Event controls and implement "stream" commands.

PiperOrigin-RevId: 390691702
2021-08-13 14:20:12 -07:00
Chong CaiandgVisor bot 498bfe542d Add Usage controls
Add Usage controls and implement "usage/usagefd" commands.

PiperOrigin-RevId: 390507423
2021-08-12 18:32:01 -07:00
Chong CaiandgVisor bot 12fcdae1fc Add Fs controls
Add Fs controls and implement "cat" command.

PiperOrigin-RevId: 388812540
2021-08-04 16:44:11 -07:00
Chong CaiandgVisor bot 0e592000ee Add Lifecycle controls
Also change runsc pause/resume cmd to access Lifecycle instead of
containerManager.

PiperOrigin-RevId: 388534928
2021-08-03 13:49:26 -07:00
Fabricio VoznikaandgVisor bot d9aec40d6b Replace whitelist with allowlist
PiperOrigin-RevId: 384586164
2021-07-13 17:20:41 -07:00
Fabricio VoznikaandgVisor bot e9434ae633 Fix stdios ownership
Set stdio ownership based on the container's user to ensure the
user can open/read/write to/from stdios.

1. stdios in the host are changed to have the owner be the same
uid/gid of the process running the sandbox. This ensures that the
sandbox has full control over it.
2. stdios owner owner inside the sandbox is changed to match the
container's user to give access inside the container and make it
behave the same as runc.

Fixes #6180

PiperOrigin-RevId: 384347009
2021-07-12 16:55:40 -07:00
Jamie LiuandgVisor bot 62f45a109d Replace kernel.ExitStatus with linux.WaitStatus.
PiperOrigin-RevId: 383705129
2021-07-08 13:39:15 -07:00
Fabricio VoznikaandgVisor bot 8b198bf9e9 Set RLimits during runsc exec
PiperOrigin-RevId: 378726430
2021-06-10 13:55:10 -07:00
Daniel DaoandDaniel Dao ce690fb046 return root pids with runsc ps
`runsc ps` currently return pid for a task's immediate pid namespace,
which is confusing when there're multiple pid namespaces. We should
return only pids in the root namespace.

Before:

```
1000      1         0         0         ?         02:24     250ms     chrome
1000      1         0         0         ?         02:24     40ms      dumb-init
1000      1         0         0         ?         02:24     240ms     chrome
1000      2         1         0         ?         02:24     2.78s     node
```

After:

```
UID       PID       PPID      C         TTY       STIME     TIME      CMD
1000      1         0         0         ?         12:35     0s        dumb-init
1000      2         1         7         ?         12:35     240ms     node
1000      13        2         21        ?         12:35     2.33s     chrome
1000      27        13        3         ?         12:35     260ms     chrome
```

Signed-off-by: Daniel Dao <[email protected]>
2021-02-24 15:20:43 +00:00
Nicolas LacasseandgVisor bot 431a295377 control.Proc.Exec should default to root pid namespace if none provided.
PiperOrigin-RevId: 358445320
2021-02-19 11:25:35 -08:00