我正在努力设置一个 GitHub 操作,将几个静态文件(html、css)上传到我的 S3 存储桶,该存储桶由 AWS 用作静态网站。
我设置了一些策略,但它们似乎不允许正确的权限来允许操作的 aws cli 工具连接到 S3。
我有一个名为
github_runner
的用户,并附加了用于访问相关存储桶的策略:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3AccessWebBucket",
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::myrealbucket-web",
"arn:aws:s3:::myrealbucket-web/*"
]
}
]
}
在桶上我有这个政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "SourceIP",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::myrealbucket-web",
"arn:aws:s3:::myrealbucket-web/*"
],
"Condition": {
"NotIpAddress": {
"aws:SourceIp": [
"0.0.0.0/32", // my subdomains I want to allow access to
"0.0.0.0/32"
]
},
"ArnNotEquals": {
"aws:SourceArn": "arn:aws:iam::11111111:user/github_runner"
}
}
},
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::myrealbucket-web/*"
},
{
"Sid": "Stmt",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::11111111:user/github_runner"
},
"Action": "s3:*",
"Resource": "arn:aws:s3:::myrealbucket-web"
}
]
}
我想问题的一部分是 SourceIP Sid,我用它来阻止除了我的组织内部之外对我的网站的访问。这不是一个极其机密的网站,但这足以让我在安全级别上阻止窥探者。
最后,当我运行该操作时,我看到:
Run aws s3 mv ./index.html ***
aws s3 mv ./index.html ***
aws s3 mv ./style.css ***
aws s3 mv ./script.js ***
shell: /usr/bin/bash -e {0}
env:
AWS_DEFAULT_REGION: ***
AWS_REGION: ***
AWS_ACCESS_KEY_ID: ***
AWS_SECRET_ACCESS_KEY: ***
move failed: ./index.html to ***/index.html An error occurred (AccessDenied) when calling the PutObject operation: Access Denied
我尝试调整
ArnNotEquals
以也排除带有 aws:PrincipalArn
的用户 arn,但无济于事。
我还尝试添加和删除一些 s3 权限,但似乎无法实现正确的设置。全局拒绝会阻止我的上传吗?存储桶和用户策略不应该为我的跑步者上传数据提供路径吗?
我完全按照您所描述的方式使用此配置:
{
"Sid": "SourceIP",
"Effect": "Deny",
"NotPrincipal": {"AWS": ["aws:SourceArn": "arn:aws:iam::11111111:user/github_runner"]},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::myrealbucket-web",
"arn:aws:s3:::myrealbucket-web/*"
],
"Condition": {
"NotIpAddress": {
"aws:SourceIp": [
"0.0.0.0/32", // my subdomains I want to allow access to
"0.0.0.0/32"
]
}
}
},
您需要将任何其他 IAM 角色/用户添加到该主体列表中,这些角色/用户也需要访问存储桶。