Skip to content

Conversation

@disq
Copy link
Member

@disq disq commented May 3, 2023

This is to prevent an s3manager unauthenticated call to get region (which then show up on CloudTrail events)

Fixes #10548

@cq-bot cq-bot added the aws label May 3, 2023
@disq disq requested a review from bbernays May 3, 2023 09:38
Copy link
Collaborator

@bbernays bbernays left a comment

Choose a reason for hiding this comment

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

This looks good... But my only question is why did it work? If it was making unsigned calls then how was it getting the information about private buckets?

@disq disq added the automerge Automatically merge once required checks pass label May 3, 2023
@spofdamon
Copy link

@bbernays If you look at the sample request in the docs, it's unsigned but still authorized:

https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadBucket.html

I think the real answer here is probably "S3 is a very very old API".

@spofdamon
Copy link

I have a feeling that it will answer HEAD requests that confirm region without any auth whatsoever. This is probably what the API itself does when you anonymously download something from S3 without putting the region in the host.

@kodiakhq kodiakhq bot merged commit 7f0128f into cloudquery:main May 3, 2023
@RyPeck
Copy link

RyPeck commented May 3, 2023

@spofdamon that's correct. golang example below to run in a Docker container without any aws config for the curious. Works for public and private buckets.

package main

import (
        "context"
        "fmt"
        "log"
        "errors"
        "os"

        "github.com/aws/aws-sdk-go-v2/config"
        "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
        "github.com/aws/aws-sdk-go-v2/service/s3"
)

func main() {
        ctx := context.TODO()

        cfg, err := config.LoadDefaultConfig(ctx,
                config.WithRegion("us-west-1"),
        )

        if err != nil {
                log.Println("error:", err)
                return
        }

        bucket := "asdf"

        region, err := manager.GetBucketRegion(ctx, s3.NewFromConfig(cfg), bucket)

        if err != nil {
                var bnf manager.BucketNotFound
                if errors.As(err, &bnf) {
                        fmt.Fprintf(os.Stderr, "unable to find bucket %s's region\n", bucket)
                }
                return
        }

        fmt.Printf("Bucket %s is in %s region\n", bucket, region)
}

@disq disq deleted the fix/aws_s3_get_bucket_location_instead_of_region branch May 3, 2023 15:46
kodiakhq bot pushed a commit that referenced this pull request May 9, 2023
🤖 I have created a release *beep* *boop*
---


## [17.2.0](plugins-source-aws-v17.1.0...plugins-source-aws-v17.2.0) (2023-05-09)


### This Release has the Following Changes to Tables
- Table `aws_config_configuration_aggregators` was added
- Table `aws_config_remediation_configurations` was added
- Table `aws_config_retention_configurations` was added
- Table `aws_networkfirewall_firewall_policies` was added
- Table `aws_networkfirewall_rule_groups` was added
- Table `aws_securityhub_enabled_standards` was added
- Table `aws_securityhub_hubs` was added
- Table `aws_wafregional_rule_groups`: column added with name `rule_ids` and type `StringArray`

### Features

* **aws-services:** Support newly added regions ([#10598](#10598)) ([e56bae2](e56bae2))
* **aws:** Add `aws_securityhub_hubs` and `aws_securityhub_enabled_standards` tables ([#10553](#10553)) ([bc77f53](bc77f53)), closes [#1592](#1592)
* **aws:** Add networkfirewall resources ([#10547](#10547)) ([74ada09](74ada09))
* **aws:** Add rule_ids to wafregional rule_group ([#10594](#10594)) ([4637baa](4637baa))
* **aws:** Refine AWS Org Error Message ([#10569](#10569)) ([b761ebc](b761ebc))
* More AWS Config resources ([#10509](#10509)) ([3db4ebb](3db4ebb))


### Bug Fixes

* **aws-policies:** Api Gateway xray tracing enabled query ([#10597](#10597)) ([341d849](341d849))
* **aws:** Use GetBucketLocation for S3 bucket region ([#10550](#10550)) ([7f0128f](7f0128f)), closes [#10548](#10548)
* **deps:** Update module github.com/aws/aws-sdk-go-v2/config to v1.18.23 ([#10576](#10576)) ([eeb13d5](eeb13d5))
* **deps:** Update module github.com/aws/aws-sdk-go-v2/internal/v4a to v1.0.25 ([#10585](#10585)) ([00d7449](00d7449))
* **deps:** Update module github.com/aws/aws-sdk-go-v2/service/accessanalyzer to v1.19.12 ([#10586](#10586)) ([4f929fe](4f929fe))
* Remove unused line in mockassert library ([#10608](#10608)) ([3fc8708](3fc8708))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Automatically merge once required checks pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: unexpected anonymous HeadBucket API calls from CloudQuery

6 participants