Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

User with tag-based permissions is unable to deploy a stage with a REST API resource policy

未关闭
#13,075 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
28/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
aws

调研方向

首先,使用 provider.stackTags、apiGateway.resourcePolicy 和基于标签的 IAM policy 重现一次部署到新 stage 的过程,然后将其与部署到现有 stage 的过程进行比较。检查生成的 CloudFormation 和 API Gateway 操作顺序;完成的标准是:新 stage 能够在所述基于标签的权限下部署其 REST API 和 resource policy。

由索引模型根据 Issue 内容生成。

描述

Issue description

We are using v4 of Serverless. (frameworkVersion: '4.4.18')

It appears there's something like an order-of-operations issue with stackTags when trying to deploy a REST API (v1) with a Resource Policy specified on it. Specifically, when a user with tag-based permissions for the apigateway:UpdateRestApiPolicy action tries to deploy a Serverless stage with those tags defined in provider.stackTags, if that stage does not ALREADY exist and with those tags, CloudFormation fails to create the RestApi resource.

Our engineers have an IAM policy that grants the required permission, assuming that the API in question is tagged as we expect:

{
    "Statement": [
        {
            "Action": [
                "apigateway:UpdateRestApiPolicy",
                "apigateway:POST"
            ],
            "Condition": {
                "ForAnyValue:StringEquals": {
                    "aws:ResourceTag/Environment": [
                        "Development",
                        "Beta",
                        "Production"
                    ]
                },
                "StringEquals": {
                    "aws:ResourceTag/Group": "My Service"
                }
            },
            "Effect": "Allow",
            "Resource": "*"
        }
    ],
    "Version": "2012-10-17"
}

This policy is sufficient for us to be able to add our desired resource policy via new deploys to existing stages. However, when we try to deploy a new stage, we run into what looks like a cart-and-horse:

Image

User: arn:aws:iam:::user/ejherbertson@.com is not authorized to perform: apigateway:UpdateRestApiPolicy on resource: arn:aws:apigateway:us-east-1::/restapis because no identity-based policy allows the apigateway:UpdateRestApiPolicy action

The serverless config we're using specifies the required tags via provider.stackTags, and I can confirm that they do (ultimately, at least) get applied as we expect to the REST API—if we strip-out the resource policy—but apparently it's not... soon enough?... to allow a tag-based policy for resource policies to work.

Here's the definition of the resource policy, if it helps. It's using the documented provider.apiGateway.resourcePolicy

  apiGateway:
    disableDefaultEndpoint: true
    resourcePolicy:
      - Effect: Allow
        Principal: '*'
        Action: execute-api:Invoke
        Resource: execute-api:/*
      - Effect: Deny
        Principal: '*'
        Action: execute-api:Invoke
        Resource: execute-api:/*
        Condition:
          NotIpAddress:
            aws:SourceIp: ${self:custom.allowedIps.${self:custom.myStage}, self:custom.allowedIps.dev}
Context

No response

主要语言
JavaScript
星标
46.9k
派生
5.7k
平均合并
23 小时 13 分钟
30 天内合并 PR
72

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

serverless/serverless 的其他 Issue

查看 serverless/serverless 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。