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

jetcd-launcher: allow starting Etcd Container via non-root user on Linux #1390

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static class Builder {
private List<String> additionalArgs;
private Network network;
private boolean shouldMountDataDirectory = true;
private String user;

public Builder withClusterName(String clusterName) {
this.clusterName = clusterName;
Expand Down Expand Up @@ -114,12 +115,18 @@ public EtcdCluster build() {
debug,
additionalArgs,
network != null ? network : Network.SHARED,
shouldMountDataDirectory);
shouldMountDataDirectory,
user);
}

public Builder withMountedDataDirectory(boolean shouldMountDataDirectory) {
this.shouldMountDataDirectory = shouldMountDataDirectory;
return this;
}

public Builder withUser(String user) {
this.user = user;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public EtcdClusterImpl(
boolean debug,
Collection<String> additionalArgs,
Network network,
boolean shouldMountDataDirectory) {
boolean shouldMountDataDirectory,
String user) {

this.clusterName = clusterName;
this.endpoints = IntStream.range(0, nodes)
Expand All @@ -57,7 +58,8 @@ public EtcdClusterImpl(
.withDebug(debug)
.withAdditionalArgs(additionalArgs)
.withNetwork(network)
.withShouldMountDataDirectory(shouldMountDataDirectory))
.withShouldMountDataDirectory(shouldMountDataDirectory)
.withUser(user))
.collect(toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class EtcdContainer extends GenericContainer<EtcdContainer> {
private Path dataDirectory;
private Collection<String> additionalArgs;
private boolean shouldMountDataDirectory = true;
private String user;

public EtcdContainer(String image, String node, Collection<String> nodes) {
super(image);
Expand Down Expand Up @@ -102,6 +103,18 @@ public EtcdContainer withAdditionalArgs(Collection<String> additionalArgs) {
return self();
}

/**
* Optional values are {@code [ user | user:group | uid | uid:gid | user:gid | uid:group ]}.
* See <a href="https://docs.docker.com/engine/reference/run/#user">User</a> .
*
* @param user Refer to {@link com.github.dockerjava.api.command.CreateContainerCmd#withUser(String)}
* @return self container.
*/
public EtcdContainer withUser(String user) {
this.user = user;
return self();
}

@Override
protected void configure() {
if (!configured.compareAndSet(false, true)) {
Expand All @@ -120,9 +133,13 @@ protected void configure() {
withEnv("ETCD_LOG_LEVEL", this.debug ? "debug" : "info");
withEnv("ETCD_LOGGER", "zap");

String user = System.getenv("TC_USER");
if (user != null) {
withCreateContainerCmdModifier(c -> c.withUser(user));
String tempUser = this.user;
if (tempUser == null) {
tempUser = System.getenv("TC_USER");
}
if (tempUser != null) {
String finalUser = tempUser;
withCreateContainerCmdModifier(c -> c.withUser(finalUser));
}

if (ssl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ public Builder withMountDirectory(boolean mountDirectory) {
return this;
}

public Builder withUser(String user) {
builder.withUser(user);
return this;
}

public EtcdClusterExtension build() {
return new EtcdClusterExtension(builder.build());
}
Expand Down