codahale / sneaker

A tool for securely storing secrets on S3 using Amazon KMS.
Other
800 stars 34 forks source link

sneaker ls with panic: runtime error: invalid memory address or nil pointer dereference #16

Closed snowman65de closed 8 years ago

snowman65de commented 8 years ago

I have sneaker 1.6 installed in a docker container:

sneaker version version: 3e52e64 goversion: go version go1.6 linux/amd64 buildtime: 2016-05-26T17:50:18Z

with sneaker ls I get: panic: runtime error: invalid memory address or nil pointer dereference [signal 0xb code=0x1 addr=0x20 pc=0x4d6682]

goroutine 1 [running]: panic(0x8bbba0, 0xc82000e090) /usr/local/go/src/runtime/panic.go:464 +0x3e6 github.com/aws/aws-sdk-go/service/s3.New(0x0, 0x0, 0x0, 0x0, 0x0, 0x0) /robotron/aws/go/src/github.com/codahale/sneaker/Godeps/_workspace/src/github.com/aws/aws-sdk-go/service/s3/service.go:41 +0x72 main.loadManager(0x7ea160) /robotron/aws/go/src/github.com/codahale/sneaker/cmd/sneaker/main.go:222 +0x329 main.main() /robotron/aws/go/src/github.com/codahale/sneaker/cmd/sneaker/main.go:55 +0x455


Tried to figure out the problem. Found the following hint in the aws-sdk-go/s3/session Info: https://github.com/aws/aws-sdk-go/commit/1a69d069352edadd48f12b0f2c5f375de4a636d7

"...Migrating to this change you'll need to add a session.Session to your application. The session will be used in each place a service client is created. Naively this can be s3.New(session.New()) instead of the previous s3.New(nil)...."_

In order to fix it I had to make the following changes: 1.) in cmd/main.go I added: import: "github.com/aws/aws-sdk-go/aws/session"

in loadManager I changed return in s3.New and kms.New to: nil -> session.New()

        return &sneaker.Manager{
                Objects: s3.New(session.New()),
                Envelope: sneaker.Envelope{
                        KMS: kms.New(session.New()),
                },
                Bucket:            u.Host,
                Prefix:            u.Path,
                EncryptionContext: ctxt,
                KeyId:             os.Getenv("SNEAKER_MASTER_KEY"),

2.) Provide AWS_REGION environment variable in addition to AWS_DEFAULT_REGION. - I think/hope that can be avoided calling proper aws-sdk-go api calls

Please check this out.

dskyberg commented 8 years ago

@snowman65de, thanks for the fix. This fixed the problem for me as well. This should be a PR.

codahale commented 8 years ago

I would accept a PR for this.