[solved] Unauthorized when using plugins/docker to build and push image

Hi there. I’m new to drone, so this is probably a configuration issue, but from what I read, I think I have things configured correctly. The issue is, the image I have builds, but then i get ‘unauthorized: incorrect username or password’ when trying to push to dockerhub. Here are all of the pieces that I’m aware of, and how I have them configured:

  build_base_image:
    image: plugins/docker:latest
    environment:
      - DOCKER_LAUNCH_DEBUG=true
    repo: corylogan/alpine-ruby-image-manipulation
    tags:
      - latest
      - ${DRONE_COMMIT_SHA:8}
    dockerfile: docker/base/Dockerfile
    context: docker/base/
    when:
      branch: master

I’ve then added my secrets using:

drone secret add --image=plugins/docker:* counterbeing/myrepo DOCKER_USERNAME corylogan
drone secret add --image=plugins/docker:* counterbeing/myrepo DOCKER_PASSWORD mypassword

And signed the .drone.yml file using drone sign counterbeing/myrepo.

I’m trying to keep my password out of the config file for obvious reasons. The plugins/docker docs show removing the keys for username and password from the config, so I think i did that correctly.

Any idea why this might be failing?

The best way to debug is to run the plugin locally with you input parameters. For instructions see https://github.com/drone-plugins/drone-docker#usage

The error indicates to me that username and password were provided.

unauthorized: incorrect username or password

This is because if username and password are blank you would see message in the logs:

Registry credentials not provided. Guest mode enabled

It therefore sounds like the username or password is wrong.

Note that you can run this plugin with debug mode enabled. I’m not sure, though, how much additional information it will provide for this error.

  build_base_image:
    image: plugins/docker:latest
    environment:
      - DOCKER_LAUNCH_DEBUG=true
    repo: corylogan/alpine-ruby-image-manipulation
    tags:
      - latest
      - ${DRONE_COMMIT_SHA:8}
    dockerfile: docker/base/Dockerfile
    context: docker/base/
+  debug: true
    when:
      branch: master

Awesome, that’s already helpful. I wasn’t convinced my environment variables were making it through from my drone secrets. I’ll give local testing a shot, but I know I’m already authenticated… Thanks for helping me bisect the problem :slight_smile:

I think perhaps I’m a bit confused about how to use it like this. When I try the following, it builds the image and doesn’t push, so, that’s a good start:

docker run --rm \
  -e PLUGIN_TAG=latest \
  -e PLUGIN_REPO=corylogan/alpine-ruby-image-manipulation \
  -e DRONE_COMMIT_SHA=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
  -v $(pwd):$(pwd) \
  -w $(pwd) \
  --privileged \
  plugins/docker --dry-run

I do have a few questions that seem unanswered by the readme, maybe you know more, but, what’s the DRONE_COMMIT_SHA? Is that a commit sha from my repo? And looking through a little of the source code, it looks like i’m using the ENV vars below correctly to set things like username… anyway

…then, the moment I add the env variables for my username, and/or my password like this

docker run --rm \
  -e PLUGIN_TAG=latest \
  -e PLUGIN_REPO=corylogan/alpine-ruby-image-manipulation \
  -e DRONE_COMMIT_SHA=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
  -e PLUGIN_USERNAME=corylogan \ 
  -v $(pwd):$(pwd) \
  -w $(pwd) \
  --privileged \
  plugins/docker --dry-run

The docker command returns an error.

docker: Error parsing reference: " " is not a valid repository/tag.                                                                     │=> true
See 'docker run --help'.

I can only imagine it’s something to do with how i’m formatting it…

Thanks!

Not a lot changed here, I’m not sure what happened to that error, but now I’ve moved on to

  docker run --rm \
    -e PLUGIN_TAG=latest \
    -e PLUGIN_REPO=corylogan/alpine-ruby-image-manipulation \
    -e DOCKER_EMAIL=myemail \
    -e DOCKER_USERNAME=corylogan \
    -e DOCKER_PASSWORD=mypassword \
    -e DRONE_COMMIT_SHA=d8dbe4d94f15fe89232e0402c6e8a0ddf21af3ab \
    -v $(pwd):$(pwd) \
    -w $(pwd) \
    --privileged \
    plugins/docker

Error authenticating: exit status 1

And, I have success!

The problem appears to be with my password. It had two special characters in it ^ and >. Changing my password fixed the issue, though, I’m not sure if there’s another solution that doesn’t involve changing passwords. But, I’m happy :slight_smile:

Thank you @brad for the advice!

Glad you figured it out. I think the use of > could cause problems from the command line because bash interprets > as a special character. I haven’t tested, but quoting the string could solve the issue in this case.