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

feat: Add optional container user namespace for Ryuk #2702

Open
wants to merge 7 commits into
base: main
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
1 change: 1 addition & 0 deletions docs/features/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ but does not allow starting privileged containers, you can turn off the Ryuk con
1. You can specify the connection timeout for Ryuk by setting the `TESTCONTAINERS_RYUK_CONNECTION_TIMEOUT` **environment variable**, or the `ryuk.connection.timeout` **property**. The default value is 1 minute.
1. You can specify the reconnection timeout for Ryuk by setting the `TESTCONTAINERS_RYUK_RECONNECTION_TIMEOUT` **environment variable**, or the `ryuk.reconnection.timeout` **property**. The default value is 10 seconds.
1. You can configure Ryuk to run in verbose mode by setting any of the `ryuk.verbose` **property** or the `TESTCONTAINERS_RYUK_VERBOSE` **environment variable**. The default value is `false`.
1. You can configure which container user namespace to use for the Ryuk container by setting the `TESTCONTAINERS_RYUK_CONTAINER_USER_NAMESPACE` **environment variable**, or the `ryuk.container.user.namespace` **property**.

!!!info
For more information about Ryuk, see [Garbage Collector](garbage_collector.md).
Expand Down
10 changes: 10 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ type Config struct {
//
// Environment variable: TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED
RyukPrivileged bool `properties:"ryuk.container.privileged,default=false"`

// RyukUserNamespace is the container user namespace used to run the Garbage Collector container.
//
// Environment variable: TESTCONTAINERS_RYUK_CONTAINER_USER_NAMESPACE
RyukUserNamespace string `properties:"ryuk.container.user.namespace,default="`

// RyukReconnectionTimeout is the time to wait before attempting to reconnect to the Garbage Collector container.
//
Expand Down Expand Up @@ -126,6 +131,11 @@ func read() Config {
config.RyukPrivileged = ryukPrivilegedEnv == "true"
}

ryukUserNamespaceEnv := os.Getenv("TESTCONTAINERS_RYUK_CONTAINER_USER_NAMESPACE")
if ryukUserNamespaceEnv != "" {
config.RyukUserNamespace = ryukUserNamespaceEnv
}

ryukVerboseEnv := os.Getenv("TESTCONTAINERS_RYUK_VERBOSE")
if parseBool(ryukVerboseEnv) {
config.RyukVerbose = ryukVerboseEnv == "true"
Expand Down
1 change: 1 addition & 0 deletions reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ func newReaper(ctx context.Context, sessionID string, provider ReaperProvider) (
WaitingFor: wait.ForListeningPort(listeningPort),
Name: reaperContainerNameFromSessionID(sessionID),
HostConfigModifier: func(hc *container.HostConfig) {
hc.UsernsMode = container.UsernsMode(tcConfig.RyukUserNamespace)
hc.AutoRemove = true
hc.Binds = []string{dockerHostMount + ":/var/run/docker.sock"}
hc.NetworkMode = Bridge
Expand Down