digitalocean / doctl

The official command line interface for the DigitalOcean API.
https://docs.digitalocean.com/reference/doctl/
Apache License 2.0
3.26k stars 397 forks source link

Errors when using Git for Windows #733

Open iranvir opened 4 years ago

iranvir commented 4 years ago

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.

bentranter commented 4 years ago

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.

iranvir commented 4 years ago

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 :(

bentranter commented 4 years ago

@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.

iranvir commented 4 years ago

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.

bentranter commented 4 years ago

@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.

iranvir commented 4 years ago

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?

bentranter commented 4 years ago

@sranvir Yup, exactly.

iranvir commented 4 years ago

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

taniarascia commented 4 years ago

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

iranvir commented 4 years ago

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

taniarascia commented 4 years ago

Thanks, can confirm using -t works on Travis.

jessequinn commented 4 years ago

with drone still fails.

doctl version 1.43.0-release
Git commit hash: 1b6d0b8
bentranter commented 4 years ago

@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?

jessequinn commented 4 years ago

@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.

the-homeless-god commented 4 years ago

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

amartincolby commented 4 years ago

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.

andrewsomething commented 4 years ago

@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
the-homeless-god commented 4 years ago

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

{
  "auths": {
    "registry.digitalocean.com": {
      "auth": "DOCKER_AUTH_TOKEN"
    }
  },
  "HttpHeaders": {
    "User-Agent": "Docker-Client/19.03.8 (linux)"
  }
}
# 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
amartincolby commented 4 years ago

@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
andrewsomething commented 4 years ago

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