4

I want to use private git repository with my config server. Here is my application.yml:

server:
  port: 100
spring:
  application:
    name: smth-config-server
  cloud:
    config:
      server:
        git:
          uri: https://github.com/smth/smth
          default-label: main
          username: smth
          password: smth
          host-key-algorithm: ssh-rsa
          ignore-local-ssh-settings: true
          host-key: ssh-rsa smth== github.com
          private-key: -----BEGIN RSA PRIVATE KEY-----
            smth
            -----END RSA PRIVATE KEY-----

I get the following error:

Caused by: org.eclipse.jgit.errors.TransportException: https://github.com/smth/smth: not authorized
    at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:544)

How should I fix it?

majorMobilych
  • 95
  • 2
  • 6
  • 3
    Since you're using HTTPS as the protocol, providing a private key is not going to work. Either change the clone URL to be a SSH compatible one or use an access token instead of the `private-key`. – Prav Sep 03 '21 at 23:01
  • 1
    @PraveenPremaratne Thank you! You were right, I also added few more configs and got it work =) – majorMobilych Sep 04 '21 at 13:34
  • 1
    Can you share the solution for the issue? @majorMobilych – Sushan Sapaliga Sep 30 '21 at 07:59

2 Answers2

2

For this to work with a private repository you must use a git access token (which you can generate following this steps) on your password property.

so for example

server:
  port: 8888

spring:
  cloud:
    config:
      server:
        git:
          uri: yourgithubrepo 
          username: ${GIT_USER}
          password: pasteyouraccesstoken
          default-label: "main"  

that should work

BugsForBreakfast
  • 712
  • 10
  • 30
1

In your config server application properties:

 profiles:
    active: git
    
  spring:
    cloud:
      config:
        server:
          git:
            uri: https://github.com/${GIT_USER}/${GIT_REPO}.git
            username: ${GIT_USER}
            password: pasteyouraccesstoken
            clone-on-start: true
            default-label: ${GIT_BRANCH}
            searchPaths: ${FOLDER_PATH}
Youzef
  • 616
  • 1
  • 6
  • 23
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 05 '23 at 11:47