-
Notifications
You must be signed in to change notification settings - Fork 104
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
feat: use manager.GetBucketRegion()
to retrieve S3 bucket region instead of GetBucketLocation
#2082
Conversation
Test results:
|
1faf018
to
b0bf89e
Compare
dc1ab15
to
b1bf791
Compare
3398a5d
to
71cde92
Compare
Rebased on main following merge of #2080 |
9460998
to
2f640e9
Compare
8825d42
to
c310fd8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @pdecat , sorry for the long delay in reviewing!
I've added some initial review comments/questions, can you please take a look? Thanks!
aws/table_aws_s3_bucket.go
Outdated
// Not doing so with such buckets causes `tls: failed to verify certificate: x509: certificate is valid for *.s3.amazonaws.com, s3.amazonaws.com, not www.somedomain.com.s3.amazonaws.com (SQLSTATE HV000)` errors. | ||
// FIXME: do we also want to implement non S3 path style? It may help avoiding rate limiting, but given the above limitation, | ||
// it may be better to define a default Steampipe limiter once actual AWS limits are discovered. | ||
resp, err := http.Head(fmt.Sprintf("https://s3.amazonaws.com/%s", bucket)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdecat I think we need to handle other partitions, like US GovCloud, China, ISO-B, etc., else this request will return a 404 code I believe. The URL could be adjusted based on the commonColumnData.Partition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good point, and apparently only buckets in regions of the standard AWS partition are exposed using this global endpoint. I do not have access to buckets in GovCloud and ISO partitions to verify this though. Can make some tests against buckets in China, but that won't cover all cases anyway.
Probably a definitive argument to switch to using the manager.GetBucketRegion()
as suggested by @vpartington a few weeks ago.
FWIW, it seems the terraform provider does not support the ISO partitions either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdecat We can do some testing against GovCloud buckets within our team, but it seems like switching to manager.GetBucketRegion()
would be a good change if that function natively supports other partitions (even if it's not all of them, like ISO).
Would you be able to update this PR to use that function instead? Sorry, I don't want to drag this PR out more (mostly due to my slow response times), but we do have some users in non-commercial partitions at the moment.
If you need any help implementing/testing that change, please let us know, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Testing in progress...
return bucketRegion, nil | ||
} | ||
|
||
func getBucketRegion(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the benefit of having this separate function vs. combining it with doGetBucketRegion
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getBucketRegion()
gets the bucket name from the hydrate item's Name
attribute directly, whereas getBucketRegionForObjects()
which also uses doGetBucketRegion()
gets it from the bucket_name
query data qualifier.
@pdecat Cross-posting here for better visibility - Did you notice any performance improvements, or other benefits? If we need to manually handle what the |
Hi @cbruno10,
I believe I've mentioned this somewhere, probably in Slack, but the main benefit is to avoid the errors that occur if the I'll address all the other comments ASAP. |
@pdecat Is there a specific query or set of queries where the plugin would call |
Found my comment investigating the errors with With Steampipe, here's the error message that is logged when
In Slack, I've found these comments (copying it as it will soon be inaccessible):
|
Here's a related issue mentioning the error I'm facing #1713 |
FYI, instead of using |
Hi @vpartington,
Interesting, this helper function does seem to do an unauthenticated HTTP HEAD request too (which is somewhat confusing because there's an actual HeadBucket API and it states All HeadBucket requests must be authenticated and signed by using IAM credentials). And it probably handles other uncommon cases as described in https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/service/s3#HeadBucketInput. |
Anyway, I've not faced any issue yet since I've switched to using HTTP HEAD two months ago. And it works even if the bucket is not yours:
Note the |
The Just as I was writing a comment for why I do For me having less code to test or maintain is the reason I threw away my code. But then I have not had my code running successfully for a while, so I would also stick with what I've got if I were you. Just thought I'd reach out because I saw you had struggled with the same problem in this MR. Take care! |
c310fd8
to
d8bdb5c
Compare
d8bdb5c
to
d858ce7
Compare
…tBucketLocation Signed-off-by: Patrick Decat <[email protected]>
Signed-off-by: Patrick Decat <[email protected]>
d858ce7
to
8c8b32b
Compare
@pdecat Sorry for the long response time (again)! I've left a few follow-up questions/suggestions, can you please have a look when you get a chance? Thanks! |
Hi @cbruno10, I've implemented the requested changes. PTAL :) |
manager.GetBucketRegion()
to retrieve S3 bucket region instead of GetBucketLocation
Can confirm everything also works fine with the use of |
Thanks so much @pdecat for this PR, and also to @vpartington for sharing info on |
This PR replaces usage of
GetBucketLocation
REST API calls by plain HTTPHEAD
requests to retrieve S3 bucket region.Resolves #1586
Note: this based on the branch of #2080 to allow running thetests/aws_s3_bucket/
test.