Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go get private bitbucket repo giving 403 forbidden

Tags:

go

go-get

On execution of go get bitbucket.org/../..

I get this error

yash.jain projectname % go get bitbucket.org/../..
go: bitbucket.org/../..
https://api.bitbucket.org/2.0/repositories/../..?fields=scm: 403 Forbidden
go: error loading module requirements

What I tried

  • Setup the ssh key (Working as expected, tested by pushing and pulling the code)

  • Set the go env variables to this:

     GOPRIVATE=""
     GOPROXY="direct"
     GOSUMDB="off"
    
  • .gitconfig looks like this

     [url "[email protected]:"]
         insteadOf = https://bitbucket.org/
     [user]
         email = [email protected]
         name = yashjain
    
  • Added keys to ssh-agent

     ssh-add -l
     ssh-add -k
    
  • .ssh/config file looks like this

     Host bitbucket.org
       HostName bitbucket.org
       User git
       IdentityFile ~/.ssh/id_rsa
       UseKeychain yes
       StrictHostKeyChecking no
    

Still, I get the same error. Please let me know If I'm doing something wrong.

like image 894
yashjain12yj Avatar asked Dec 17 '22 12:12

yashjain12yj


1 Answers

These are the steps I tried to make it work.

  1. Setup SSH key and connect to bitbucket. I used sourcetree gui by bitbucket to connect using ssh.
  2. Set the GOPRIVATE=bitbucket.org/<orgname>/*

* is to allow all the repo of the org.

After these 2 steps I am able to import the package.

Note: Sourcetree is only available to Mac and Windows.

Using Commnd Line: For Linux/Mac/Windows:

  1. git config --global url."[email protected]:".insteadOf "https://bitbucket.org/"
  2. Set the GOPRIVATE=bitbucket.org/<orgname>/*

Update You might receive the 404 error even after above configuration.

Error
reading https://api.bitbucket.org/2.0/repositories/xyz/privaterepo?fields=scm: 404 Not Found

Bitbucket recently update their APIs for private repository and due to which certain golang version breaks.

Users who do not have access to a private repository will receive 404 (not found) response codes instead of 403 (forbidden) response codes to mask the existence of a private repository at a given URL path.
Rolling out these changes will break previous versions of Go due to the fact that the go command relies on a 403 response to fetch repositories hosted on Bitbucket Cloud.
To ensure that you will not run into any issues, update GoLang to the latest version.

  1. Ensure you are on a supported version of GoLang: 1.18, 1.17, or 1.16.
  2. If you are using 1.17 or 1.16, ensure you are on the latest patch (1.17.7 or 1.16.14)

This will be in effect from June 1st 2022.

Changes to Bitbucket API Requires Latest Version of Go

like image 119
Shubham Chadokar Avatar answered Jan 13 '23 02:01

Shubham Chadokar