forked from aws-observability/aws-otel-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support rotating credentials in newsigv4
This adds an additional feature set to a fork of the sigv4 extension. An explicit configuration option can define a shared credential file location and profile name, this file will be watched for changes and propogate the fresh credentials to upstream consumers. Where possible the AWS SDK machinery has been leveraged to maintain best compatibility with other AWS toolchains. The change should maintain backwards compatibility with the existing sigv4 extension, and both should be interchangable for uses requiring static credentials or sts credentials. Closes rocketsciencegg/aws-gamelift#174
- Loading branch information
Showing
9 changed files
with
192 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package newsigv4 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
) | ||
|
||
type sharedCredentialsProvider struct { | ||
sfile string | ||
profile string | ||
} | ||
|
||
// Retrieve returns fresh credentials from the given shared | ||
// credentials file. | ||
func (s *sharedCredentialsProvider) Retrieve(ctx context.Context) (aws.Credentials, error) { | ||
sharedcfg, err := config.LoadSharedConfigProfile(ctx, s.profile, func(opts *config.LoadSharedConfigOptions) { | ||
opts.CredentialsFiles = []string{s.sfile} | ||
}) | ||
if err != nil { | ||
return aws.Credentials{}, err | ||
} | ||
|
||
return sharedcfg.Credentials, nil | ||
} |
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,38 @@ | ||
package newsigv4 | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSharedCredentialsProvider_Retrieve(t *testing.T) { | ||
t.Run("Retrieve valid credentials from a temp file", func(t *testing.T) { | ||
tmpFile, err := os.CreateTemp("", "shared-credentials") | ||
require.NoError(t, err) | ||
defer os.Remove(tmpFile.Name()) | ||
|
||
sampleProfile := `[default] | ||
aws_access_key_id = TEST_ACCESS_KEY | ||
aws_secret_access_key = TEST_SECRET_KEY | ||
` | ||
_, err = tmpFile.WriteString(sampleProfile) | ||
require.NoError(t, err) | ||
|
||
// Close the file so the provider can read it properly. | ||
err = tmpFile.Close() | ||
require.NoError(t, err) | ||
|
||
provider := &sharedCredentialsProvider{ | ||
profile: "default", | ||
sfile: tmpFile.Name(), | ||
} | ||
creds, err := provider.Retrieve(context.Background()) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, creds.AccessKeyID, "TEST_ACCESS_KEY") | ||
require.Equal(t, creds.SecretAccessKey, "TEST_SECRET_KEY") | ||
}) | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,8 +1,11 @@ | ||
sigv4auth: | ||
newsigv4: | ||
region: "region" | ||
service: "service" | ||
assume_role: | ||
session_name: "role_session_name" | ||
sigv4auth/missing_credentials: | ||
shared_credentials_watcher: | ||
file_location: "/local/credentials/credentials" | ||
profile_name: "default" | ||
newsigv4/missing_credentials: | ||
region: "region" | ||
service: "service" |
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