AWS 讀/寫 RDS 策略

AWS 讀/寫 RDS 策略

abc-database-backups/rds/postgresql-backup在我的場景中,我想要一個允許在 S3 上讀寫的策略?我們希望我的伺服器添加該存取權限。

創建角色並將其附加到伺服器是最好還是向伺服器添加密鑰最好?

我試過這個:

aws iam create-policy \
     --policy-name rds-s3-integration-policy \
     --policy-document '{
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Effect": "Allow",
                    "Action": "s3:ListAllMyBuckets",
                    "Resource": "*"
                },
                {
                    "Effect": "Allow",
                    "Action": [
                        "s3:ListBucket",
                        "s3:GetBucketACL",
                        "s3:GetBucketLocation"
                    ],
                    "Resource": "arn:aws:s3:::bucket_name"
                },
                {
                    "Effect": "Allow",
                    "Action": [
                        "s3:GetObject",
                        "s3:PutObject",
                        "s3:ListMultipartUploadParts",
                        "s3:AbortMultipartUpload"
                    ],
                    "Resource": "arn:aws:s3:::bucket_name/key_prefix/*"
                }
            ]
        }' 

我將非常感謝任何幫助,因為我在這一領域的經驗有些有限。

答案1

用一個服務相關角色讓 RDS 提供對 S3 和您需要的任何其他命名資源的存取。確保 RDS 實例具有此角色。你也應該閱讀這個文檔關於使用擴充將 S3 資料導入 RDS PostgreSQL。

我已經將一些 CloudFormation 基礎架構改編為我擁有的應該設定角色的程式碼。您需要修改權限和儲存桶名稱以滿足您的要求。它應該按原樣工作,但我確實必須修改我現有的程式碼,所以如果它不能 100% 工作,請編輯帖子或評論,以便我可以編輯它。

AWSTemplateFormatVersion: '2010-09-09'
Description: Role for RDS

Resources:    
    RdsS3IntegrationRole:
        Type: AWS::IAM::Role
        Properties:
            RoleName: RdsS3IntegrationRole
            AssumeRolePolicyDocument:
                Version: 2012-10-17
                Statement:
                    -
                        Effect: Allow
                        Principal:
                            Service:
                                - rds.amazonaws.com
                        Action:
                            - sts:AssumeRole
                
    RDSS3IntegrationPolicy:
        Type: AWS::IAM::Policy
        Properties:
            Roles:
                - !Ref 'RdsS3IntegrationRole'
            PolicyName: RDSS3IntegrationPolicy
            PolicyDocument:
                Statement:
                    - Effect: Allow
                        Action:
                            - s3:GetObject
                            - s3:ListBucket 
                            - s3:PutObject 
                        Resource:
                            - !Sub 'arn:aws:s3:::bucketname/*'
                            - !Sub 'arn:aws:s3:::bucketname'
                    - Effect: Allow
                        Action:
                            - kms:Decrypt
                            - kms:Encrypt
                            - kms:GenerateDataKey
                            - kms:ReEncryptTo
                            - kms:DescribeKey
                            - kms:ReEncryptFrom
                        Resource:
                            - !Sub 'arn:aws:kms:ap-southeast-2:${AWS::AccountId}:key/*'

相關內容