Skip to content

bug: secret manager always returning base64 encoded string even in GoSDK #11319

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

Closed
1 task done
MathiasVandePol opened this issue Aug 6, 2024 · 3 comments
Closed
1 task done
Labels
area: integration/aws-sdk-go Issues related to AWS Golang SDK aws:secretsmanager AWS Secrets Manager type: bug Bug report

Comments

@MathiasVandePol
Copy link

MathiasVandePol commented Aug 6, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When using the Go aws SDK, It seems that localstack somehow always returns a base64 encoded secretBinary even though this should not happen for the GoSDK (and others besides Python?)

https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html#API_GetSecretValue_ResponseSyntax

The decrypted secret value, if the secret value was originally provided as binary data in the form of a byte array. When you retrieve a SecretBinary using the HTTP API, the Python SDK, or the AWS CLI, the value is Base64-encoded. Otherwise, it is not encoded.

Expected Behavior

Return a non base64 encoded binary

How are you starting LocalStack?

With a docker-compose file

Steps To Reproduce

Below is some go code that works if the awsEndpoint is not overriden to localstack.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/secretsmanager"
)

func main() {
	// $ touch secrets.json
	// $ cat > secrets.json << EOF
	// {
	//   "username": "admin",
	//   "password": "password"
	// }
	// EOF
	// $ awslocal secretsmanager create-secret --name xxx --secret-binary fileb://secrets.json

	secretName := "xxx"

	awsEndpoint := "http://localhost:4566"
	awsRegion := "us-east-1"

	awsCfg, err := config.LoadDefaultConfig(context.TODO(),
		config.WithRegion(awsRegion),
	)
	if err != nil {
		log.Fatal(err)
	}

	// Create Secrets Manager client
	svc := secretsmanager.NewFromConfig(awsCfg, func(o *secretsmanager.Options) {
		o.BaseEndpoint = aws.String(awsEndpoint)
	})

	input := &secretsmanager.GetSecretValueInput{
		SecretId: aws.String(secretName),
	}

	result, err := svc.GetSecretValue(context.TODO(), input)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s", result.SecretBinary) // This should print the json but it prints a base64 encoded string
}

Environment

- OS:
- LocalStack:
  LocalStack version:
  LocalStack Docker image sha:
  LocalStack build date:
  LocalStack build git hash:

Anything else?

No response

@MathiasVandePol MathiasVandePol added status: triage needed Requires evaluation by maintainers type: bug Bug report labels Aug 6, 2024
@localstack-bot
Copy link
Collaborator

Welcome to LocalStack! Thanks for reporting your first issue and our team will be working towards fixing the issue for you or reach out for more background information. We recommend joining our Slack Community for real-time help and drop a message to LocalStack Pro Support if you are a Pro user! If you are willing to contribute towards fixing this issue, please have a look at our contributing guidelines and our contributing guide.

@MathiasVandePol MathiasVandePol changed the title bug: secret manager always returning base64 bug: secret manager always returning base64 encoded string even in GoSDK Aug 6, 2024
@Anze1508 Anze1508 added aws:secretsmanager AWS Secrets Manager area: integration/aws-sdk-go Issues related to AWS Golang SDK status: backlog Triaged but not yet being worked on and removed status: triage needed Requires evaluation by maintainers labels Aug 7, 2024
@alexrashed
Copy link
Member

Hi @MathiasVandePol!
This issue has been addressed in #11535. Could you please give us some feedback if this resolved your issue?
The fix is containe in the latest release (3.8.1) as well as in the latest images.

@alexrashed alexrashed added status: response required Waiting for a response from the reporter and removed status: backlog Triaged but not yet being worked on labels Oct 30, 2024
@maciejwalkowiak
Copy link

As far as I can tell regression has been fixed - my tests are passing with 3.8.1: awspring/spring-cloud-aws#1217

@localstack-bot localstack-bot removed the status: response required Waiting for a response from the reporter label Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: integration/aws-sdk-go Issues related to AWS Golang SDK aws:secretsmanager AWS Secrets Manager type: bug Bug report
Projects
None yet
Development

No branches or pull requests

5 participants