Spring Cloud Config Server - Git - Not authorized

I have a Spring-Boot application that use Spring Cloud Config and I'm trying to get the application's configuration file from Bitbucket. I was able to get the configuration file some time ago but now I'm getting an error when I try to access by config-server url.

application.yml:

server:
    port: 8888
spring:
    application:
        name: config-server
    cloud:
        config:
            server:
                git:
                    password: ##########
                    username: ##########
                    uri: https://[email protected]/repositorios-closeup/cup-configuration-files
                    searchPaths: '{application}'

When I try to access the url the application is showing an error - NOT AUTHORIZED:

org.eclipse.jgit.api.errors.TransportException: https://[email protected]/repositorios-closeup/cup-configuration-files: not authorized

    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:254) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar:5.1.3.201810200350-r]
    at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar:5.1.3.201810200350-r]

Does anybody know what is happening? I've already check all credentials and url on bitbucket.

Upvotes: 5

Views: 8191

Answers (6)

PKS
PKS

Reputation: 763

Generate a token(classic) from developer settings in your GitHub Settings.Use that as a password and you'll be okay

Upvotes: 0

mahonri
mahonri

Reputation: 43

I want to add my contribution to this question. I hope it might help someone. @henriqueor answer was what helped me. As I've enabled SSH I needed to generate a Personal Access Token with all scopes granted. (As I'm a Junior Developer, I would need more time to investigate what scopes are necessary to avoid this error.)

Selected scopes: admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, delete:packages, delete_repo, gist, notifications, project, repo, user, workflow, write:discussion, write:packages

Upvotes: 1

Joan Garcia
Joan Garcia

Reputation: 86

For BitBucket i had to create an App Password and put it in the spring.cloud.config.server.git.password property BitBucket config BitBucket create App Passwords

Upvotes: 0

I needed to change the authentication to use ssh instead of https.


I generated the ssh using this command:

sh-keygen -m PEM -t rsa -b 4096 -C 'bitbucket_username'

Imported the public key to bitbucket using this tutorial: https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/

And changed my application.yml to use the ssh-private-key:

    cloud:
        config:
            server:
                git:
                    uri: [email protected]:repositorios/configuration-files.git
                    searchPaths: '{application}'
                    ignore-local-ssh-settings: true
                    private-key: |
                        -----BEGIN RSA PRIVATE KEY-----
                        ...
                        -----END RSA PRIVATE KEY-----
                    default-label: master

Upvotes: 0

henriqueor
henriqueor

Reputation: 939

I had to generate a Personal Access Token on my Github user settings. And use it, instead of the real password.

enter image description here

I know you mentioned Bitbucket, but I've got the same issue with Github instead. And that's how I solved the "Not authorized" message.

Upvotes: 6

Mert Bahardoğan
Mert Bahardoğan

Reputation: 1

I added the following command line. It worked for me.

spring.cloud.config.server.git.ignore-local-ssh-settings=true

This setting ignores the local ssh config.

Upvotes: 0

Related Questions