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

s3_bucket_name: add length validation #554

Merged

Conversation

davimmt
Copy link
Contributor

@davimmt davimmt commented Sep 25, 2023

}

bucketNameMinLength := 3
bucketNameMaxLength := 63
Copy link
Member

Choose a reason for hiding this comment

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

Can you avoid hardcoding this and find somewhere to reference it? AWS has a lot of schemas for their API that should specify this somewhere...

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it seems rather bad to hardcode, but I also haven't found somewhere to reference it from.

@bendrucker
Copy link
Member

Seems like this could be added to the existing aws_s3_bucket_name rule. Ideally that would have been aws_s3_bucket_name_prefix and aws_s3_bucket_name would just enforce the official rules. In addition to the length limit, the rule should enforce all the other requirements.

if len(name) < bucketNameMinLength || len(name) > bucketNameMaxLength {
runner.EmitIssue(
r,
fmt.Sprintf(`Bucket name "%s" length must be within %d - %d character range`, name, bucketNameMinLength, bucketNameMaxLength),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt.Sprintf(`Bucket name "%s" length must be within %d - %d character range`, name, bucketNameMinLength, bucketNameMaxLength),
fmt.Sprintf("Bucket name %q must be between %d and %d characters", name, bucketNameMinLength, bucketNameMaxLength),

Copy link
Contributor Author

@davimmt davimmt Sep 25, 2023

Choose a reason for hiding this comment

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

Nice. I've just commited it through rebasing.

@davimmt
Copy link
Contributor Author

davimmt commented Sep 25, 2023

Seems like this could be added to the existing aws_s3_bucket_name rule. Ideally that would have been aws_s3_bucket_name_prefix and aws_s3_bucket_name would just enforce the official rules. In addition to the length limit, the rule should enforce all the other requirements.

I thought about it and I think it's probably the right thing to do; however, for what I've seen, the aws_s3_bucket_name rule requires an explicit regex configuration and it's not enabled by default (as the bucket name length enforcement should always be), so I decided to make it separate.

@bendrucker
Copy link
Member

Right, so:

requires an explicit regex configuration

That would need to become optional

it's not enabled by default

Then this can happen

@davimmt davimmt force-pushed the aws_s3_bucket_name_length branch from 86f199a to 1ff7feb Compare September 25, 2023 18:44
@davimmt
Copy link
Contributor Author

davimmt commented Sep 25, 2023

Yeah, that's right. I was hoping your feedback on this matter, if you agreed on using the same rule. I will work on it, then.

@davimmt davimmt force-pushed the aws_s3_bucket_name_length branch from 1ff7feb to 21b745f Compare September 25, 2023 19:04
@davimmt davimmt force-pushed the aws_s3_bucket_name_length branch from 2f6f2ed to 86a8e3e Compare September 25, 2023 19:31
@davimmt davimmt force-pushed the aws_s3_bucket_name_length branch from 86a8e3e to c205007 Compare September 25, 2023 20:46
@davimmt
Copy link
Contributor Author

davimmt commented Sep 26, 2023

Seems all right.

image

Have you found anything about the min and max numbers from the API?

Also, your opinion on this. The bucket name length should throw an Error severity, but that was not the case for the regex and prefix checks.

@bendrucker
Copy link
Member

Thanks, will review and respond within the next 1-2 weeks (traveling)

Copy link
Member

@bendrucker bendrucker left a comment

Choose a reason for hiding this comment

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

Thanks for your patience!

@bendrucker bendrucker changed the title ADD RULE aws_s3_bucket_name_length s3_bucket_name: add length validation Oct 26, 2023
@bendrucker bendrucker merged commit 83e7f11 into terraform-linters:master Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants