Skip to content

Commit

Permalink
Merge pull request #7725 from tangledbytes/utkarsh/add/prohibit-stand…
Browse files Browse the repository at this point in the history
…ard-upload

Add configuration to deny upload to "STANDARD" storage class
  • Loading branch information
tangledbytes authored Jan 25, 2024
2 parents 38d8d28 + 8e67135 commit ac96a39
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ config.S3_CORS_EXPOSE_HEADERS = [
].join(',');
config.STS_CORS_EXPOSE_HEADERS = 'ETag';

config.DENY_UPLOAD_TO_STORAGE_CLASS_STANDARD = false;

/////////////////////
// SECRETS CONFIG //
/////////////////////
Expand Down
6 changes: 6 additions & 0 deletions src/endpoint/s3/ops/s3_post_object_uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

const s3_utils = require('../s3_utils');
const mime = require('mime');
const config = require('../../../../config');
const S3Error = require('../s3_errors').S3Error;

/**
* http://docs.aws.amazon.com/AmazonS3/latest/API/mpUploadInitiate.html
Expand All @@ -12,6 +14,10 @@ async function post_object_uploads(req, res) {
const tagging = s3_utils.parse_tagging_header(req);
const encryption = s3_utils.parse_encryption(req);
const storage_class = s3_utils.parse_storage_class_header(req);
if (config.DENY_UPLOAD_TO_STORAGE_CLASS_STANDARD && storage_class === s3_utils.STORAGE_CLASS_STANDARD) {
throw new S3Error(S3Error.InvalidStorageClass);
}

const reply = await req.object_sdk.create_object_upload({
bucket: req.params.bucket,
key: req.params.key,
Expand Down
3 changes: 3 additions & 0 deletions src/endpoint/s3/ops/s3_put_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ async function put_object(req, res) {
const copy_source = s3_utils.parse_copy_source(req);
const tagging = s3_utils.parse_tagging_header(req);
const storage_class = s3_utils.parse_storage_class_header(req);
if (config.DENY_UPLOAD_TO_STORAGE_CLASS_STANDARD && storage_class === s3_utils.STORAGE_CLASS_STANDARD) {
throw new S3Error(S3Error.InvalidStorageClass);
}
const lock_settings = config.WORM_ENABLED ? s3_utils.parse_lock_header(req) : undefined;
// Copy request sends empty content and not relevant to the object data
const { size, md5_b64, sha256_b64 } = copy_source ? {} : {
Expand Down

0 comments on commit ac96a39

Please sign in to comment.