* fix(storage): Storage Assume Role Support This commit introduces fixes to enable operators to use AWS dynamic credentials on the storage side of this plugin, namely validation, improved credential lifecycle management to allow for storage buckets to be updated from static to dynamic credentials and vice versa, and a new way to determine credential types. It also introduces new tests for dynamic credential usage for the various functions. * fix(storage): Static rotated creds being deleted on plugin err On Storage Bucket update, when we determine if the credentials are to be updated to new ones, we call `credState.ReplaceCreds`. This call, if the old credentials were managed by us (rotated at create time), will delete the old credentials and set the new ones onto credState. We called this function without validating if the incoming credentials are valid. This could get the bucket in a state where where, while we'd return an update error if the incoming credentials weren't working with S3 (err in the dry run process that happens at the end of the update), we'd also silently delete the old credentials the bucket used, rendering the bucket completely broken. --------- Co-authored-by: Hugo <hugoamvieira@users.noreply.github.com>
40 lines
958 B
Go
40 lines
958 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package host
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/boundary-plugin-aws/internal/credential"
|
|
"github.com/hashicorp/go-secure-stdlib/awsutil/v2"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAwsCatalogPersistedStateEC2Client(t *testing.T) {
|
|
require := require.New(t)
|
|
cred, err := credential.NewAwsCredentialPersistedState(
|
|
credential.WithCredentialsConfig(&awsutil.CredentialsConfig{
|
|
Region: "us-west-2",
|
|
AccessKey: "foobar",
|
|
SecretKey: "barfoo",
|
|
}),
|
|
)
|
|
require.NoError(err)
|
|
|
|
state, err := newAwsCatalogPersistedState(
|
|
withCredentials(cred),
|
|
withTestEC2APIFunc(newTestMockEC2(nil)),
|
|
)
|
|
require.NoError(err)
|
|
|
|
clientRaw, err := state.EC2Client(context.Background())
|
|
require.NoError(err)
|
|
require.NotNil(clientRaw)
|
|
client, ok := clientRaw.(*testMockEC2)
|
|
require.True(ok)
|
|
require.NotNil(client)
|
|
require.Equal("us-west-2", client.Region)
|
|
}
|