AWS PHP SDK。Bucket加密不工作

问题描述 投票:1回答:1

我使用 PHP AWS SDK Ver 3 创建了一个脚本来创建一个 Bucket。

 try {
        // bucket creation
        $this->s3->createBucket([
            'Bucket' => $bucket,
        ]);

        // set the encryption type
        $result = $this->s3->putBucketEncryption([
            'Bucket' => $bucket,
            'ServerSideEncryptionConfiguration' => [
                'Rules' => [
                    'ApplyServerSideEncryptionByDefault' => [
                        'KMSMasterKeyID' => $key,
                        'SSEAlgorithm' => 'aws:kms'
                    ]
                ]
            ]
        ]);
        return true;
    } catch(S3Exception $e) {
        return false;
    }

Bucket被创建了,但是加密没有工作,当我检查控制台时,加密设置为NONE。当我记录结果时,我只能看到一个空体,根本没有错误。我传递的密钥ID是客户管理密钥中的密钥ID,而不是ARN。

同样为了测试这一点,我尝试使用默认的服务器端加密,通过更新我的ApplyServerSideEncryptionByDefault来使用SSEAlgorithm到AES256,但是在AWS控制台中检查这个, bucket上仍然没有加密记录。

AWS CONSOLE

php laravel amazon-web-services amazon-s3
1个回答
2
投票

你忘了在key中添加数组等参数 Rules

result = $this->s3->putBucketEncryption([
    'Bucket' => $bucket,
    'ServerSideEncryptionConfiguration' => [
        'Rules' => [
            [ // forget add array
                'ApplyServerSideEncryptionByDefault' => [
                    'KMSMasterKeyID' => $key,
                    'SSEAlgorithm' => 'aws:kms', // REQUIRED
                ],
            ],
        ],
    ],
]);

希望对你有所帮助。请检查 文件.

© www.soinside.com 2019 - 2024. All rights reserved.