7

我正在尝试为我的 nginx 服务器使用日志轮换配置,该服务器用作位于 EC2 Ubuntu 实例上的反向代理机器。

我想在轮换后将这些日志存储在 S3 存储桶上,但是当我尝试配置 s3cmd 工具时,我只会收到“访问被拒绝,你确定你的密钥有 ListAllMyBuckets 权限错误”。

我很确定我的凭据在 IAM 上已正确配置,尝试了至少五个不同的凭据(甚至是根凭据),结果相同。使用具有相同凭据的 aws cli 工具列出本地计算机中的所有存储桶可以正常工作,因此让我感到困惑的是,我仅在我的 EC2 实例上没有任何访问权限。

这就是我运行的:

which s3cmd
/usr/local/bin/s3cmd

s3cmd --configure --debug

Access Key: **************
Secret Key: *******************************
Encryption password: 
Path to GPG program: /usr/bin/gpg
Use HTTPS protocol: False
HTTP Proxy server name:
HTTP Proxy server port: 0

这就是结果

...
DEBUG: ConnMan.put(): connection put back to pool (http://s3.amazonaws.com#1)
DEBUG: S3Error: 403 (Forbidden)
DEBUG: HttpHeader: x-amz-id-2: nMI8DF+............
DEBUG: HttpHeader: server: AmazonS3
DEBUG: HttpHeader: transfer-encoding: chunked
DEBUG: HttpHeader: x-amz-request-id: 5912737605BB776C
DEBUG: HttpHeader: date: Wed, 23 Apr 2014 13:16:53 GMT
DEBUG: HttpHeader: content-type: application/xml
DEBUG: ErrorXML: Code: 'AccessDenied'
DEBUG: ErrorXML: Message: 'Access Denied'
DEBUG: ErrorXML: RequestId: '5912737605BB776C'
DEBUG: ErrorXML: HostId: 'nMI8DF+............
ERROR: Test failed: 403 (AccessDenied): Access Denied
ERROR: Are you sure your keys have ListAllMyBuckets permissions?

我的 nginx 服务器前面唯一的东西是负载均衡器,但我不明白为什么它会干扰我的请求。会不会是我错过的其他东西?

4

6 回答 6

9

请检查您正在使用的 IAM 用户权限

步骤将是

  • AWS 控制台转到IAM面板
  • IAM用户>选择该用户>在底部菜单第二个选项卡是 权限
  • 附加用户策略

    {
    "Version": "2012-10-17",
    "Statement": [
     {
      "Effect": "Allow",
      "Action": ["s3:ListAllMyBuckets"],
      "Resource": "arn:aws:s3:::*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListBucket",
        "s3:GetBucketLocation"
      ],
      "Resource": "arn:aws:s3:::YOU-Bucket-Name"
    
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:PutObject",
        "s3:GetObject",
        "s3:DeleteObject"
      ],
      "Resource": "arn:aws:s3:::YOU-Bucket-Name/*"
    
    
    }
    ]
    }
    

让我知道事情的后续

于 2014-04-23T14:07:39.787 回答
9

请不要相信 --configure 开关:

我面临同样的问题。它在 --configure 中显示 403 但最后我保存了设置然后尝试:

错误:测试失败:403 (AccessDenied):拒绝访问
重试配置?[Y/n] n
保存设置?[y/N] y
配置保存到“/root/.s3cfg”

# s3cmd put MyFile s3://MyBucket/

& 有效..

于 2014-09-03T06:15:12.057 回答
6

s3cmd 设置时会在您的主目录中创建一个名为 .s3cfg 的文件。我会确保你把这个文件放在你的 logrotate 脚本可以读取它的地方,并使用 -c 标志。

例如将 logfile.txt 文件上传到 logbucket 存储桶:

/usr/local/bin/s3cmd -c /home/ubuntu/.s3cfg put logfile.txt s3://logbucket

于 2014-04-24T00:59:08.137 回答
1

你使用的是什么版本s3cmd

我使用s3cmd1.1 进行了尝试,似乎s3cmd1.1 不适用于 IAM 角色。

但有人说s3cmd1.5 alpha2 支持 IAM 角色。(http://t1983.file-systems-s3-s3tools.file-systemstalk.info/s3cmd-1-5-0-alpha2-iam-roles-supportincluded-t1983。 html )

我已经尝试了s3cmd1.5 beta1(https://github.com/s3tools/s3cmd/archive/v1.5.0-beta1.tar.gz),它适用于 IAM 角色。

所以有两种方法可以访问 s3 的存储桶s3cmd

  1. 使用访问密钥和密钥`

    您需要在 /root/.s3cfg(默认路径)中设置一个配置文件,如下所示

    access_key=xxxxxxxx secret_key=xxxxxxxxxxxxxxxxxxxx

    注意在.s3cfg中只设置了上面两个key-value,不需要其他key。

    `
  2. 使用 IAM 添加 s3 策略和 s3cmd > 1.5 alph2。`

    您需要将 IAM 添加到 ec2 实例,此角色可能具有如下策略

    {“效果”:“允许”,“动作”:[“s3:”],“资源”:“ ”}`
于 2014-04-24T04:33:43.367 回答
0

我通过删除 s3cmd 的所有安装找到了解决问题的方法。然后确保 apt-get 是最新的并再次从 apt-get 安装它。在我的配置之后(和以前一样)它工作得很好!

于 2014-04-29T08:32:27.847 回答
0

我也有类似的问题。即使在使用 s3 完全访问策略将我的 EC2 实例与 IAM 角色相关联之后,我的 s3cmd 仍然失败,因为其中没有任何 .s3cfg 文件。我通过更新我的 s3cmd 的版本来修复。

sudo pip install s3cmd==1.6.1

成功了!

于 2016-08-26T12:21:59.620 回答