Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: ACL on bucket creation in S3 Streamwrapper #2676

Merged
merged 7 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/nextrelease/streamwrapper-acl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "bugfix",
"category": "S3",
"description": "Removes ACL from bucket creation in S3 Streamwrapper."
}
]
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"paragonie/random_compat": ">= 2",
"sebastian/comparator": "^1.2.3 || ^4.0",
"yoast/phpunit-polyfills": "^1.0",
"dms/phpunit-arraysubset-asserts": "^0.4.0"
"dms/phpunit-arraysubset-asserts": "^0.4.0",
"psr/http-message": "<1.1"
},
"suggest": {
"ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages",
Expand Down
1 change: 1 addition & 0 deletions src/S3/StreamWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ private function createBucket($path, array $params)
return $this->triggerError("Bucket already exists: {$path}");
}

unset($params['ACL']);
return $this->boolCall(function () use ($params, $path) {
$this->getClient()->createBucket($params);
$this->clearCacheKey($path);
Expand Down
3 changes: 3 additions & 0 deletions tests/Crypto/RandomByteStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public function __construct($maxLength)
});
}

/**
* @return int|null
*/
public function getSize()
{
return $this->maxLength;
Expand Down
8 changes: 4 additions & 4 deletions tests/S3/StreamWrapperPathStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function testCreatingAlreadyExistingBucketForKeyRaisesError()
mkdir('s3://already-existing-bucket/key');
}

public function testCreatingBucketsSetsAclBasedOnPermissions()
public function testCreatingBucketsDoesNotSetAcl()
{
$history = new History();
$this->client->getHandlerList()->appendSign(Middleware::history($history));
Expand Down Expand Up @@ -296,9 +296,9 @@ function ($cmd, $r) { return new S3Exception('404', $cmd); },
$this->assertSame('PUT', $entries[1]['request']->getMethod());
$this->assertSame('/bucket/', $entries[1]['request']->getUri()->getPath());
$this->assertSame('s3.amazonaws.com', $entries[1]['request']->getUri()->getHost());
$this->assertSame('public-read', (string) $entries[1]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('authenticated-read', (string) $entries[3]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('private', (string) $entries[5]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('', (string) $entries[1]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('', (string) $entries[3]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('', (string) $entries[5]['request']->getHeaderLine('x-amz-acl'));
}

public function testCreatesNestedSubfolder()
Expand Down
8 changes: 4 additions & 4 deletions tests/S3/StreamWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public function testCreatingAlreadyExistingBucketForKeyRaisesError()
mkdir('s3://already-existing-bucket/key');
}

public function testCreatingBucketsSetsAclBasedOnPermissions()
public function testCreatingBucketsDoesNotSetAcl()
{
$history = new History();
$this->client->getHandlerList()->appendSign(Middleware::history($history));
Expand Down Expand Up @@ -409,9 +409,9 @@ function ($cmd, $r) { return new S3Exception('404', $cmd); },
$this->assertSame('PUT', $entries[1]['request']->getMethod());
$this->assertSame('/', $entries[1]['request']->getUri()->getPath());
$this->assertSame('bucket.s3.amazonaws.com', $entries[1]['request']->getUri()->getHost());
$this->assertSame('public-read', (string) $entries[1]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('authenticated-read', (string) $entries[3]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('private', (string) $entries[5]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('', (string) $entries[1]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('', (string) $entries[3]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('', (string) $entries[5]['request']->getHeaderLine('x-amz-acl'));
}

public function testCreatesNestedSubfolder()
Expand Down
8 changes: 4 additions & 4 deletions tests/S3/StreamWrapperV2ExistenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public function testCreatingAlreadyExistingBucketForKeyRaisesError()
mkdir('s3://already-existing-bucket/key');
}

public function testCreatingBucketsSetsAclBasedOnPermissions()
public function testCreatingBucketsDoesNotSetAcl()
{
$history = new History();
$this->client->getHandlerList()->appendSign(Middleware::history($history));
Expand Down Expand Up @@ -377,9 +377,9 @@ function ($cmd, $r) {return new S3Exception(
$this->assertSame('PUT', $entries[1]['request']->getMethod());
$this->assertSame('/', $entries[1]['request']->getUri()->getPath());
$this->assertSame('bucket.s3.amazonaws.com', $entries[1]['request']->getUri()->getHost());
$this->assertSame('public-read', (string) $entries[1]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('authenticated-read', (string) $entries[3]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('private', (string) $entries[5]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('', (string) $entries[1]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('', (string) $entries[3]['request']->getHeaderLine('x-amz-acl'));
$this->assertSame('', (string) $entries[5]['request']->getHeaderLine('x-amz-acl'));
}

public function testCreatesNestedSubfolder()
Expand Down