0

我使用部署到关键云代工厂的 Spring Cloud 数据流,将 Spring Batch 作业作为 Spring Cloud 任务运行,并且这些作业需要 aws 凭据才能访问 s3 存储桶。

我尝试将 aws 凭据作为任务属性传递,但凭据在任务的日志文件中显示为参数或属性。(https://docs.spring.io/spring-cloud-dataflow/docs/current/reference/htmlsingle/#spring-cloud-dataflow-global-properties

现在,我在每次部署后手动将凭据设置为 pcf 中的 env 变量,但我正在尝试自动执行此操作。在实际启动任务之前不会部署任务,因此在部署时我必须启动任务,然后等待它由于缺少凭据而失败,然后使用cfcli 设置环境变量凭据。我如何提供这些凭据,而不显示在 pcf 应用程序的日志中?

我也探索过使用 vault 和 spring cloud config,但同样,我需要将凭据传递给任务以访问 spring cloud config。

谢谢!

4

3 回答 3

1

任务的安全凭证应该通过任务定义中的环境变量来配置,或者使用 Spring Cloud Config Server 之类的东西来提供它们(并在静止时加密存储它们)。Spring Cloud Task 将所有命令行参数以明文形式存储在数据库中,这就是为什么不应该以这种方式传递它们的原因。

于 2018-05-25T15:23:31.873 回答
1

在考虑了提供的答案中包含的方法后,我继续测试和研究并得出结论,最好的方法是使用 Cloud Foundry“用户提供的服务”来为任务提供 AWS 凭证。

https://docs.cloudfoundry.org/devguide/services/user-provided.html

Spring Boot 自动处理每个应用程序容器中包含的 VCAP_SERVICES 环境变量。

http://engineering.pivotal.io/post/spring-boot-injecting-credentials/

然后,我在 application-cloud.properties 中使用属性占位符将处理后的属性映射到 spring-cloud-aws 属性中:

cloud.aws.credentials.accessKey=${vcap.services.aws-s3.credentials.aws_access_key_id}
cloud.aws.credentials.secretKey=${vcap.services.aws-s3.credentials.aws_secret_access_key}
于 2018-05-29T20:53:33.750 回答
1

这是一个任务/批处理作业示例

这个应用程序使用spring-cloud-starter-aws. 这个启动器已经提供了引导自动配置和覆盖 AWS 凭据作为引导属性的能力。

从 SCDF 启动时,您将覆盖这些属性,例如:

任务启动 --name S3LoaderJob --arguments "--cloud.aws.credentials.accessKey= --cloud.aws.credentials.secretKey= --cloud.aws.region.static= --cloud.aws.region.auto=错误的”

您可以决定控制任务的日志级别,因此它不会以纯文本形式记录它们。

于 2018-05-25T14:54:50.687 回答