简体   繁体   中英

Spring Cloud Config Server - User id and Password to connect to github

I looked at the code for a number of spring cloud config servers in github repo and below are the 2 values that are provided as part of property file. I believe in order to connect to https end point of github , user id and password are also necessary. Could these perhaps be part of environment variables?

server.port=7070
spring.cloud.config.server.git.uri=https://

EDIT:

Below is the example that I saw in spring website. However in all the github repos within my enterprise I don't see userid and password being set as they are sensitive info. How could it be set or config server access github url , if uid / pwd is not provided in the property file?

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo
          username: trolley
          password: strongpassword
  1. for public repository there is no need to use username and password or other authorizations to get config properties, for private repository auth are required.
  2. it is possible to set variable from enviroment which from os or java-system-property and command line. for precedence: command-line-param > java-system-property > os-env > application.properties .

So, for example what if i set property use command-line directly (which has highest precedence.) like:

java -jar config-server.jar --spring.cloud.config.server.git.username=xxx --spring.cloud.config.server.git.password=xxx

which contain all param in CI tools or whatever then managed by someone, you wouldn't see that in source code.

Easy Tip -

Go to github.com -> Developer settings -> Create Access Token, then create an access token with a read repo priviliage only. that way a private repository can be expose without giving plain text password!

Something like this -

spring.cloud.config.server.git.password=0371abshak3048sa8d81828488483sd302

Yes, just use variables like this:


    spring.cloud.config.server.git.uri=${GIT_REPO_URL}
    spring.cloud.config.server.git.username=${GIT_USERNAME}
    spring.cloud.config.server.git.password=${GIT_TOKEN}

And set those env vars on any CI. For example as secrets on GitHub Actions:


    - name: Build config-service
      env:
         GIT_REPO_URL: ${{ secrets.GIT_REPO_URL }}
         GIT_USERNAME: ${{ secrets.GIT_USERNAME }}
         GIT_TOKEN: ${{ secrets.GIT_TOKEN }}

And seems like you can't use password anymore to access GitHub, you need top pass GitHub token here spring.cloud.config.server.git.password

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM