spring-cloud-config icon indicating copy to clipboard operation
spring-cloud-config copied to clipboard

Support GitLab configuration with private access token

Open david-9000 opened this issue 5 years ago • 4 comments

Hi everyone!

According to the GitLab documentation you can read repositories with a private access token. See link: https://docs.gitlab.com/ee/api/README.html#personalproject-access-tokens

The current version and prior version of Spring Cloud Config Server seem not to support this feature.

Environment

Component       Version
Spring Boot     2.4.0
Spring Cloud    2020.0.0-M5
GitLab CE       13.5.3
Java VM         openjdk 11

What I have tried so far I have created a private access token on the GitLab server and tried to configure it inside the spring cloud config server.

  1. When I add the ?private-token= parameter, the server won't start because JGit seems to append a path to the configured uri which leads to an invalid url. Caused by: org.apache.http.client.CircularRedirectException: Circular redirect to 'https://gitlab.home.local/spring-cloud-config.git?private_token=<token>/info/refs&service=git-upload-pack'
  2. I have tried to add the token as a header field in the application.properties. But the property seems to be ignored or at least not evaluated at this point. spring.cloud.config.headers.PRIVATE-TOKEN=<token> or spring.cloud.config.headers.Authorization=Bearer <token>

Best regards, David

david-9000 avatar Dec 07 '20 16:12 david-9000

That header is for config client talking to config server. We would need something equivalent for git in general (not specific to any git hosting service).

spencergibb avatar Dec 07 '20 16:12 spencergibb

A new parameter like spring.cloud.config.server.git.headers.*? Or via spring.cloud.config.server.git.preferred-authentications? I am looking still for a document specifiying possible values for this parameter. A dedicated preferred authentication type like "token" or similar and a corresponding parameter to provide the token could do the trick.

david-9000 avatar Dec 07 '20 17:12 david-9000

This workaround seemed to work for me based on some JGit documentation:

spring:
  cloud:
    config:
      server:
        git:
          uri: https://<token-name>:<token>@<repo_url>
          username: <username>
          password: <token>

mzeitlin avatar Nov 02 '22 16:11 mzeitlin

you can try like this https://usernameofgit:[email protected]/repo_nameorurl

nphatan avatar Feb 09 '24 11:02 nphatan