简体   繁体   English

AWS CLI Secrets Manager 创建密钥

[英]AWS CLI Secrets Manager Create Secret

I want to create a new secret in Secrets Manager.我想在 Secrets Manager 中创建一个新密钥。 The secret needs to be a key/value pair.秘密需要是键/值对。 When I create the secret using the CLI it is stored as plaintext instead of as a key/value pair:当我使用 CLI 创建密钥时,它存储为纯文本而不是键/值对:

aws secretsmanager create-secret --name github/oauthtoken \
    --description "GitHub OAuth Token" \
    --secret-string file:///tmp/github_oauth.json

github_oauth.json github_oauth.json

[
  {
    "Key": "oauth_token",
    "Value": "MYOAUTHTOKEN"
  }
]

When I attempt to resolve the secret in CloudFormation I'm getting an error:当我尝试解析 CloudFormation 中的密钥时,出现错误:

Secrets Manager can?t find the specified secret. 

When I access the secret in the Secrets Manager UI the secret is in plaintext with an error under Secret key/value:当我在 Secrets Manager UI 中访问秘密时,秘密是明文,在秘密键/值下有错误:

The secret value can't be converted to key name and value pairs

How can I create a secret in Secrets Manager stored as a key/value pair?如何在 Secrets Manager 中创建存储为键/值对的密钥?

I have tried in this way:我试过这种方式:

aws secretsmanager create-secret --name github/oauthtoken aws secretsmanager create-secret --name github/oauthtoken
--description "GitHub OAuth Token" --description "GitHub OAuth 令牌"
--secret-string '{"oauth_token":"MYOAUTHTOKEN"}' --region us-east-1 --secret-string '{"oauth_token":"MYOAUTHTOKEN"}' --region us-east-1

The SecretsManager console and the SecretsManager-CloudFormation integration default to treating the SecretString as a JSON object, as you correctly discovered.正如您正确发现的那样,SecretsManager 控制台和 SecretsManager-CloudFormation 集成默认将 SecretsString 视为 JSON 对象。

The console parses this JSON and shows you key/value pairs.控制台解析此 JSON 并向您显示键/值对。 In CloudFormation, you can use dynamic reference to fetch individual JSON values when the SecretString is a JSON object.在 CloudFormation 中,当 SecretString 是 JSON 对象时,您可以使用动态引用来获取单个 JSON 值。

This, of course, does not force you to use key/value pairs in your SecretString.当然,这并不强制您在 SecretString 中使用键/值对。 You can have any freetext in there and view it in the console under the "Plaintext" tab.你可以在那里有任何自由文本,并在“纯文本”选项卡下的控制台中查看它。 In CloudFormation, you can use dynamic references to reference the entire SecretString and avoid parsing it as JSON.在 CloudFormation 中,您可以使用动态引用来引用整个 SecretString 并避免将其解析为 JSON。

You can also create secrets through CloudFormation that are key/value pairs or free text, along with setting up resource policies, rotation, etc.您还可以通过 CloudFormation 创建密钥/值对或自由文本密钥,以及设置资源策略、轮换等。

Refs -参考 -

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html#dynamic-references-secretsmanager https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html#dynamic-references-secretsmanager

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secret.html https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-secretsmanager-secret.html

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

相关问题 在 AWS Secrets Manager 中创建密钥 - Create secrets in AWS Secrets Manager 使用 AWS cli 解析来自 AWS 机密管理器的机密 - Parsing secrets from AWS secrets manager using AWS cli AWS Secrets Manager 和 Cloud Formation - 无法创建秘密,因为它已经存在 - AWS Secrets Manager and Cloud Formation - can not create secret because it already exists AWS Secret Manager 轮换 Lambda 在数据库秘密轮换时超时 - AWS Secret Manager Rotation Lambda is timing out on a DB secrets rotation 是否可以使用 terraform 在 AWS 机密管理器中设置多用户机密轮换? - Is it possible to set up a multiuser secret rotation in AWS secrets manager with terraform? AWS 资源策略中的条件不允许 lambda 访问 Secrets Manager Secret - Condition in AWS resource policy not allowing lambda to access Secrets Manager Secret 使用 aws cli 运行 create secrets manager 命令时出错 - Getting error while running create secrets manager command using aws cli 如何检索 AWS Secrets Manager 密钥的特定值? - How do retrieve the specific value of an AWS Secrets Manager secret? GKE Secrets 或 Google 机密管理器 - GKE Secrets OR Google Secret manager 如何将存储在 AWS Secret Manager 中的机密传递到 Sagemaker 中的 Docker 容器? - How to I pass secrets stored in AWS Secret Manager to a Docker container in Sagemaker?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM