【问题标题】:Spring Cloud Config Server - User id and Password to connect to githubSpring Cloud Config Server - 连接 github 的用户名和密码
【发布时间】:2019-02-21 17:17:47
【问题描述】:

我在 github repo 中查看了一些 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

【问题讨论】:

  • 通过环境变量?

标签: java spring spring-boot spring-cloud


【解决方案1】:
  1. 对于公共存储库,对于私有存储库,不需要使用用户名密码或其他授权来获取配置属性 需要身份验证。
  2. 可以从操作系统或java-system-property 和命令行的环境中设置变量。优先级:命令行参数 > 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 工具中的所有参数或随后由某人管理的任何内容,您不会在源代码中看到它。

【讨论】:

  • 谢谢,这有帮助
【解决方案2】:

是的,只需使用这样的变量:


    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

【讨论】:

    【解决方案3】:

    简单提示 -

    转到 github.com -> 开发人员设置 -> 创建访问令牌,然后创建一个仅具有读取回购权限的访问令牌。这样就可以在不提供纯文本密码的情况下公开私有存储库!

    类似的东西-

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

    【讨论】:

    • OP 询问的是如何保护配置服务器而不是如何以安全的方式访问 git
    • 使用降低网络可见性的技巧来保护配置服务器,并添加引导属性以使用别名,例如 - spring.cloud.config.uri=config
    猜你喜欢
    • 2019-07-01
    • 2016-09-26
    • 1970-01-01
    • 2020-09-05
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 1970-01-01
    • 2017-01-27
    相关资源
    最近更新 更多