Skip to content

Commit

Permalink
fix: consistent RLS access for S3 access token
Browse files Browse the repository at this point in the history
  • Loading branch information
fenos committed Apr 16, 2024
1 parent 1d45ba0 commit d519404
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/storage/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class ObjectStorage {
await this.db.testPermission((db) => {
return Promise.all([
db.findObject(this.bucketId, sourceObjectName, 'id'),
db.updateObject(this.bucketId, sourceObjectName, {
db.createObject({
name: destinationObjectName,
version: newVersion,
bucket_id: destinationBucket,
Expand Down
30 changes: 24 additions & 6 deletions src/storage/protocols/s3/s3-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ export class S3ProtocolHandler {
}
)

await this.storage.db.insertUploadPart({
await this.storage.db.asSuperUser().insertUploadPart({
upload_id: UploadId,
version: multipart.version,
part_number: PartNumber || 0,
Expand Down Expand Up @@ -715,7 +715,25 @@ export class S3ProtocolHandler {
throw ERRORS.InvalidUploadId()
}

const multipart = await this.storage.db.findMultipartUpload(UploadId, 'id,version')
if (!Bucket) {
throw ERRORS.MissingParameter('Bucket')
}

if (!Key) {
throw ERRORS.MissingParameter('Key')
}

const multipart = await this.storage.db
.asSuperUser()
.findMultipartUpload(UploadId, 'id,version')

const uploader = new Uploader(this.storage.backend, this.storage.db)
await uploader.canUpload({
bucketId: Bucket,
objectName: Key,
owner: this.owner,
isUpsert: true,
})

await this.storage.backend.abortMultipartUpload(
storageS3Bucket,
Expand Down Expand Up @@ -989,7 +1007,7 @@ export class S3ProtocolHandler {

const maxParts = Math.min(command.MaxParts || 1000, 1000)

let result = await this.storage.db.asSuperUser().listParts(command.UploadId, {
let result = await this.storage.db.listParts(command.UploadId, {
afterPart: command.PartNumberMarker,
maxParts: maxParts + 1,
})
Expand Down Expand Up @@ -1103,8 +1121,8 @@ export class S3ProtocolHandler {
const uploader = new Uploader(this.storage.backend, this.storage.db)

await uploader.canUpload({
bucketId: Bucket as string,
objectName: Key as string,
bucketId: Bucket,
objectName: Key,
owner: this.owner,
isUpsert: true,
})
Expand Down Expand Up @@ -1133,7 +1151,7 @@ export class S3ProtocolHandler {
rangeBytes
)

await this.storage.db.insertUploadPart({
await this.storage.db.asSuperUser().insertUploadPart({
upload_id: UploadId,
version: multipart.version,
part_number: PartNumber,
Expand Down
15 changes: 6 additions & 9 deletions src/test/rls_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ tests:
- description: 'Will only able to move objects when authenticated'
policies:
- read_only_all_objects
- update_only_all_objects
- insert_only_all_objects
asserts:
- operation: bucket.get
status: 400
Expand All @@ -408,9 +408,12 @@ tests:
status: 400
error: 'new row violates row-level security policy'

- operation: upload
- operation: bucket.delete
status: 400
error: 'new row violates row-level security policy'
error: 'Bucket not found'

- operation: upload
status: 200

- operation: upload.upsert
status: 400
Expand All @@ -419,8 +422,6 @@ tests:
- operation: upload
bucketName: 'bucket_to_move_{{runId}}'
objectName: 'object_to_move_{{runId}}.txt'
policies:
- insert_only_all_objects
status: 200

- operation: object.move
Expand All @@ -431,10 +432,6 @@ tests:
- operation: object.delete
status: 400

- operation: bucket.delete
status: 400
error: 'Bucket not found'

- description: 'Will only able to copy owned objects when authenticated'
policies:
- read_only_all_objects
Expand Down

0 comments on commit d519404

Please sign in to comment.