首页 > 解决方案 > 我可以允许匿名访问 AWS API Gateway 文档吗?

问题描述

我有一个 CloudFormation 模板,其中包含使用 OpenAPI 3.0 主体配置的 API 网关。我想让我的 API 的用户可以使用 OpenAPI 规范。理想情况下,在一个不错的 GUI 中,但这个答案表明这是不可能的。我不想设置开发者门户。

我的 CFT 包含为 API 创建文档的 DocumentationVersion 元素。

根据这个这个,我应该能够从像这样的 URL 下载我的文档

https://apigateway.[my_aws_region].amazonaws.com/restapis/[my_api_id]/stages/[my_api_stage]/exports/oas30

事实上,当我访问这个 URL 时,我会得到类似的东西

{"logref":"56f5173b-a329-11e9-a8d5-e97c525eb634","message":"Missing Authentication Token"}

这表明这将使用正确的令牌。

此页面显示您可以使用策略控制对 API 文档的访问。(虽然奇怪的是它说要使用的 account_id 是您要授予访问权限的用户之一 - 对吗?)

所以我尝试将以下资源添加到我的 CFT:

    "ApiDocumentationAccessPolicy": {
        "Type": "AWS::IAM::ManagedPolicy",
        "Properties": {
            "Description": "Read access to API documentation restricted by IP",
            "PolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Action": [
                            "apigateway:GET"
                        ],
                        "Resource": {
                            "Fn::Join": [
                                "",
                                [
                                    "arn:aws:apigateway::",
                                    { "Ref": "AWS::AccountId" },
                                    ":/restapis/",
                                    "*/documentation/*"
                                ]
                            ]
                        },
                        "Condition" : {
                            "IpAddress": {
                                "aws:SourceIp": ["xxx.xxx.xxx.xxx" ]
                            }
                        }
                    }
                ]
            }
        }
    },

但是,我仍然收到“缺少身份验证令牌”。我相信“条件”部分是正确的,因为它在 CFT 的其他地方使用。

我想做的事情是否可能,如果是,我哪里错了?

编辑添加"Principal": "*"到上面的政策声明并将其直接移动到 APIGateway 的政策似乎也没有帮助。

标签: amazon-web-servicesaws-api-gateway

解决方案


推荐阅读