You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过OAC让CloudFront访问S3返回Access Denied问题排查

问题:S3+CloudFront配置私有访问后出现Access Denied错误

我在S3存储桶托管静态网站,测试阶段将存储桶设为完全公开并开启静态网站托管,通过CloudFront备用域名访问一切正常。现在希望限制S3文件权限,仅允许CloudFront访问,按官方及第三方教程操作后始终出现Access Denied错误。

当前配置细节

  • 完全禁用S3公开访问,关闭静态网站托管
  • 创建CloudFront Origin Access Control(OAC),选择「sign requests」,源类型为S3
  • CloudFront源配置选择目标S3桶,启用上述OAC,未开启Origin Shield
  • 已将CloudFront生成的S3策略粘贴到桶策略字段,内容如下:
    {    
        "Version": "2008-10-17",    
        "Id": "PolicyForCloudFrontPrivateContent",    
        "Statement": [        
            {            
                "Sid": "AllowCloudFrontServicePrincipal",            
                "Effect": "Allow",            
                "Principal": {                
                    "Service": "cloudfront.amazonaws.com"            
                },            
                "Action": "s3:GetObject",            
                "Resource": "arn:aws:s3:::examplebucketid/*",            
                "Condition": {                
                    "StringEquals": {                    
                        "AWS:SourceArn": "arn:aws:cloudfront::11736596049:distribution/E1OS67E245W70W"                
                    }            
                }        
            }    
        ]
    }
    
  • S3桶Object Ownership设为「Bucket owner enforced」,配置过CORS(也尝试移除),当前规则:
    [    
        {        
            "AllowedHeaders": [            
                "*"        
            ],        
            "AllowedMethods": [            
                "GET",            
                "HEAD"        
            ],        
            "AllowedOrigins": [            
                "*"        
            ],        
            "ExposeHeaders": [],        
            "MaxAgeSeconds": 3000    
        }
    ]
    
  • CloudFront默认行为选择该S3桶为源,HTTP重定向到HTTPS,默认根对象设为/index.html(文件上传正常,设私有前可访问)

已尝试的操作

  • 重新创建S3桶和CloudFront分发
  • 改用OAI方式,并让CloudFront自动更新S3策略
  • 每次修改后均等待部署完成再测试,结果一致

请问还有哪些调整或检查方向可以解决这个Access Denied问题?

内容的提问来源于stack exchange,提问作者rexcision

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 23:43:29