gpt4 book ai didi

amazon-web-services - AWS S3 CloudFormation 只读权限

转载 作者:行者123 更新时间:2023-12-03 07:31:53 25 4
gpt4 key购买 nike

我正在尝试创建两个用户并授予 user1 对 s3 存储桶的只读权限,我还需要授予 user2 读写访问权限。这是我到目前为止所做的事情

AWSTemplateFormatVersion: "2010-09-09"


Resources:
s3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private

User1:
Type: AWS::IAM::User

User2:
Type: AWS::IAM::User

User1Key:
Type: AWS::IAM::AccessKey
Properties:
UserName: !Ref 'User1'

User2Key:
Type: AWS::IAM::AccessKey
Properties:
UserName: !Ref 'User2'
Outputs:
AccessKey:
Value: !Ref 'User1Key'
Description: AWSAccessKeyId of User 1
SecretKey:
Value: !GetAtt [User1Key, SecretAccessKey]
Description: AWSSecretAccessKey of User 1
AccessKey2:
Value: !Ref 'User2Key'
Description: AWSAccessKeyId of User 2
SecretKey2:
Value: !GetAtt [User2Key, SecretAccessKey]
Description: AWSSecretAccessKey of User 2

我不知道如何实现

最佳答案

其中一种方法是使用 IAM 策略来实现相同的目的。

看看下面的代码。我们正在创建两种策略,一种用于读取,一种用于写入。一个用户同时分配有读取和写入策略,另一用户仅分配有读取策略。

AWSTemplateFormatVersion: "2010-09-09"

Resources:
s3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private

S3ReadPolicy:
Type: "AWS::IAM::Policy"
Properties:
PolicyName: "S3ReadPolicy"
PolicyDocument:
Statement:
- Action: s3:GetObject
Effect: Allow
Resource: !Sub "arn:aws:s3:::${s3Bucket}/*"
- Action: s3:ListBucket
Effect: Allow
Resource: !Sub "arn:aws:s3:::${s3Bucket}"
Users:
- Ref: User1
- Ref: User2

S3WritePolicy:
Type: "AWS::IAM::Policy"
Properties:
PolicyName: "S3WritePolicy"
PolicyDocument:
Statement:
- Action: s3:PutObject
Effect: Allow
Resource: !Sub "arn:aws:s3:::${s3Bucket}/*"
Users:
- Ref: User2

User1:
Type: AWS::IAM::User

User2:
Type: AWS::IAM::User

User1Key:
Type: AWS::IAM::AccessKey
Properties:
UserName: !Ref "User1"

User2Key:
Type: AWS::IAM::AccessKey
Properties:
UserName: !Ref "User2"
Outputs:
AccessKey:
Value: !Ref "User1Key"
Description: AWSAccessKeyId of User 1
SecretKey:
Value: !GetAtt [User1Key, SecretAccessKey]
Description: AWSSecretAccessKey of User 1
AccessKey2:
Value: !Ref "User2Key"
Description: AWSAccessKeyId of User 2
SecretKey2:
Value: !GetAtt [User2Key, SecretAccessKey]
Description: AWSSecretAccessKey of User 2

希望这有帮助

关于amazon-web-services - AWS S3 CloudFormation 只读权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59585116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com