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

[1.13] Cherrypick: Removes check for dummy key in AWS Secrets manager (#3519) #3521

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e

export INFLUX_TOKEN=$(openssl rand -base64 32)
echo "INFLUX_TOKEN=$INFLUX_TOKEN" >> $GITHUB_ENV
docker-compose -f .github/infrastructure/docker-compose-influxdb.yml -p influxdb up -d
docker compose -f .github/infrastructure/docker-compose-influxdb.yml -p influxdb up -d
2 changes: 1 addition & 1 deletion .github/scripts/components-scripts/docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -e
FILE="$1"
PROJECT="${2:-$FILE}"

docker-compose -f .github/infrastructure/docker-compose-${FILE}.yml -p ${PROJECT} up -d
docker compose -f .github/infrastructure/docker-compose-${FILE}.yml -p ${PROJECT} up -d
25 changes: 1 addition & 24 deletions secretstores/aws/secretmanager/secretmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ package secretmanager
import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"

"github.com/aws/aws-sdk-go/service/secretsmanager"
"github.com/aws/aws-sdk-go/service/secretsmanager/secretsmanageriface"

awsAuth "github.com/dapr/components-contrib/common/authentication/aws"
"github.com/dapr/components-contrib/common/utils"
"github.com/dapr/components-contrib/metadata"
"github.com/dapr/components-contrib/secretstores"
"github.com/dapr/kit/logger"
"github.com/dapr/kit/ptr"
)

const (
Expand Down Expand Up @@ -62,34 +59,14 @@ func (s *smSecretStore) Init(ctx context.Context, metadata secretstores.Metadata
return err
}

// This check is needed because d.client is set to a mock in tests
if s.client == nil {
s.client, err = s.getClient(meta)
if err != nil {
return err
}
}
s.client, err = s.getClient(meta)
if err != nil {
return err
}

var notFoundErr *secretsmanager.ResourceNotFoundException
if err := s.validateConnection(ctx); err != nil && !errors.As(err, &notFoundErr) {
return fmt.Errorf("error validating access to the aws.secretmanager secret store: %w", err)
}
return nil
}

// validateConnection runs a dummy GetSecretValueWithContext operation
// to validate the connection credentials
func (s *smSecretStore) validateConnection(ctx context.Context) error {
_, err := s.client.GetSecretValueWithContext(ctx, &secretsmanager.GetSecretValueInput{
SecretId: ptr.Of(utils.GetRandOrDefaultString("dapr-test-secret")),
})

return err
}

// GetSecret retrieves a secret using a key and returns a map of decrypted string/string values.
func (s *smSecretStore) GetSecret(ctx context.Context, req secretstores.GetSecretRequest) (secretstores.GetSecretResponse, error) {
var versionID *string
Expand Down
19 changes: 0 additions & 19 deletions secretstores/aws/secretmanager/secretmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ func (m *mockedSM) GetSecretValueWithContext(ctx context.Context, input *secrets
func TestInit(t *testing.T) {
m := secretstores.Metadata{}
s := NewSecretManager(logger.NewLogger("test"))
s.(*smSecretStore).client = &mockedSM{
GetSecretValueFn: func(ctx context.Context, input *secretsmanager.GetSecretValueInput, option ...request.Option) (*secretsmanager.GetSecretValueOutput, error) {
// Simulate a non error response
return nil, nil
},
}

t.Run("Init with valid metadata", func(t *testing.T) {
m.Properties = map[string]string{
Expand All @@ -61,19 +55,6 @@ func TestInit(t *testing.T) {
err := s.Init(context.Background(), m)
require.NoError(t, err)
})

t.Run("Init with invalid connection details", func(t *testing.T) {
s.(*smSecretStore).client = &mockedSM{
GetSecretValueFn: func(ctx context.Context, input *secretsmanager.GetSecretValueInput, option ...request.Option) (*secretsmanager.GetSecretValueOutput, error) {
// Simulate a failure that resembles what AWS SM would return
return nil, fmt.Errorf("wrong-credentials")
},
}

err := s.Init(context.Background(), m)
require.Error(t, err)
require.EqualError(t, err, "error validating access to the aws.secretmanager secret store: wrong-credentials")
})
}

func TestGetSecret(t *testing.T) {
Expand Down
12 changes: 8 additions & 4 deletions tests/certification/flow/dockercompose/dockercompose.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func Up(project, filename string) flow.Runnable {

func (c Compose) Up(ctx flow.Context) error {
out, err := exec.Command(
"docker-compose",
"docker",
"compose",
"-p", c.project,
"-f", c.filename,
"up", "-d",
Expand All @@ -65,7 +66,8 @@ func Down(project, filename string) flow.Runnable {

func (c Compose) Down(ctx flow.Context) error {
out, err := exec.Command(
"docker-compose",
"docker",
"compose",
"-p", c.project,
"-f", c.filename,
"down", "-v").CombinedOutput()
Expand All @@ -81,12 +83,13 @@ func Start(project, filename string, services ...string) flow.Runnable {
func (c Compose) Start(services ...string) flow.Runnable {
return func(ctx flow.Context) error {
args := []string{
"compose",
"-p", c.project,
"-f", c.filename,
"start",
}
args = append(args, services...)
out, err := exec.Command("docker-compose", args...).CombinedOutput()
out, err := exec.Command("docker", args...).CombinedOutput()
ctx.Log(string(out))
return err
}
Expand All @@ -99,12 +102,13 @@ func Stop(project, filename string, services ...string) flow.Runnable {
func (c Compose) Stop(services ...string) flow.Runnable {
return func(ctx flow.Context) error {
args := []string{
"compose",
"-p", c.project,
"-f", c.filename,
"stop",
}
args = append(args, services...)
out, err := exec.Command("docker-compose", args...).CombinedOutput()
out, err := exec.Command("docker", args...).CombinedOutput()
ctx.Log(string(out))
return err
}
Expand Down
5 changes: 3 additions & 2 deletions tests/certification/pubsub/pulsar/pulsar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/dapr/dapr/pkg/config/protocol"

"github.com/apache/pulsar-client-go/pulsar"

"github.com/dapr/dapr/pkg/runtime"
dapr "github.com/dapr/go-sdk/client"
"github.com/dapr/go-sdk/service/common"
Expand Down Expand Up @@ -123,7 +124,7 @@ func TestPulsar(t *testing.T) {

t.Log("Starting OAuth2 server...")
out, err := exec.Command(
"docker-compose",
"docker", "compose",
"-p", "oauth2",
"-f", dockerComposeMockOAuth2YAML,
"up", "-d").CombinedOutput()
Expand All @@ -133,7 +134,7 @@ func TestPulsar(t *testing.T) {
t.Cleanup(func() {
t.Log("Stopping OAuth2 server...")
out, err = exec.Command(
"docker-compose",
"docker", "compose",
"-p", "oauth2",
"-f", dockerComposeMockOAuth2YAML,
"down", "-v",
Expand Down
Loading