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

configContainsAuth check throws exception for valid docker config files. #477

Closed
ghost opened this issue Apr 3, 2023 · 2 comments · Fixed by #481
Closed

configContainsAuth check throws exception for valid docker config files. #477

ghost opened this issue Apr 3, 2023 · 2 comments · Fixed by #481
Assignees

Comments

@ghost
Copy link

ghost commented Apr 3, 2023

I was having issues with the cli authenticating to a private registry. After digging through the trace logs and searching the source code I discovered that the following line was causing me grief. The issue is that the configContainsAuth check will throw an exception on Object.keys(dockerConfig.credHelpers) when the $HOME/.docker/config.json file does not contain an entry for credHelpers.

You could probably just nullish coalesce the access into the .credHelpers and .auths to solve the issue, something like below?

configContainsAuth = Object.keys(dockerConfig.credHelpers ?? {}).length > 0 || !!dockerConfig.credsStore || Object.keys(dockerConfig.auths ?? {}).length > 0;
@NigelRook
Copy link

NigelRook commented Apr 5, 2023

+1 this is also causing our CI to fail since the update to 0.36.0

Redacted contents of ~/.docker/config.json:

{
	"auths": {
		"redacted.dkr.ecr.us-west-2.amazonaws.com": {
			"auth": "redacted"
		}
	}
}

Trace output of devcontainer up:

[2023-04-05T12:25:49.728Z] @devcontainers/cli 0.36.0. Node.js v14.18.1. linux 5.15.0-1020-aws x64.
[2023-04-05T12:25:49.728Z] Start: Run: docker buildx version
[2023-04-05T12:26:01.110Z] Stop (11382 ms): Run: docker buildx version
[2023-04-05T12:26:01.110Z] github.com/docker/buildx v0.5.1-docker 11057da37336192bfc57d81e02359ba7ba848e4a
[2023-04-05T12:26:01.110Z] 
[2023-04-05T12:26:01.111Z] Start: Resolving Remote
[2023-04-05T12:26:01.115Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=/mnt/jenkins/workspace/imp_server-pipeline --filter label=devcontainer.config_file=redacted/.devcontainer/devcontainer.json
[2023-04-05T12:26:01.149Z] Stop (34 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=/mnt/jenkins/workspace/imp_server-pipeline --filter label=devcontainer.config_file=redacted/.devcontainer/devcontainer.json
[2023-04-05T12:26:01.150Z] Start: Run: docker ps -q -a --filter label=devcontainer.local_folder=redacted
[2023-04-05T12:26:01.182Z] Stop (32 ms): Run: docker ps -q -a --filter label=devcontainer.local_folder=redacted
[2023-04-05T12:26:01.183Z] Start: Run: docker-compose version --short
[2023-04-05T12:26:04.635Z] Stop (3452 ms): Run: docker-compose version --short
[2023-04-05T12:26:04.635Z] Docker Compose version: 1.29.2
[2023-04-05T12:26:04.636Z] Start: Run: docker ps -q -a --filter label=com.docker.compose.project=redacted --filter label=com.docker.compose.service=app
[2023-04-05T12:26:04.670Z] Stop (34 ms): Run: docker ps -q -a --filter label=com.docker.compose.project=redacted --filter label=com.docker.compose.service=app
[2023-04-05T12:26:04.671Z] Start: Run: docker-compose -f redacted/.devcontainer/docker-compose.yml config
[2023-04-05T12:26:05.111Z] Stop (440 ms): Run: docker-compose -f redacted/.devcontainer/docker-compose.yml config
[2023-04-05T12:26:05.111Z] redacted

[2023-04-05T12:26:05.114Z] Start: Run: docker -v
[2023-04-05T12:26:05.150Z] Stop (36 ms): Run: docker -v
[2023-04-05T12:26:05.150Z] Start: Run: docker events --format {{json .}} --filter event=start
[2023-04-05T12:26:05.153Z] PersistedPath=/tmp/devcontainercli-jenkins, ContainerHasLabels=false
[2023-04-05T12:26:05.153Z] Start: Run: docker-compose -f redacted/.devcontainer/docker-compose.yml config
[2023-04-05T12:26:05.585Z] Stop (432 ms): Run: docker-compose -f redacted/.devcontainer/docker-compose.yml config
[2023-04-05T12:26:05.585Z] redacted
[2023-04-05T12:26:05.588Z] Start: Run: docker inspect --type image redacted
[2023-04-05T12:26:05.621Z] Stop (33 ms): Run: docker inspect --type image redacted
[2023-04-05T12:26:05.622Z] > input: docker.io/redacted
[2023-04-05T12:26:05.622Z] >
[2023-04-05T12:26:05.622Z] > resource: docker.io/redacted
[2023-04-05T12:26:05.622Z] > id: core-build-container
[2023-04-05T12:26:05.622Z] > version: redacted
[2023-04-05T12:26:05.622Z] > owner: redacted
[2023-04-05T12:26:05.622Z] > namespace: redacted
[2023-04-05T12:26:05.622Z] > registry: docker.io
[2023-04-05T12:26:05.622Z] > path: redacted
[2023-04-05T12:26:05.622Z] manifest url: https://registry-1.docker.io/v2/redacted
[2023-04-05T12:26:05.648Z] [httpOci] Attempting to authenticate via 'Bearer' auth.
[2023-04-05T12:26:05.650Z] [httpOci] Failed to read docker config.json: TypeError: Cannot convert undefined or null to object
[2023-04-05T12:26:05.651Z] [httpOci] Invoking platform default credential helper 'secret'
[2023-04-05T12:26:05.651Z] Start: Run: docker-credential-secret get
[2023-04-05T12:26:05.654Z] Stop (3 ms): Run: docker-credential-secret get
events.js:377
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at afterWriteDispatched (internal/stream_base_commons.js:156:25)
    at writeGeneric (internal/stream_base_commons.js:147:3)
    at Socket._writeGeneric (net.js:798:11)
    at Socket._write (net.js:810:8)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at Socket.Writable.write (internal/streams/writable.js:303:10)
    at /usr/local/src/nvm/versions/node/v14.18.1/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:1640:265
    at new Promise (<anonymous>)
    at $n (/usr/local/src/nvm/versions/node/v14.18.1/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:1639:15553)
    at async tD (/usr/local/src/nvm/versions/node/v14.18.1/lib/node_modules/@devcontainers/cli/dist/spec-node/devContainersSpecCLI.js:1753:10021)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}

@joshspicer joshspicer self-assigned this Apr 5, 2023
@joshspicer
Copy link
Member

Thank you both for the reports, taking a look.

joshspicer added a commit that referenced this issue Apr 5, 2023
* null coalesce when detecting docker cred helpers (#477)

* remove whitespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants