Skip to content

Commit

Permalink
Add acl option for s3 storage (#8264)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Cousens <413395+dcousens@users.noreply.github.com>
  • Loading branch information
jhohlfeld and dcousens committed Jan 26, 2023
1 parent fdff2e0 commit 5a9ca53
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/five-papayas-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@keystone-6/core': minor
'@keystone-6/website': minor
---

Add acl option for s3 storage configuration.
13 changes: 13 additions & 0 deletions docs/pages/docs/config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,19 @@ S3 options:
- `endpoint`: The endpoint to use - if provided, this endpoint will be used instead of the default amazon s3 endpoint
- `forcePathStyle`: Force the old pathstyle of using the bucket name after the host
- `signed.expiry`: Use S3 URL signing to keep S3 assets private. `expiry` is in seconds
{% if $nextRelease %}
- `acl`: Set the permissions for the uploaded asset. If not set, the permissions of the asset will depend on your S3 provider's default settings.
These values are supported:
- `'private'` No public access.
- `'public-read'` Public read access.
- `'public-read-write'` Public read and write access.
- `'aws-exec-read'` Amazon EC2 gets read access.
- `'authenticated-read'` Authenticated users get access.
- `'bucket-owner-read'` Bucket owner gets read access.
- `'bucket-owner-full-control'` Bucket owner gets full control.

See https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl for more details.
{% /if %}

```typescript
import { config } from '@keystone-6/core';
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/lib/assets/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function s3ImageAssetsAPI(storageConfig: StorageConfig & { kind: 's3' }):
gif: 'image/gif',
jpg: 'image/jpeg',
}[extension],
ACL: storageConfig.acl,
},
});
await upload.done();
Expand Down Expand Up @@ -63,6 +64,7 @@ export function s3FileAssetsAPI(storageConfig: StorageConfig & { kind: 's3' }):
Key: (storageConfig.pathPrefix || '') + filename,
Body: stream,
ContentType: 'application/octet-stream',
ACL: storageConfig.acl,
},
});

Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/types/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ export type StorageConfig = (
endpoint?: string;
/** If true, will force the 'old' S3 path style of putting bucket name at the start of the pathname of the URL */
forcePathStyle?: boolean;
/** A string that sets permissions for the uploaded assets. Default is 'private'.
*
* Amazon S3 supports a set of predefined grants, known as canned ACLs.
* See https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl
* for more details.
*/
acl?:
| 'private'
| 'public-read'
| 'public-read-write'
| 'aws-exec-read'
| 'authenticated-read'
| 'bucket-owner-read'
| 'bucket-owner-full-control';
}
) &
FileOrImage;
Expand Down

1 comment on commit 5a9ca53

@vercel
Copy link

@vercel vercel bot commented on 5a9ca53 Jan 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.