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

Enable AWS SDK for go authentication to fix IMDSv1 issue #4897

Merged
merged 1 commit into from
Oct 7, 2022

Conversation

friedrichg
Copy link
Member

@friedrichg friedrichg commented Oct 5, 2022

What this PR does:
Introduces a boolean flag to enable AWS SDK for go auth
Enables AWS SDK for go auth

Which issue(s) this PR fixes:
Enable IMDSv1 again #4896 and most likely other use cases

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

alvinlin123
alvinlin123 previously approved these changes Oct 5, 2022
Copy link
Contributor

@alvinlin123 alvinlin123 left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@@ -86,6 +87,7 @@ func (cfg *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.BoolVar(&cfg.Insecure, prefix+"s3.insecure", false, "If enabled, use http:// for the S3 endpoint instead of https://. This could be useful in local dev/test environments while using an S3-compatible backend storage, like Minio.")
f.StringVar(&cfg.SignatureVersion, prefix+"s3.signature-version", SignatureVersionV4, fmt.Sprintf("The signature version to use for authenticating against S3. Supported values are: %s.", strings.Join(supportedSignatureVersions, ", ")))
f.StringVar(&cfg.BucketLookupType, prefix+"s3.bucket-lookup-type", BucketAutoLookup, fmt.Sprintf("The s3 bucket lookup style. Supported values are: %s.", strings.Join(supportedBucketLookupTypes, ", ")))
f.BoolVar(&cfg.AWSSDKAuth, prefix+"s3.aws-sdk-auth", false, "If enabled, the client will use default authentication methods of the AWS GO SDK for go based on known environment variables and known AWS config files.")
Copy link
Member

Choose a reason for hiding this comment

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

default should be true?

If this is false we are changing the behavior as far as i understood?

Copy link
Contributor

@alvinlin123 alvinlin123 Oct 5, 2022

Choose a reason for hiding this comment

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

I think this is default is false in thanos

Copy link
Contributor

@alvinlin123 alvinlin123 Oct 6, 2022

Choose a reason for hiding this comment

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

actually, after looking at Thanos' code a bit I am wondering if we should just "hardcode" AWSSDKAuth: true and not to have yet-another-configuration. Let me take a closer look to see if there is any cred resolution strategy that is not covered by AWSSDKAuth before its introduction.

Copy link
Contributor

Choose a reason for hiding this comment

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

After reading thanos-io/thanos#4667 and the code I think it's safe to just use AWSSDKAuth: true and don't expose yet-another-config. I am not sure what would be the benefit of using the the cred providers from minio over aws go sdk v2; I think minio didn't use aws sdk to minimize dependencies?

Also, we will need to have some logic to set AWSSDKAuth: false if AccessKeyID is defined; they can't co-exist.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree these options are hard to decide by users and we should try to avoid them. I am happy you jump on this quick :)

But here is the thing: s3 provider in objstore supports AWSSDKAuth: false and AccessKey: "".

https://github.com/thanos-io/objstore/blob/cec51c61948b0c04b60c035fd372cc83a540881b/providers/s3/s3.go#L231-L242

this is the code path my configuration was using in AWS and it was just by chance working due to their bug.

This makes no sense to AWS, but it makes sense to minio. Because minio has support for access without AccessKey that sort of works like AWS but doesn't use AWS libraries. See https://min.io/docs/minio/linux/developers/security-token-service.html

So I think the other possible solution to this is to rename our current s3 provider to minio provider and have a native s3 provider that sets AWSSDKAuth: true or even better don't use any minio at all. In that sense, Thanos should also do the same, I think.

I like this option better because it simplifies the use case for AWS and still enables minio.

Let me know what you think @alvinlin123 @alanprot @yeya24

Copy link
Contributor

@alvinlin123 alvinlin123 Oct 6, 2022

Choose a reason for hiding this comment

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

I think the resolver chain from Thanos at https://github.com/thanos-io/objstore/blob/cec51c61948b0c04b60c035fd372cc83a540881b/providers/s3/s3.go#L231-L242 is a subset of what the AWS SDK does.

In other words, the following cred resolving order implemented in Minio is covered by the AWS SDK; AWS SDK supports assume role with web identity, env var, loading shared profile etc.

chain = []credentials.Provider{
			wrapCredentialsProvider(&credentials.EnvAWS{}),
			wrapCredentialsProvider(&credentials.FileAWSCredentials{}),
			wrapCredentialsProvider(&credentials.IAM{
				Client: &http.Client{
					Transport: http.DefaultTransport,
				},
				Endpoint: config.STSEndpoint,
			}),
		}

So what works previously, AWSSDKAuth: false AccessKeyID:"", should be equivalent to AWSSDKAuth: true AccessKeyID:"" with the current version of Thanos and Minio.

Would you be able give AWSSDKAuth: true AccessKeyID:"" a try and see if it work on some of your test cluster?

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. AWS SDK might also do the right thing with minio in all the use cases, even without AccessKey.
Then we can skip this code path completely.

My use case is solved with AWSDKAuth: true, yes. Let me implement the logic you mentioned before about nonempty AccessKey.

@alvinlin123 alvinlin123 dismissed their stale review October 6, 2022 02:39

I have second thought on exposing new config

@friedrichg
Copy link
Member Author

Tested this minio using access_key_id and secret_access_key and see no problem.

Click to expand!
brew install minio
minio server /tmp/minio --address 127.0.0.1:9000

mini.yml

auth_enabled: false
blocks_storage:
  s3:
    access_key_id: minioadmin
    bucket_name: mybucket
    endpoint: 127.0.0.1:9000
    insecure: true
    secret_access_key: minioadmin
ingester:
  lifecycler:
    address: 127.0.0.1
    min_ready_duration: 0s
    ring:
      kvstore:
        store: inmemory
      replication_factor: 1
target: compactor,ingester,distributor
./cortex --config.file=mini.yaml

We also have integration tests based on minio.
If there is anything else that should be tested with minio, there should be a test for it.

Ready for review

@friedrichg friedrichg changed the title Allowing to enable AWS SDK for go authentication Enable AWS SDK for go authentication to fix IMDSv1 issue Oct 7, 2022
@alvinlin123 alvinlin123 merged commit c37a475 into master Oct 7, 2022
@friedrichg friedrichg deleted the allow-aws-sdk-auth branch October 12, 2022 09:58
zalegrala pushed a commit to grafana/tempo that referenced this pull request Aug 4, 2023
* Backport cortexproject/cortex#4897 to fix IDMSv1

Signed-off-by: Jakub Coufal <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Jakub Coufal <[email protected]>

---------

Signed-off-by: Jakub Coufal <[email protected]>
joe-elliott pushed a commit to grafana/tempo that referenced this pull request Aug 30, 2023
* Backport cortexproject/cortex#4897 to fix IDMSv1

Signed-off-by: Jakub Coufal <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Jakub Coufal <[email protected]>

---------

Signed-off-by: Jakub Coufal <[email protected]>
(cherry picked from commit ba621f6)
joe-elliott added a commit to grafana/tempo that referenced this pull request Aug 30, 2023
* Backport cortexproject/cortex#4897 to fix IDMSv1

Signed-off-by: Jakub Coufal <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Jakub Coufal <[email protected]>

---------

Signed-off-by: Jakub Coufal <[email protected]>
(cherry picked from commit ba621f6)

Co-authored-by: Jakub Coufal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants