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

Panic when using secretcache with an incomplete config #12

Open
merschformann opened this issue Oct 18, 2022 · 1 comment
Open

Panic when using secretcache with an incomplete config #12

merschformann opened this issue Oct 18, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@merschformann
Copy link

merschformann commented Oct 18, 2022

Describe the bug

When using secretcache with an incomplete config (not setting all fields) it results in a panic on secrets.GetSecretString.
I.e., the following code panicks:

config := secretcache.CacheConfig{
	// Uncomment the defaults below to make the example work again
	// MaxCacheSize: secretcache.DefaultMaxCacheSize,
	// VersionStage: secretcache.DefaultVersionStage,
	CacheItemTTL: 30 * 1000 * 1000 * 1000,
}
secrets, err := secretcache.New(
	func(c *secretcache.Cache) { c.CacheConfig = config },
)
if err != nil {
	panic(fmt.Errorf("error creating secret cache: %w", err))
}
secrets.GetSecretString("foo")

Find a minimal working example also here: https://github.com/merschformann/aws-secrets-manager-panic

Expected Behavior

Expected to receive an error from either secretcache.New for an incomplete configuration or cache.GetSecretString for an invalid secret ID. It should not panic.

Current Behavior

The example panics due to a nil pointer dereference.
This is the output:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x72bb7d]

goroutine 1 [running]:
github.com/aws/aws-secretsmanager-caching-go/secretcache.(*secretCacheItem).getSecretValue(0x0, {0x7b976e?, 0x3?})
        github.com/aws/[email protected]/secretcache/cacheItem.go:168 +0x9d
github.com/aws/aws-secretsmanager-caching-go/secretcache.(*Cache).GetSecretStringWithStage(0xc00018fef0?, {0x7b76e4?, 0x43cec5?}, {0x7b976e, 0xa})
        github.com/aws/[email protected]/secretcache/cache.go:94 +0x3b
github.com/aws/aws-secretsmanager-caching-go/secretcache.(*Cache).GetSecretString(...)
        github.com/aws/[email protected]/secretcache/cache.go:86
main.main()
        aws-secrets-manager-panic/main.go:22 +0xdd
exit status 2

Reproduction Steps

Just run the minimal example here (go run main.go) or copy above code to a file and run it.

Possible Solution

If there are assumptions about the config (e.g.: MaxCacheSize > 0), they may be checked on secretcache.New. A descriptive error could be returned, if something is not met.

Version used

v1.1.0

Environment details (Version of Go (go version)? OS name and version, etc.)

go version go1.19.1 linux/amd64

@jbct
Copy link

jbct commented Oct 24, 2022

Thank you for reporting the issue. We are looking into it.

@simonmarty simonmarty added the bug Something isn't working label Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants