runatlantis / atlantis

Terraform Pull Request Automation
https://www.runatlantis.io
Other
7.68k stars 1.05k forks source link

`atlantis testdrive` doesn't work due to ngrok requiring an account #4218

Open KevinCarterDev opened 7 months ago

KevinCarterDev commented 7 months ago

Community Note


Overview of the Issue

ngrok requires an account and the client needs to authenticate with an authtoken.

Reproduction Steps

% ./atlantis testdrive
Welcome to Atlantis testdrive!

This mode sets up Atlantis on a test repo so you can try it out. We will
- fork an example terraform project to your username
- install terraform (if not already in your PATH)
- install ngrok so we can expose Atlantis to GitHub
- start Atlantis

Press Ctrl-c at any time to exit

github.com username: KevinCarterDev

To continue, we need you to create a GitHub personal access token
with "repo" scope so we can fork an example terraform project.

Follow these instructions to create a token (we don't store any tokens):
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-fine-grained-personal-access-token
- use "atlantis" for the token description
- add "repo" scope
- copy the access token

GitHub access token (will be hidden):
=> forking repo
=> fork completed!
=> terraform found in $PATH at /opt/homebrew/bin/terraform
=> ngrok found in $PATH at /opt/homebrew/bin/ngrok
=> creating secure tunnel
Error: creating ngrok tunnel: timeout, logs:
t=2024-02-07T11:39:51-0700 lvl=info msg="open config file" path=/var/folders/pz/1s31jdrx0fz4gbxgjhkvxmhc0000gp/T/atlantis-testdrive-ngrok-config290247732 err=nil
t=2024-02-07T11:39:51-0700 lvl=info msg="starting web service" obj=web addr=localhost:41414 allow_hosts=[]
t=2024-02-07T11:39:52-0700 lvl=eror msg="failed to reconnect session" obj=tunnels.session obj=csess id=8627fe3d2a25 err="authentication failed: Usage of ngrok requires a verified account and authtoken
.\n\nSign up for an account: https://dashboard.ngrok.com/signup\nInstall your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken\r\n\r\nERR_NGROK_4018\r\n"
t=2024-02-07T11:39:52-0700 lvl=eror msg="session closing" obj=tunnels.session err="authentication failed: Usage of ngrok requires a verified account and authtoken.\n\nSign up for an account: https://d
ashboard.ngrok.com/signup\nInstall your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken\r\n\r\nERR_NGROK_4018\r\n"
t=2024-02-07T11:39:52-0700 lvl=info msg="received stop request" obj=app stopReq="{err:{Remote:true Inner:{Inner:0x140005b72c0}} restart:false}"
t=2024-02-07T11:39:52-0700 lvl=eror msg="terminating with error" obj=app err="authentication failed: Usage of ngrok requires a verified account and authtoken.\n\nSign up for an account: https://dashbo
ard.ngrok.com/signup\nInstall your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken\r\n\r\nERR_NGROK_4018\r\n"
t=2024-02-07T11:39:52-0700 lvl=crit msg="command failed" err="authentication failed: Usage of ngrok requires a verified account and authtoken.\n\nSign up for an account: https://dashboard.ngrok.com/si
gnup\nInstall your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken\r\n\r\nERR_NGROK_4018\r\n"

ERROR:  authentication failed: Usage of ngrok requires a verified account and authtoken.
ERROR:
ERROR:  Sign up for an account: https://dashboard.ngrok.com/signup
ERROR:  Install your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken
ERROR:
ERROR:  ERR_NGROK_4018
ERROR:

Usage:
  atlantis testdrive [flags]

Flags:
  -h, --help   help for testdrive

Logs

Environment details

% ./atlantis version
atlantis 0.27.1 (commit: da67e7d) (build date: 2024-01-21T23:42:15Z)

% ngrok -v
ngrok version 3.5.0

Additional Context

Manually running the command that testdrive runs results in the same error

% ngrok start atlantis --config /var/folders/pz/1s31jdrx0fz4gbxgjhkvxmhc0000gp/T/atlantis-testdrive-ngrok-config290247732 --log stderr --log-format term
INFO[02-07|11:40:54] open config file                         path=/var/folders/pz/1s31jdrx0fz4gbxgjhkvxmhc0000gp/T/atlantis-testdrive-ngrok-config290247732 err=nil
INFO[02-07|11:40:54] starting web service                     obj=web addr=localhost:41414 allow_hosts=[]
EROR[02-07|11:40:54] failed to reconnect session              obj=tunnels.session obj=csess id=b5a7b057bd2d err="authentication failed: Usage of ngrok requires a verified account and authtoken.\n\nSig
n up for an account: https://dashboard.ngrok.com/signup\nInstall your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken\r\n\r\nERR_NGROK_4018\r\n"
EROR[02-07|11:40:54] session closing                          obj=tunnels.session err="authentication failed: Usage of ngrok requires a verified account and authtoken.\n\nSign up for an account: https
://dashboard.ngrok.com/signup\nInstall your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken\r\n\r\nERR_NGROK_4018\r\n"
INFO[02-07|11:40:54] received stop request                    obj=app stopReq="{err:{Remote:true Inner:{Inner:0x140006064d0}} restart:false}"
EROR[02-07|11:40:54] terminating with error                   obj=app err="authentication failed: Usage of ngrok requires a verified account and authtoken.\n\nSign up for an account: https://dashboard
.ngrok.com/signup\nInstall your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken\r\n\r\nERR_NGROK_4018\r\n"
WARN[02-07|11:40:54] failed to check for update               obj=updater err="Post \"https://update.equinox.io/check\": context canceled"
CRIT[02-07|11:40:54] command failed                           err="authentication failed: Usage of ngrok requires a verified account and authtoken.\n\nSign up for an account: https://dashboard.ngrok.c
om/signup\nInstall your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken\r\n\r\nERR_NGROK_4018\r\n"
INFO[02-07|11:40:54] no more state changes                    obj=tunnels.session
NAME:
  start - start tunnels by name from the configuration file

USAGE:
  ngrok start [flags]

DESCRIPTION:
  Starts tunnels by name from the configuration file. You may specify any
  number of tunnel names. You may start all tunnels in the configuration
  file with the --all switch.

TERMS OF SERVICE: https://ngrok.com/tos

EXAMPLES:
  ngrok start dev        # start tunnel named 'dev' in the configuration file
  ngrok start web blog   # start tunnels named 'web' and 'blog'
  ngrok start --all      # start all tunnels defined in the config file

OPTIONS:
      --all                 start all tunnels in the configuration file
      --authtoken string    ngrok.com authtoken identifying a user
      --config strings      path to config files; they are merged if multiple
  -h, --help                help for start
      --log string          path to log file, 'stdout', 'stderr' or 'false' (default "false")
      --log-format string   log record format: 'term', 'logfmt', 'json' (default "term")
      --log-level string    logging level: 'debug', 'info', 'warn', 'error', 'crit' (default "info")
      --none                start running no tunnels

ERROR:  authentication failed: Usage of ngrok requires a verified account and authtoken.
ERROR:
ERROR:  Sign up for an account: https://dashboard.ngrok.com/signup
ERROR:  Install your authtoken: https://dashboard.ngrok.com/get-started/your-authtoken
ERROR:
ERROR:  ERR_NGROK_4018
ERROR:

Adding the --authtoken flag to the command allows this to work

% ngrok start atlantis --config /var/folders/pz/1s31jdrx0fz4gbxgjhkvxmhc0000gp/T/atlantis-testdrive-ngrok-config290247732 --log stderr --log-format term --authtoken <mytoken>
INFO[02-07|11:41:17] open config file                         path=/var/folders/pz/1s31jdrx0fz4gbxgjhkvxmhc0000gp/T/atlantis-testdrive-ngrok-config290247732 err=nil
INFO[02-07|11:41:17] starting web service                     obj=web addr=localhost:41414 allow_hosts=[]
INFO[02-07|11:41:18] client session established               obj=tunnels.session obj=csess id=6a0a27342484
INFO[02-07|11:41:18] tunnel session started                   obj=tunnels.session
INFO[02-07|11:41:18] started tunnel                           obj=tunnels name=atlantis addr=http://localhost:4141 url=https://94af-[ipsnip].ngrok-free.app

Seems like testdrive needs to start asking for the ngrok authtoken to be input.

babyhuey commented 5 months ago

For now, you can run: NGROK_AUTHTOKEN=your_token_here atlantis testdrive and it will work!

mirageglobe commented 3 months ago

interesting. i am getting ngrok path not found even though it exists. Seems the above is installed with brew but why does detecting fail? thank you

=> forking repo
=> fork completed!
=> terraform found in $PATH at /opt/homebrew/Cellar/atlantis/0.28.1/libexec/bin/terraform
=> ngrok not found in $PATH.
=> downloading ngrok
=> downloaded ngrok successfully!
=> creating secure tunnel
Error: creating ngrok tunnel: timeout, logs:
❯ which ngrok
/opt/homebrew/bin/ngrok
mirageglobe commented 3 months ago

For now, you can run: NGROK_AUTHTOKEN=your_token_here atlantis testdrive and it will work!

unfortunately this doesnt seem to work as ngrok didnt pick up the token for some reason. testdrive will download and try to run ngrok from a temp folder and during this process, it generates a new config file everytime. this means the auth token cannot be added.

mikesplain commented 2 months ago

For anyone that comes across this issue, I was able to work around it by installing a local version of atlantis rather than brew. Something like this worked for me:

wget https://github.com/runatlantis/atlantis/releases/download/v0.28.3/atlantis_darwin_arm64.zip
unzip atlantis_darwin_arm64.zip
chmod +x atlantis_darwin_arm64.zip

NGROK_AUTHTOKEN=<yourtoken> ./atlantis testdrive