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

Unable to update commit status: making request ... unexpected status code: 401, body #54

Closed
cjs226 opened this issue Jun 6, 2019 · 9 comments

Comments

@cjs226
Copy link

cjs226 commented Jun 6, 2019

I'm running into problems, presumably with bitbucket authentication.

I've verified the bitbucket username and app password using curl.

My terraform.tfvars has the following (with actual username and app password):

atlantis_bitbucket_user = "foo"
atlantis_bitbucket_user_token = "bar"

I see the ATLANTIS_BITBUCKET_USER populated correctly as an environment variable for the Fargate container.

However, when I test it fails with the following:

2019/06/06 02:52:20+0000 [DBUG] events_controller.go:100 server: Handling Bitbucket Cloud post
2019/06/06 02:52:20+0000 [DBUG] events_controller.go:154 server: Handling as comment created event
2019/06/06 02:52:20+0000 [INFO] events_controller.go:367 server: Parsed comment as command="plan" verbose=false dir="" workspace="" project="" flags=""
2019/06/06 02:52:20+0000 [DBUG] events_controller.go:389 server: Executing command
2019/06/06 02:52:20+0000 [INFO] middleware.go:42 server: POST /events – respond HTTP 200
2019/06/06 02:52:20+0000 [WARN] command_runner.go:208 foo/terraform#24: Unable to update commit status: making request "POST https://api.bitbucket.org/2.0/repositories/foo/terraform/commit/3a050fbb589a/statuses/build" unexpected status code: 401, body:
2019/06/06 02:52:20+0000 [DBUG] project_command_builder.go:102 foo/terraform#24: Got workspace lock
2019/06/06 02:52:21+0000 [WARN] command_runner.go:223 foo/terraform#24: Unable to update commit status: making request "POST https://api.bitbucket.org/2.0/repositories/foo/terraform/commit/3a050fbb589a/statuses/build" unexpected status code: 401, body:
2019/06/06 02:52:21+0000 [EROR] command_runner.go:383 foo/terraform#24: Making request "GET https://api.bitbucket.org/2.0/repositories/foo/terraform/pullrequests/24/diffstat" unexpected status code: 401, body:
2019/06/06 02:52:21+0000 [EROR] command_runner.go:390 foo/terraform#24: Unable to comment: making request "POST https://api.bitbucket.org/2.0/repositories/foo/terraform/pullrequests/24/comments" unexpected status code: 401, body:
@lkysow
Copy link

lkysow commented Jun 6, 2019

Have you verified via curl that your credentials are correct?

curl -v -u foo:bar https://api.bitbucket.org/2.0/repositories/foo/terraform/commit/3a050fbb589a/statuses

401 is the code you get for bad authentication.

@cjs226
Copy link
Author

cjs226 commented Jun 6, 2019

@lkysow, yes sir:

{"pagelen": 10, "values": [{"key": "ci/circleci: build", "description": "Your tests passed on CircleCI!", "repository": {"links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/foo/terraform"}, "html": {"href": "https://bitbucket.org/foo/terraform"}, "avatar": {"href": "https://bytebucket.org/ravatar/%7B3ec3ab0f-8649-454b-924a-8caa1d996f59%7D?ts=2140477"}}, "type": "repository", "name": "terraform", "full_name": "foo/terraform", "uuid": "{3ec3ab0f-8649-454b-924a-8caa1d996f59}"}, "url": "https://circleci.com/bb/foo/terraform/79?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=bitbucket-build-link", "links": {"commit": {"href": "https://api.bitbucket.org/2.0/repositories/foo/terraform/commit/3a050fbb589ad4fd8e04ffc56831d3235bdcaff5"}, "self": {"href": "https://api.bitbucket.org/2.0/repositories/foo/terraform/commit/3a050fbb589ad4fd8e04ffc56831d3235bdcaff5/statuses/build/ci/circleci:%20build"}}, "refname": null, "state": "SUCCESSFUL", "created_on": "2019-06-05T21:30:18.348516+00:00", "commit": {"hash": "3a050fbb589ad4fd8e04ffc56831d3235bdcaff5", "type": "commit", "links": {"self": {"href": "https://api.bitbucket.org/2.0/repositories/foo/terraform/commit/3a050fbb589ad4fd8e04ffc56831d3235bdcaff5"}, "html": {"href": "https://bitbucket.org/foo/terraform/commits/3a050fbb589ad4fd8e04ffc56831d3235bdcaff5"}}}, "updated_on": "2019-06-05T21:30:36.926274+00:00", "type": "build", "name": "ci/circleci: build"}], "page": 1, "size": 1}

@lkysow
Copy link

lkysow commented Jun 6, 2019

Looking at the tf code, it looks like it's being passed in correctly. I'd like to fully eliminate the chances of the credentials being passed to Atlantis being incorrect. Can you verify what values were passed in to the container by creating a custom workflow that echo's out the environment variables?

# atlantis.yaml
version: 3
projects:
- dir: .
  workflow: echo
workflows:
  echo:
    plan:
      steps:
      - run: echo $ATLANTIS_BITBUCKET_USER
      - run: echo $ATLANTIS_BITBUCKET_TOKEN

@cjs226
Copy link
Author

cjs226 commented Jun 6, 2019

Sorry, where do I look to see the actual echo'ing out? (sorry, I'm new to Fargate)

I see in CloudWatch Logs the commands run successfully:

2019/06/06 17:37:06+0000 [INFO] run_step_runner.go:55 foo/terraform#24: Successfully ran "echo $ATLANTIS_BITBUCKET_USER_TOKEN" in "/home/atlantis/.atlantis/repos/foo/terraform/24/default"
2019/06/06 17:37:06+0000 [INFO] run_step_runner.go:55 foo/terraform#24: Successfully ran "echo $ATLANTIS_BITBUCKET_TOKEN" in "/home/atlantis/.atlantis/repos/foo/terraform/24/default"

In the container's environment variables I see:

ATLANTIS_BITBUCKET_TOKEN | /atlantis/bitbucket/user/token

even though I've set both atlantis_bitbucket_user_token AND atlantis_bitbucket_token to the bitbucket app password. atlantis_bitbucket_user_token is referenced in the documentation. I added atlantis_bitbucket_token after you noted it in the debugging step above.

@cjs226
Copy link
Author

cjs226 commented Jun 6, 2019

Sigh.. After far too long, I realized the output was being added as a comment to the PR. The good news is 1) the token was being written correctly and 2) after one of the 362 steps I've taken today, Atlantis is working for me now.

Thanks for your help!

@cjs226 cjs226 closed this as completed Jun 6, 2019
@lkysow
Copy link

lkysow commented Jun 6, 2019

🎉 so what was the problem in the end? For others who stumble on this.

@cjs226
Copy link
Author

cjs226 commented Jun 7, 2019

Unfortunately, I honestly don't know.

@smilite
Copy link

smilite commented Jul 2, 2019

I was testing my atlantis instance with my repos and I had the same error. My bot had no access to the repos

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants