【问题标题】:AWS Config Credentials are not being accessed in dockerDocker 中未访问 AWS Config 凭证
【发布时间】:2020-10-30 10:01:24
【问题描述】:

我在本地系统上设置了秘密管理器,现在我的 Windows 根目录中有 .aws 目录。通过使用以下代码,我正在检索我的访问密钥 ID 和值。

client.getSecretValue({SecretId: secretName}, function(err, data) {
// console.log(err);
if (err) {
    console.log(err);
    if (err.code === 'DecryptionFailureException')
        // Secrets Manager can't decrypt the protected secret text using the provided KMS key.
        throw err;
    else if (err.code === 'InternalServiceErrorException')
        // An error occurred on the server side.
        throw err;
    else if (err.code === 'InvalidParameterException')
        // You provided an invalid value for a parameter.
        throw err;
    else if (err.code === 'InvalidRequestException')
        // You provided a parameter value that is not valid for the current state of the resource.
        throw err;
    else if (err.code === 'ResourceNotFoundException')
        // We can't find the resource that you asked for.
        throw err;
}
else {
    
    // Decrypts secret using the associated KMS CMK.
    // Depending on whether the secret is a string or binary, one of these fields will be populated.
    if ('SecretString' in data) {
        secret = JSON.parse(data.SecretString);
        secretKey = secret["AWS_ACCESS_KEY_ID"];
        clientID = secret["AWS_ACCESS_KEY_ID"];
        secret.region = "us-east-1";
        global.secret = secret;
    } else {
        let buff = new Buffer(data.SecretBinary, 'base64');
        decodedBinarySecret = buff.toString('ascii');
    }

    // routes 
   
    require('./services')(router,validation);
}

});

它运行良好。但是当我用 docker 运行上面的代码时,它会因为以下错误而失败

配置中缺少凭据,如果使用 AWS_CONFIG_FILE,请设置 AWS_SDK_LOAD_CONFIG=1。

【问题讨论】:

  • 这将失败,因为秘密管理器客户端正在返回此错误,您是否为此客户端指定了任何凭据?
  • 感谢您的快速回复@Chris Williams。实际上,我在 .aws 目录中有名为 .credentials 的文件,它具有访问密钥 ID 和密钥。它在我不使用 docker 但使用 docker 时会引发问题
  • 在Docker容器中创建了吗?
  • 不,它不是在那里创建的。你能建议我如何做到这一点吗?我做了一些研发,发现了这个 docker run -it -p 3000:3000 -v ~/.aws/:/root/.aws/ --user=root service-docker-image-2:latest 。但它没有用。
  • 当你说没有工作时,它是在运行该命令时返回错误还是没有效果?

标签: node.js amazon-web-services docker aws-secrets-manager


【解决方案1】:

您可以通过 CLI 将这些值作为 environment variables 传递。

要使用以下语法运行此操作

docker run -it -p 3000:3000 -e AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE -e AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY service-docker-image-2:latest .

【讨论】:

  • 我试过了,但出现错误“/usr/local/bin/docker-entrypoint.sh: 8: exec: .: Permission denied”
  • 确保这与您正常运行的内容相匹配,但添加了环境参数。这是展示的示例命令:)
猜你喜欢
  • 2019-12-09
  • 2014-04-03
  • 2016-08-17
  • 2015-02-25
  • 1970-01-01
  • 1970-01-01
  • 2013-06-28
  • 2020-11-08
  • 1970-01-01
相关资源
最近更新 更多