amazon-web-services - 使用 AWS CDK,如何在代码管道中设置源代码的 oathToken,从 GitHub 提取源代码,而不使用 Secret Manager 服务?

标签 amazon-web-services github oauth pipeline aws-cdk

我正在使用 CDK 在 AWS 中设置代码管道。管道阶段需要从 github 下载源代码,因此使用 oauth token 来验证请求。我希望能够从 AWS Parameter Store 和 访问 token 不是 在管道阶段设置值时来自 AWS Secret Manager。

有很多使用 Secret Manager 执行此操作的示例。但是,在 CDK 项目中没有使用 Parameter Store 或以纯文本硬编码 token 的示例。

我们在 CDK 1.3.0 中使用 typescript。

我曾尝试将 token 存储在 Parameter Store 中。当存储为安全字符串时,您需要在检索值时另外指定版本。但是我不能然后转换到 SecretValue需要设置 oauthToken在管道阶段的属性(property)。

从 Parameter Store 中获取值 ..

    // get the secureString 
    const secureString = ssm.StringParameter.fromSecureStringParameterAttributes(construct,'MySecretParameter', {
      parameterName: 'my-secure-parameter-name',
      version: 1,
     });

我需要投 secretStringCDK.SecretValue然后用它来设置 oauthToken .我看不出如何做到这一点。
  const sourceAction = new codepipelineactions.GitHubSourceAction({
      actionName: 'Source',
      owner: owner,
      repo: repository,
      oauthToken: githubOAuthAccessToken,
      output: sourceOutput,
      branch: branch,
      trigger: codepipelineactions.GitHubTrigger.WEBHOOK,
    });

CDK 文档说建议将 token 存储在 Secret Manager 中。
" 建议使用Secret Manager SecretString 获取token "

它并不是说不能从其他来源检索和使用 token 。如果情况能够得到澄清,并且如果有人在 Secrets Manager 之外存储 token 并且仍然能够使用它们在管道的源阶段设置 token ,我将不胜感激。

最佳答案

您可以使用 cdk.SecretValue.ssmSecurecdk.SecretValue.plainText :

oauthToken: cdk.SecretValue.ssmSecure('param-name', 'version');
// OR
oauthToken: cdk.SecretValue.plainText('oauth-token-here');

来自 plainText 的文档:

Do not use this method for any secrets that you care about. The only reasonable use case for using this method is when you are testing.

关于amazon-web-services - 使用 AWS CDK,如何在代码管道中设置源代码的 oathToken,从 GitHub 提取源代码,而不使用 Secret Manager 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57755650/

相关文章:

perl - 我如何使用 Perl 更新我的 Twitter 状态并且只使用 LWP::UserAgent?

ios - Pinterest 是否需要在 OAuth 工作之前授权 App ID?

python - cron 事件的 chalice @app.schedule 语法是什么?

amazon-web-services - CloudWatch 日志事件中的事件时间错误

merge - 将新目录添加到 GitHub 存储库分支并合并回主干

带有 VSCode 和 Ubuntu 的 Git 配置问题

asp.net-web-api - 在 Asp.Net Web Api 和 Owin 中同时使用 OAuth 和 Basic Auth

c# - AWS S3 授予对整个文件夹的访问权限 - C#

python - 使用 X-Ray 检测 Python 3.6 Lambda 函数会导致错误

node.js - 关闭 Github Api 中的证书验证