簡體   English   中英

Spring Cloud Config Server - 用於連接到 github 的用戶 ID 和密碼

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

我查看了 github 存儲庫中許多 spring 雲配置服務器的代碼,下面是作為屬性文件的一部分提供的 2 個值。 我相信為了連接到 github 的 https 端點,用戶 ID 和密碼也是必要的。 這些可能是環境變量的一部分嗎?

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

編輯:

下面是我在 spring 網站上看到的示例。 但是,在我企業內的所有 github 存儲庫中,我沒有看到用戶 ID 和密碼被設置,因為它們是敏感信息。 如果屬性文件中未提供 uid / pwd ,如何設置或配置服務器訪問 github url ?

spring:
  cloud:
    config:
      server:
        git:
          uri: https://github.com/spring-cloud-samples/config-repo
          username: trolley
          password: strongpassword
  1. 對於公共存儲庫,不需要使用用戶名密碼或其他授權來獲取配置屬性,對於私有存儲庫則需要身份驗證。
  2. 可以從 os 或 java-system-property 和命令行的環境中設置變量。 優先級: command-line-param > java-system-property > os-env > application.properties

因此,例如,如果我直接設置屬性使用命令行(具有最高優先級),例如:

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

其中包含 CI 工具中的所有參數或由某人管理的任何內容,您不會在源代碼中看到它。

簡單提示 -

轉到 github.com -> 開發人員設置 -> 創建訪問令牌,然后創建一個僅具有讀取 repo 權限的訪問令牌。 這樣就可以在不提供純文本密碼的情況下公開私有存儲庫!

像這樣的東西——

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

是的,只需使用這樣的變量:


    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}

並在任何 CI 上設置這些環境變量。 例如作為 GitHub Actions 上的秘密:


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

並且似乎您不能再使用密碼來訪問 GitHub,您需要在此處頂部傳遞 GitHub 令牌spring.cloud.config.server.git.password

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM