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

Amazon S3 Buckets Creation not properly working for regions #40

Open
JattJames opened this issue Jul 31, 2023 · 2 comments
Open

Amazon S3 Buckets Creation not properly working for regions #40

JattJames opened this issue Jul 31, 2023 · 2 comments

Comments

@JattJames
Copy link

JattJames commented Jul 31, 2023

There was a discussion i saw on CFML Slack Channel where one of the Guys' named @simone has shared some details that the Creating of Buckets is not working, I replicated the cases he mentioned and noticed something, the Buckets do get Created with an error, but the Permissions are set to block access all.

Here is the Code he used for Creating Buckets

He Modified the code as below:

boolean function putBucket(
		required string bucketName    = variables.defaultBucketName,
		string acl                    = variables.defaultACL,
		string location               = "",
		string objectOwnership        = variables.defaultObjectOwnership,
		boolean BlockPublicAcls       = false,
		boolean IgnorePublicAcls      = false,
		boolean BlockPublicPolicy     = false,
		boolean RestrictPublicBuckets = false
	){
		requireBucketName( arguments.bucketName );
		if(arguments.location == "EU") {
			var constraintXML = "<CreateBucketConfiguration><LocationConstraint>EU</LocationConstraint></CreateBucketConfiguration>"
		} else if(arguments.location == 'ca-central-1') {
			var constraintXML = "<CreateBucketConfiguration><LocationConstraint>ca-central-1</LocationConstraint></CreateBucketConfiguration>"
		} else if(arguments.location == 'ap-southeast-2') {
			var constraintXML = "<CreateBucketConfiguration><LocationConstraint>ap-southeast-2</LocationConstraint></CreateBucketConfiguration>"
		} else {
			var constraintXML = "";
		}
		var headers       = { "content-type" : "text/xml" };
		if ( len( arguments.objectOwnership ) ) {
			if (
				!listFindNoCase(
					"BucketOwnerPreferred,ObjectWriter,BucketOwnerEnforced",
					arguments.objectOwnership
				)
			) {
				throw(
					message = "Invalid value [#arguments.objectOwnership#] for [objectOwnership] when creating bucket.",
					detail  = "Valid options are: [BucketOwnerPreferred, ObjectWriter, BucketOwnerEnforced]"
				);
			}
			headers[ "x-amz-object-ownership" ] = arguments.objectOwnership;
		}

		var results = s3Request(
			method   = "PUT",
			resource = arguments.bucketName,
			body     = constraintXML,
			headers  = headers
		);

		// s3 does not provide a way to set this when creating the bucket
		putBucketPublicAccess(
			arguments.bucketName,
			arguments.BlockPublicAcls,
			arguments.IgnorePublicAcls,
			arguments.BlockPublicPolicy,
			arguments.RestrictPublicBuckets
		);

		// Must set ACL in second step in case public access settings above would prevent the ACL from being saved.
		putBucketACL( arguments.bucketName, arguments.acl );

		return results.responseheader.status_code == 200;
	}

so in the above I see he added some conditions in the constraintXML which makes the code to check which region it has to choose and create

Thanks

@lmajano
Copy link
Contributor

lmajano commented Aug 3, 2023

@bdw429s @jclausen can you validate this?

@bdw429s
Copy link
Contributor

bdw429s commented Aug 9, 2023

the Buckets do get Created with an error

What is the error?

My feedback here is pretty much the same as it was on Slack. If someone knows the correct code to work, please send a pull request. But ideally, we'd use some code a bit more generic and not a big if statement with nearly identical XML blocks for each region.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants