我有一个使用 Spring Cloud Config 的 Spring-Boot 应用程序,我正在尝试从 Bitbucket 获取应用程序的配置文件。我不久前能够获取配置文件,但现在当我尝试通过配置服务器 url 访问时出现错误。
application.yml:
server:
port: 8888
spring:
application:
name: config-server
cloud:
config:
server:
git:
password: ##########
username: ##########
uri: https://[email protected]/repositorios-closeup/cup-configuration-files
searchPaths: '{application}'
当我尝试访问该网址时,应用程序显示错误 - 未授权:
org.eclipse.jgit.api.errors.TransportException: https://[email protected]/repositorios-closeup/cup-configuration-files: not authorized
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:254) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar:5.1.3.201810200350-r]
at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar:5.1.3.201810200350-r]
有人知道发生了什么事吗?我已经检查了 bitbucket 上的所有凭据和 url。
我想对这个问题添加我的贡献。我希望它可以帮助某人。 @henriqueor 答案对我有帮助。由于我启用了 SSH,因此我需要生成一个具有授予所有范围的个人访问令牌。 (由于我是初级开发人员,我需要更多时间来调查避免此错误所需的范围。)
选定范围:admin:enterprise、admin:gpg_key、admin:org、admin:org_hook、admin:public_key、admin:repo_hook、admin:ssh_signing_key、delete:packages、delete_repo、gist、通知、项目、repo、用户、工作流程,写:讨论,写:包
我添加了以下命令行。这对我有用。
spring.cloud.config.server.git.ignore-local-ssh-settings=true
此设置忽略本地 ssh 配置。
我需要更改身份验证以使用 ssh 而不是 https。
我使用以下命令生成了 ssh:
sh-keygen -m PEM -t rsa -b 4096 -C 'bitbucket_username'
使用本教程将公钥导入到 bitbucket: https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/
并更改了我的 application.yml 以使用 ssh-private-key:
cloud:
config:
server:
git:
uri: [email protected]:repositorios/configuration-files.git
searchPaths: '{application}'
ignore-local-ssh-settings: true
private-key: |
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
default-label: master
对于 BitBucket,我必须创建一个 App Password 并将其放入
spring.cloud.config.server.git.password
属性中
BitBucket 创建应用程序密码
从 GitHub 设置中的开发者设置生成令牌(经典)。使用它作为密码就可以了