3

使用 spring-cloud-starter-aws-secrets-manager-config 在应用程序启动时检索 AWS 机密。在 AWS 机密管理器中定义多个机密后,我看不到如何定义多个映射来映射这些机密。

引导程序.yml

aws:
  secretsmanager:
    prefix: /secret
    defaultContext: context-name 
    profileSeparator: _
    failFast: true
    name: service-name
    enabled: true

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.9.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.SR4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws-secrets-manager-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

AWS 中定义为 /secret/context-name/val1 [foo:bar] /secret/context-name/val2 [wibble:wombat] 的秘密

AwsSecretsManagerPropertySource 中的底层代码似乎在以下位置寻找真正的秘密 /secret/context-name /secret/context-name_ /secret/service-name /secret_service-name_

只有,所以永远不会在 /secret/context-name/X 找到秘密

这是预期的行为吗?如果是这样,我将如何在 bootstrap.yml 中定义多个秘密?

4

1 回答 1

0

对我来说,bootstrap.yml 中的以下配置有效

spring:
  application:
    name: AwsSecretManager
aws:
  secretsmanager:
    prefix: /secret
    defaultContext: service
    profileSeparator: _
    failFast: true
    name: AwsSecretManager
    enabled: true 
cloud:
  aws:
    stack:
      auto: false
    region:
      use-default-aws-region-chain: true
    credentials:   
      use-default-aws-credentials-chain: true

AWS 中定义的属性如下

密钥名称: /secret/AwsSecretManager_dev

这里dev表示为其定义属性的配置文件。

注意:bootstarp.yml 中定义的配置只是 Secret manager 服务的示例配置,不使用 AWS 堆栈。属性将根据要求而有所不同。

于 2020-10-29T07:08:04.227 回答