CodePipeline - 由于权限不足导致部署失败
CodePipeline - Deployment failure due to insufficient permission
我在尝试通过 CodePipeline 将应用程序部署到我的 AWS Elastic Beanstalk 时收到权限不足错误。
这是错误:
权限不足
提供的角色没有足够的权限访问 Elastic Beanstalk:拒绝访问
奇怪的是,附加到 CodePipeline 角色的策略确实拥有对 Beanstalk 的所有可能权限:
{
"Action": "elasticbeanstalk:*",
"Effect": "Allow",
"Resource": "*"
}
我仔细检查了 CodePipeline 是否附加了正确的角色以及角色是否附加了正确的策略。
这里缺少权限是什么意思?
Edit1:我没有其他可能有冲突的拒绝政策...
Edit2:出于测试目的,我更改了策略(见下文)并且它起作用了,所以它与权限有关:
{
"Statement": [
{
"Action": "*",
"Effect": "Allow",
"Resource": "*"
}
],
"Version": "2012-10-17"
}
确保目标 S3 存储桶(如果有)等相邻资源也可以访问 ElasticBeanstalk。
例如参见this related question。
当您创建管道时,您应该已经创建了一个 service role。这最初由 AWS 创建并添加了所有必需的权限。引用文档:
The service role is not an AWS managed role but is created initially
for pipeline creation, and then as new permissions are added to the
service role policy, you may need to update the service role for your
pipeline. Once your pipeline is created with a service role, you
cannot apply a different service role to that pipeline. Attach the
recommended policy to the service role.
然后在Manage the CodePipeline service role中我们读到:
The CodePipeline service role is configured with one or more policies
that control access to the AWS resources used by the pipeline. You
might want to attach more policies to this role, edit the policy
attached to the role, or configure policies for other service roles in
AWS.
再往下:
You can edit the service role statement to remove access to resources
you do not use. For example, if none of your pipelines include Elastic
Beanstalk, you can edit the policy statement to remove the section
that grants access to Elastic Beanstalk resources.
总结一下:
- 在创建管道之前,使用 CLI 或在控制台中创建一个服务角色。
- 最初创建此服务角色是为了包含所有必要的权限。应包括部署到 ElasticBeanstalk 的权限。
- 服务角色不受亚马逊管理。这意味着,如果将来需要更多权限部署到 ElasticBeanstalk,它们将不会自动添加到此处。您需要自己添加它们。
- 您可以编辑角色以添加部署所需的新策略或删除不需要的权限。
看来您没有正确创建服务角色,或者您已经编辑了角色。或者管道已在未来创建,现在 Elastic Beanstalk 需要更多权限。如果可能,请按照文档中的说明从头开始创建新管道。注意服务角色创建步骤。如果做不到,请再次创建一个新的临时管道,正确创建服务角色并将策略复制到旧服务角色。 (无法更改已创建管道的服务角色。您只能将新策略附加到它)。
我在尝试通过 CodePipeline 将应用程序部署到我的 AWS Elastic Beanstalk 时收到权限不足错误。
这是错误: 权限不足 提供的角色没有足够的权限访问 Elastic Beanstalk:拒绝访问
奇怪的是,附加到 CodePipeline 角色的策略确实拥有对 Beanstalk 的所有可能权限:
{
"Action": "elasticbeanstalk:*",
"Effect": "Allow",
"Resource": "*"
}
我仔细检查了 CodePipeline 是否附加了正确的角色以及角色是否附加了正确的策略。
这里缺少权限是什么意思?
Edit1:我没有其他可能有冲突的拒绝政策...
Edit2:出于测试目的,我更改了策略(见下文)并且它起作用了,所以它与权限有关:
{
"Statement": [
{
"Action": "*",
"Effect": "Allow",
"Resource": "*"
}
],
"Version": "2012-10-17"
}
确保目标 S3 存储桶(如果有)等相邻资源也可以访问 ElasticBeanstalk。
例如参见this related question。
当您创建管道时,您应该已经创建了一个 service role。这最初由 AWS 创建并添加了所有必需的权限。引用文档:
The service role is not an AWS managed role but is created initially for pipeline creation, and then as new permissions are added to the service role policy, you may need to update the service role for your pipeline. Once your pipeline is created with a service role, you cannot apply a different service role to that pipeline. Attach the recommended policy to the service role.
然后在Manage the CodePipeline service role中我们读到:
The CodePipeline service role is configured with one or more policies that control access to the AWS resources used by the pipeline. You might want to attach more policies to this role, edit the policy attached to the role, or configure policies for other service roles in AWS.
再往下:
You can edit the service role statement to remove access to resources you do not use. For example, if none of your pipelines include Elastic Beanstalk, you can edit the policy statement to remove the section that grants access to Elastic Beanstalk resources.
总结一下:
- 在创建管道之前,使用 CLI 或在控制台中创建一个服务角色。
- 最初创建此服务角色是为了包含所有必要的权限。应包括部署到 ElasticBeanstalk 的权限。
- 服务角色不受亚马逊管理。这意味着,如果将来需要更多权限部署到 ElasticBeanstalk,它们将不会自动添加到此处。您需要自己添加它们。
- 您可以编辑角色以添加部署所需的新策略或删除不需要的权限。
看来您没有正确创建服务角色,或者您已经编辑了角色。或者管道已在未来创建,现在 Elastic Beanstalk 需要更多权限。如果可能,请按照文档中的说明从头开始创建新管道。注意服务角色创建步骤。如果做不到,请再次创建一个新的临时管道,正确创建服务角色并将策略复制到旧服务角色。 (无法更改已创建管道的服务角色。您只能将新策略附加到它)。