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

[Bug]: missleding error when user has no permissions on docker.sock #9195

Closed
jtnord opened this issue Sep 4, 2024 · 1 comment
Closed

[Bug]: missleding error when user has no permissions on docker.sock #9195

jtnord opened this issue Sep 4, 2024 · 1 comment
Labels

Comments

@jtnord
Copy link

jtnord commented Sep 4, 2024

Module

Core

Testcontainers version

1.19.8

Using the latest Testcontainers version?

No

Host OS

Linux

Host Arch

amd64

Docker version

Client:
 Version:           27.1.1
 API version:       1.46
 Go version:        go1.21.12
 Git commit:        6312585
 Built:             Tue Jul 23 19:55:52 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Desktop  ()
 Engine:
  Version:          27.1.1
  API version:      1.46 (minimum version 1.24)
  Go version:       go1.21.12
  Git commit:       cc13f95
  Built:            Tue Jul 23 19:57:19 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.19
  GitCommit:        2bf793ef6dc9a18e00cb12efb64355c2c9d5eb41
 runc:
  Version:          1.7.19
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

Test containers failed to start reporting "Could not find a valid Docker environment. Please see logs and check configuration"
with the following in the logs WARNING: DOCKER_HOST unix:///var/run/docker.sock is not listening

This is incorrect and missleading as verified by running the docker command.

After much confusion it was realized that the docker.sock did exist but was not available (rw) to the current user (the docker binary was suid)

Relevant log output

WARNING: DOCKER_HOST unix:///var/run/docker.sock is not listening

Additional Information

this problem would still happen in the latest version.

if (!new File(dockerHost.getPath()).exists()) {
log.debug("DOCKER_HOST socket file '{}' does not exist", dockerHost.getPath());
return false;
}
checks that the file exists, but does not check that it is read and writable before continuing.

If the file is not read/write for the current user, but exists, you fall through to

try (Socket socket = socketProvider.call()) {
Duration timeout = Duration.ofMillis(200);
Awaitility
.await()
.atMost(TestcontainersConfiguration.getInstance().getClientPingTimeout(), TimeUnit.SECONDS)
.pollInterval(timeout)
.pollDelay(Duration.ofSeconds(0)) // start checking immediately
.ignoreExceptionsInstanceOf(SocketTimeoutException.class)
.untilAsserted(() -> socket.connect(socketAddress, (int) timeout.toMillis()));
return true;
} catch (Exception e) {
log.warn("DOCKER_HOST {} is not listening", dockerHost);
return false;
}
which emits the incorrect message. (the server is listening, just the current user is not allowed to talk to it!)

Can most likely be easily reproduced by attempting to run test-containers as a user that is not a member of the docker group

@eddumelendez
Copy link
Member

#8055 has been merged and should fix this.

@eddumelendez eddumelendez closed this as not planned Won't fix, can't repro, duplicate, stale Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants