-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #741 from aws/jasdel/cust/IMDSClient
Add EC2 IMDS API client and credentials provider
- Loading branch information
Showing
510 changed files
with
6,253 additions
and
4,096 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
Package config provides utilities for loading configuration from multiple | ||
sources that can be used to configure the SDK's API clients, and utilities. | ||
The config package will load configuration from environment variables, AWS | ||
shared configuration file (~/.aws/config), and AWS shared credentials file | ||
(~/.aws/credentials). | ||
Use the LoadDefaultConfig to load configuration from all the SDK's supported | ||
sources, and resolve credentials using the SDK's default credential chain. | ||
* TODO Additional documentation needed. | ||
*/ | ||
package config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
github.com/awslabs/smithy-go v0.0.0-20200914213924-b41e7bef5d4f h1:+ORlmI9IRG6Z/MDqHZfIgz/JvRWDVjUKS8FL/XXA1vc= | ||
github.com/awslabs/smithy-go v0.0.0-20200914213924-b41e7bef5d4f/go.mod h1:hPOQwnmBLHsUphH13tVSjQhTAFma0/0XoZGbBcOuABI= | ||
github.com/aws/aws-sdk-go-v2/service/sts v0.0.0-20200922201841-db749849ec30/go.mod h1:eBfZQDyojdkQZeXOPY3mgfCpUgbZCn8yg8WCx58vyLw= | ||
github.com/awslabs/smithy-go v0.0.0-20200917082847-627658712072/go.mod h1:hPOQwnmBLHsUphH13tVSjQhTAFma0/0XoZGbBcOuABI= | ||
github.com/awslabs/smithy-go v0.0.0-20200922192056-dab44aa99759 h1:jgGfVJaeAs+VN7pdR0YGvJhSUwHetVfGcisKwx6q4pU= | ||
github.com/awslabs/smithy-go v0.0.0-20200922192056-dab44aa99759/go.mod h1:hPOQwnmBLHsUphH13tVSjQhTAFma0/0XoZGbBcOuABI= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/google/go-cmp v0.4.1 h1:/exdXoGamhu5ONeUJH0deniYLWYvQwW66yvlfiiKTu0= | ||
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= | ||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= | ||
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Package ec2rolecreds provides the credentials provider implementation for | ||
retrieving AWS credentials from Amazon EC2 Instance Roles via Amazon EC2 IMDS. | ||
Concurrency and caching | ||
The Provider is not safe to be used concurrently, and does not provide any | ||
caching of credentials retrieved. You should wrap the Provider with a | ||
`aws.CredentialsCache` to provide concurrency safety, and caching of | ||
credentials. | ||
Loading credentials with the SDK's AWS Config | ||
The EC2 Instance role credentials provider will automatically be the resolved | ||
credential provider int he credential chain if no other credential provider is | ||
resolved first. | ||
To explicitly instruct the SDK's credentials resolving to use the EC2 Instance | ||
role for credentials, you specify a `credentials_source` property in the config | ||
profile the SDK will load. | ||
[default] | ||
credential_source = Ec2InstanceMetadata | ||
Loading credentials with the Provider directly | ||
Another way to use the EC2 Instance role credentials provider is to create it | ||
directly and assign it as the credentials provider for an API client. | ||
The following example creates a credentials provider for a command, and wraps | ||
it with the CredentialsCache before assigning the provider to the Amazon S3 API | ||
client's Credentials option. | ||
provider := ec2imds.New(ec2imds.Options{}) | ||
// Create the service client value configured for credentials. | ||
svc := s3.New(s3.Options{ | ||
Credentials: &aws.CredentialsCache{Provider: provider}, | ||
}) | ||
If you need more control, you can set the configuration options on the | ||
credentials provider using the ec2imds.Options type to configure the EC2 IMDS | ||
API Client and ExpiryWindow of the retrieved credentials. | ||
provider := ec2imds.New(ec2imds.Options{ | ||
// See ec2imds.Options type's documentation for more options available. | ||
Client: ec2imds.New(Options{ | ||
HTTPClient: customHTTPClient, | ||
}), | ||
// Modify how soon credentials expire prior to their original expiry time. | ||
ExpiryWindow: 5 * time.Minute, | ||
}) | ||
EC2 IMDS API Client | ||
See the github.com/aws/aws-sdk-go-v2/ec2imds module for more details on | ||
configuring the client, and options available. | ||
*/ | ||
package ec2rolecreds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// +build integration,ec2env | ||
|
||
package ec2rolecreds | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
) | ||
|
||
func TestInteg_RetrieveCredentials(t *testing.T) { | ||
provider := New(Options{}) | ||
|
||
creds, err := provider.Retrieve(context.Background()) | ||
if err != nil { | ||
t.Fatalf("expect no error, got %v", err) | ||
} | ||
|
||
if !creds.HasKeys() { | ||
t.Errorf("expect credential values, got none") | ||
} | ||
|
||
t.Logf("AccessKey: %v", creds.AccessKeyID) | ||
} |
Oops, something went wrong.