简体   繁体   English

如何为 spring 启动应用程序设置 azure 密钥库?

[英]How to set up azure keyvault for spring boot app?

There was some dependency incompatibility occurring because we were using an older version of azure keyvault (azure-keyvault-secrets-spring-boot-starter 2.2.1) but it got updated and we are upgrading it to azure-spring-boot-starter-keyvault-secrets 4.0.0.由于我们使用的是旧版本的 azure 密钥库(azure-keyvault-secrets-spring-boot-starter 2.2.1),因此发生了一些依赖项不兼容,但它已更新,我们正在将其升级到 azure-spring-boot-starter- keyvault-secrets 4.0.0. Now the keyvault isn't being connected maybe because the application.yml keyvault config is in the wrong syntax.现在 keyvault 没有连接可能是因为 application.yml keyvault 配置的语法错误。

This is what was there before when it was working with the 2.2.1 version:这是之前使用 2.2.1 版本时的情况:

azure:
  keyvault:
    uri: ${uri}
    client-id: ${clientId}
    client-key: ${clientKey}
    token-acquire-timeout-seconds: 120

This is how we are trying now but it isn't connecting.这就是我们现在正在尝试的方式,但它没有连接。

spring:
  cloud:
    azure:
      keyvault:
        secret:
          property-sources:
            uri: ${uri}
            client-id: ${clientId}
            client-key: ${clientKey}
            token-acquire-timeout-seconds: 120

What is the correct syntax for this azure keyvault version configuration??这个 azure keyvault 版本配置的正确语法是什么?

Add the below dependency of spring-cloud-azure-starter-keyvault-certificates to the pom.xml file.spring-cloud-azure-starter-keyvault-certificates的以下依赖项添加到pom.xml文件中。

<properties>
        <version.spring.cloud.azure>4.3.0</version.spring.cloud.azure> 
</properties>
<dependencies>
      <dependency>
             <groupId>com.azure.spring</groupId>
             <artifactId>spring-cloud-azure-starter-keyvault-secrets</artifactId>
      </dependency> 
</dependencies> 
<dependencyManagement>
         <dependencies>
             <dependency>
                 <groupId>com.azure.spring</groupId>
                 <artifactId>spring-cloud-azure-dependencies</artifactId>
                 <version>${version.spring.cloud.azure}</version>
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
   </dependencies> 
</dependencyManagement>
  • Go to--> src/main/resources/application.properties file and add the below properties to configure the azure key vault to link to the spring boot application: Go 到--> src/main/resources/application.properties文件并添加以下属性以配置 azure 密钥保管库以链接到 Z2A2D595E6ED9A0B24F027F2B63B1 应用程序:
    spring.cloud.azure.keyvault.secret.property-source-enabled=true
    spring.cloud.azure.keyvault.secret.property-sources[0].credential.client-id=<your client ID>
    spring.cloud.azure.keyvault.secret.property-sources[0].credential.client-secret=<your client key>
    spring.cloud.azure.keyvault.secret.property-sources[0].endpoint=https://contosokv.vault.azure.net/
    spring.cloud.azure.keyvault.secret.property-sources[0].profile.tenant-id=<your tenant ID>

The above references are taken from the Microsoft Document and refer this to know more about adding Key Vault configuration to the app.上述参考资料取自Microsoft 文档,并参考此内容以了解有关将 Key Vault 配置添加到应用程序的更多信息。

It should most probably look like this:它很可能看起来像这样:

spring:
  cloud:
    azure:
      keyvault:
        secret:
          property-sources[0]:
            endpoint: ${uri}
            credential:
              client-id: ${clientId}
              client-secret: ${clientKey}

From the migration guide from 3.xx to 4.x ( direct link ):从从 3.xx 到 4.x 的迁移指南( 直接链接):

Legacy properties旧版属性 Modern properties现代物业
azure.keyvault.case-sensitive-keys azure.keyvault.case-sensitive-keys spring.cloud.azure.keyvault.secret.property-sources[n].case-sensitive spring.cloud.azure.keyvault.secret.property-sources[n].case-sensitive
azure.keyvault.certificate-password azure.keyvault.certificate-password spring.cloud.azure.keyvault.secret.property-sources[n].credential.client-certificate-password spring.cloud.azure.keyvault.secret.property-sources[n].credential.client-certificate-password
azure.keyvault.certificate-path azure.keyvault.certificate-path spring.cloud.azure.keyvault.secret.property-sources[n].credential.client-certificate-path spring.cloud.azure.keyvault.secret.property-sources[n].credential.client-certificate-path
azure.keyvault.client-id azure.keyvault.client-id spring.cloud.azure.keyvault.secret.property-sources[n].credential.client-id spring.cloud.azure.keyvault.secret.property-sources[n].credential.client-id
azure.keyvault.client-key azure.keyvault.client-key spring.cloud.azure.keyvault.secret.property-sources[n].credential.client-secret spring.cloud.azure.keyvault.secret.property-sources[n].credential.client-secret
azure.keyvault.enabled azure.keyvault.enabled spring.cloud.azure.keyvault.secret.enabled and spring.cloud.azure.keyvault.secret.property-source-enabled spring.cloud.azure.keyvault.secret.enabled and spring.cloud.azure.keyvault.secret.property-source-enabled
azure.keyvault.refresh-interval azure.keyvault.refresh-interval spring.cloud.azure.keyvault.secret.property-sources[n].refresh-interval spring.cloud.azure.keyvault.secret.property-sources[n].refresh-interval
azure.keyvault.secret-keys azure.keyvault.secret-keys spring.cloud.azure.keyvault.secret.property-sources[n].secret-keys spring.cloud.azure.keyvault.secret.property-sources[n].secret-keys
azure.keyvault.tenant-id azure.keyvault.tenant-id spring.cloud.azure.keyvault.secret.property-sources[n].profile.tenant-id spring.cloud.azure.keyvault.secret.property-sources[n].profile.tenant-id
azure.keyvault.uri azure.keyvault.uri spring.cloud.azure.keyvault.secret.property-sources[n].endpoint spring.cloud.azure.keyvault.secret.property-sources[n].endpoint

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有 Spring 引导的 Keyvault MSI:如何配置 keyvault 以在本地运行时使用 Azure cli 凭据而不是托管身份? - Keyvault MSI with Spring boot : How to config keyvault to use Azure cli credentials instead of managed identity while running on local? 如何使用Java中来自Azure KeyVault的证书设置SSLContext - How do I set up a SSLContext using certificate from Azure KeyVault in Java 如何在弹簧靴中设置过滤链? - How to set up filter chain in spring boot? 如何在 spring 启动应用程序中通过 logback.xml 为两个附加程序设置两个不同的日志级别? - How to set up two different log levels for two appenders via logback.xml in spring boot app? Azure KeyVault:如何添加带有连字符作为秘密的Spring属性 - Azure KeyVault: How to add Spring properties with hypehen as secrets 如何在 Spring Boot 应用程序中设置用于 azure 监控的变量 instrumentationKey - How to set the variable instrumentationKey for azure monitoring in a spring boot application Spring Boot - 缓存不起作用,如何正确设置缓存? - Spring Boot - cache not working, how to set cache up correctly? 如何设置 Spring Boot 以运行 HTTPS/HTTP 端口 - How set up Spring Boot to run HTTPS / HTTP ports 如何为Java Spring Boot和MySql设置Docker容器 - How to set up Docker containers for Java Spring Boot and MySql 如何仅将 spring 引导记录器设置为计划任务? - How to set up the spring boot logger to scheduled tasks only?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM