-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Cache whether we've been initialized to reduce load on storage #7549
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ require ( | |
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 // indirect | ||
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e | ||
golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db // indirect | ||
google.golang.org/appengine v1.4.0 // indirect | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here |
||
google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107 // indirect | ||
google.golang.org/grpc v1.22.0 | ||
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,13 @@ import ( | |
"sync" | ||
"time" | ||
|
||
metrics "github.com/armon/go-metrics" | ||
"github.com/armon/go-metrics" | ||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/vault/sdk/helper/jsonutil" | ||
"github.com/hashicorp/vault/sdk/helper/strutil" | ||
"github.com/hashicorp/vault/sdk/logical" | ||
"github.com/hashicorp/vault/sdk/physical" | ||
"go.uber.org/atomic" | ||
) | ||
|
||
const ( | ||
|
@@ -69,6 +70,8 @@ type AESGCMBarrier struct { | |
// future versioning of barrier implementations. It's var instead | ||
// of const to allow for testing | ||
currentAESGCMVersionByte byte | ||
|
||
initialized atomic.Bool | ||
} | ||
|
||
// NewAESGCMBarrier is used to construct a new barrier that uses | ||
|
@@ -86,12 +89,17 @@ func NewAESGCMBarrier(physical physical.Backend) (*AESGCMBarrier, error) { | |
// Initialized checks if the barrier has been initialized | ||
// and has a master key set. | ||
func (b *AESGCMBarrier) Initialized(ctx context.Context) (bool, error) { | ||
if b.initialized.Load() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see why using Uber's atomic package is convenient here since we want to return bool, but I wonder if we could simply use the stdlib's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was Jeff's suggestion. He likes the API the library provides and thought this would be a convenient occasion to give it a try. I concurred. |
||
return true, nil | ||
} | ||
|
||
// Read the keyring file | ||
keys, err := b.backend.List(ctx, keyringPrefix) | ||
if err != nil { | ||
return false, errwrap.Wrapf("failed to check for initialization: {{err}}", err) | ||
} | ||
if strutil.StrListContains(keys, "keyring") { | ||
b.initialized.Store(true) | ||
return true, nil | ||
} | ||
|
||
|
@@ -100,6 +108,7 @@ func (b *AESGCMBarrier) Initialized(ctx context.Context) (bool, error) { | |
if err != nil { | ||
return false, errwrap.Wrapf("failed to check for initialization: {{err}}", err) | ||
} | ||
b.initialized.Store(out != nil) | ||
return out != nil, nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please go mod tidy. This is really annoying because for some reason right now this keeps getting added on build and removed on go mod tidy. (Are you on go 1.12.10? I only noticed it after upgrading to that, although it may be unrelated.) However, for the moment we're not committing build-time only changes since it'll be pulled right back out on the next tidy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My IDE (goland) also auto-adds it back, very annoying I agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try merging in master, it should be fixed (I no longer get on my diffs).