doctl icon indicating copy to clipboard operation
doctl copied to clipboard

Errors when using Git for Windows

Open iranvir opened this issue 6 years ago • 20 comments

Doctl says unknown terminal, when trying doctl auth init: So, I have been using doctl on Windows via the Git Bash utility, powershell isn't my thing. I download the doctl.exe to bin directory in my home folder. And invoke it using git bash CLI.

This used to work just fine till 1.36 but upon trying doctl auth init on a fresh Windows 10 install I am getting this error:

Ranvir@WestWind MINGW64 /
$ doctl auth init
Error: unable to read DigitalOcean access token: unknown terminal

This is easily circumvented using PowerShell, but with Git Bash the error is very annoying. Since this wasn't an issue in previous releases, but is an issue now, I thought I will share it with everyone.

Hopefully, we aren't relying on Windows' underlying brokeness.

Environment: OS: Windows 10, 1909 up-to-date Arch: x86_64 doctl version 1.37.0-release (downloaded from GitHub releases page)

Additional Details: Using the --trace flag doesn't print anything extra than what is mentioned above.

iranvir avatar Jan 30 '20 23:01 iranvir

Hey @sranvir, thanks for the report.

I've reproduced this with multiple versions of doctl now, so I wonder if it's an issue with the Git Bash terminal. The issue happens here,

https://github.com/digitalocean/doctl/blob/884a996946e1691b2100877a075c7fdee902a843/commands/auth.go#L44-L46

Somehow, in Git Bash, it doesn't think that standard output is a terminal. I also tried switching it to standard input, and using syscall.Stdout and syscall.Stdin, but the error still occurred.

Do you happen to know which version of doctl you were running when this worked?


As a workaround for Git Bash, you can run doctl auth init -t <YOUR_TOKEN>, which skips reading the token from the terminal.

bentranter avatar Jan 31 '20 21:01 bentranter

I tried it with doctl 1.36 and 1.35 (don’t remember the exact patch numbers) and it worked just fine, if memory serves me right. But here’s the thing, Git bash has also released a new version since then git 2.25 so maybe I need to see their changelog. Sorry, I wasn’t much help here :(

iranvir avatar Jan 31 '20 21:01 iranvir

@sranvir No problem, thanks for the info! Our team is looking to see if there's a better workaround for this, so I'll leave this issue open and keep you updated on any progress we make.

bentranter avatar Jan 31 '20 21:01 bentranter

One last thing though, everything else works just fine, after token is added. I can list my droplets, etc. How does one part of the CLI thinks terminal is the stdout, while the other doesn’t.

iranvir avatar Jan 31 '20 21:01 iranvir

@sranvir That's a good question – while I'm not 100% sure about the answer, my understanding is that stdout and stdin are fine on Git Bash, but somehow their file descriptor is not what Go on Windows expects it to be. The only time we need to use those file descriptors is when Go changes the terminal's flags to prevent input from being echoed, so it ends up being broken only for that command.

bentranter avatar Jan 31 '20 21:01 bentranter

the terminal's flags to prevent input from being echoed.

You mean, like when we type our passwords into the terminal and nothing shows up?

iranvir avatar Jan 31 '20 21:01 iranvir

@sranvir Yup, exactly.

bentranter avatar Jan 31 '20 21:01 bentranter

Awesome! I will be very curious to learn more when the issue is resolved. Thanks a tonne for your time and explanations. :)

iranvir avatar Jan 31 '20 21:01 iranvir

Having the same issue when trying to login to doctl from a Travis terminal.

taniarascia avatar Feb 03 '20 00:02 taniarascia

Tried the command doctl auth init -t <token> ? Ben recommended it above, as a means to circumvent the issue for now.

iranvir avatar Feb 03 '20 01:02 iranvir

Thanks, can confirm using -t works on Travis.

taniarascia avatar Feb 03 '20 04:02 taniarascia

with drone still fails.

doctl version 1.43.0-release
Git commit hash: 1b6d0b8

jessequinn avatar May 21 '20 21:05 jessequinn

@jessequinn Sorry, I'm not sure what drone is, is it Drone? If so, what was the command that caused the failure – was it doctl auth init?

bentranter avatar May 25 '20 18:05 bentranter

@bentranter sorry drone. it is for CI/CD. yes doctl auth init -t token. in the end i had to use the doctl auth init -c /somefolder/.config/doctl/config.yaml to get it to work with Drone.

jessequinn avatar May 25 '20 20:05 jessequinn

Same issue at BitBucket Pipelines using image: atlassian/default-image:2 When I'm using the following:

doctl auth init --context name --access-token token

But works without --context

doctl auth init --access-token token

the-homeless-god avatar Jun 24 '20 22:06 the-homeless-god

Glad to see that I'm not the only one. I am having the same error with Gitlab CI/CD. I'm using the docker-in-docker image. Seems to be using docker:latest for the base image. This is a depressing failure for me since I'm running to doctl because Gitlab's CI/CD into DO Kube is broken on Gitlab's side for some reason. Doctl, you're my only hope!

doctl auth init --context corona --access-token ${DO_TOKEN} fails. doctl auth init --access-token ${DO_TOKEN} fails. doctl auth init --context corona -t ${DO_TOKEN} fails. echo ${DO_TOKEN} | doctl auth init --context corona fails.

amartincolby avatar Aug 25 '20 05:08 amartincolby

@amartincolby Could you provide any further details about the failure you are seeing? I've tried to reproduce it, but I've been unable to do so.

A .gitlab-ci.yml file like this succeeds for me on gitlab.com:

before_script:
  - cd /root/ && wget https://github.com/digitalocean/doctl/releases/download/v1.46.0/doctl-1.46.0-linux-amd64.tar.gz
  - tar xf /root/doctl-1.46.0-linux-amd64.tar.gz
  - mv /root/doctl /usr/local/bin
  - doctl auth init --access-token $DO_TOKEN

test:
  script:
    - doctl account get

I also tried specifying the image you mentioned, but this also succeeds:

image: docker:latest

before_script:
  - cd /root/ && wget https://github.com/digitalocean/doctl/releases/download/v1.46.0/doctl-1.46.0-linux-amd64.tar.gz
  - tar xf /root/doctl-1.46.0-linux-amd64.tar.gz
  - mv /root/doctl /usr/local/bin
  - doctl auth init --access-token $DO_TOKEN

test:
  script:
    - doctl account get

andrewsomething avatar Aug 25 '20 15:08 andrewsomething

Solved by custom script like the following against registry that created at DigitalOcean:

  • in root of repo (config.json)
{
  "auths": {
    "registry.digitalocean.com": {
      "auth": "DOCKER_AUTH_TOKEN"
    }
  },
  "HttpHeaders": {
    "User-Agent": "Docker-Client/19.03.8 (linux)"
  }
}

  • in ci steps
# make a root folder for docker
mkdir ~/.docker

# addition of env token to config file
sed -i 's/DOCKER_AUTH_TOKEN/'$DOCKER_AUTH'/g' config.json

# move a config to a root folder of docker
mv config.json ~/.docker/config.json

# login to docker
docker login $REGISTRY_HERE

# build container
docker build --tag $TAG_HERE:latest .

# push container
docker push $TAG_HERE:latest

the-homeless-god avatar Aug 25 '20 20:08 the-homeless-god

@amartincolby Could you provide any further details about the failure you are seeing? I've tried to reproduce it, but I've been unable to do so.

A .gitlab-ci.yml file like this succeeds for me on gitlab.com:

before_script:
  - cd /root/ && wget https://github.com/digitalocean/doctl/releases/download/v1.46.0/doctl-1.46.0-linux-amd64.tar.gz
  - tar xf /root/doctl-1.46.0-linux-amd64.tar.gz
  - mv /root/doctl /usr/local/bin
  - doctl auth init --access-token $DO_TOKEN

test:
  script:
    - doctl account get

I also tried specifying the image you mentioned, but this also succeeds:

image: docker:latest

before_script:
  - cd /root/ && wget https://github.com/digitalocean/doctl/releases/download/v1.46.0/doctl-1.46.0-linux-amd64.tar.gz
  - tar xf /root/doctl-1.46.0-linux-amd64.tar.gz
  - mv /root/doctl /usr/local/bin
  - doctl auth init --access-token $DO_TOKEN

test:
  script:
    - doctl account get

I must have missed a combination. Putting the doctl commands in the before_script worked, but only if I don't use context. If I use a context, I receive this:

'doctl-1.46.0-linux-amd64.tar.gz' saved
$ tar xf /root/doctl-1.46.0-linux-amd64.tar.gz
$ mv /root/doctl /usr/local/bin
$ doctl auth init --context corona --access-token $DO_TOKEN
Error: Unable to read DigitalOcean access token: unknown terminal
ERROR: Job failed: exit code 1

amartincolby avatar Aug 26 '20 03:08 amartincolby

@amartincolby That issue is being tracked in https://github.com/digitalocean/doctl/issues/703

andrewsomething avatar Aug 26 '20 14:08 andrewsomething