Interim vkv plugin push

This commit is contained in:
Jeff Mitchell 2018-04-03 14:34:36 -04:00
parent 6b840e6c1c
commit 9d16593f48
8 changed files with 129 additions and 106 deletions

View file

@ -99,12 +99,6 @@
]
revision = "0fb14efe8c47ae851c0034ed7a448854d3d34cf3"
[[projects]]
branch = "master"
name = "github.com/hashicorp/golang-math-big"
packages = ["big"]
revision = "561262b71329a2a771294d66accacab6b598b37b"
[[projects]]
branch = "master"
name = "github.com/hashicorp/hcl"
@ -122,7 +116,7 @@
revision = "f40e974e75af4e271d97ce0fc917af5898ae7bda"
[[projects]]
branch = "0.10-beta"
branch = "master"
name = "github.com/hashicorp/vault"
packages = [
"api",
@ -134,8 +128,7 @@
"helper/kdf",
"helper/keysutil",
"helper/locksutil",
"helper/logbridge",
"helper/logformat",
"helper/logging",
"helper/mlock",
"helper/parseutil",
"helper/pluginutil",
@ -150,7 +143,7 @@
"physical/inmem",
"version"
]
revision = "44aa151b78976c6da41dc63d93b40d2070b23277"
revision = "205c40489422f350b58e3d57b242fe8e6e36134a"
[[projects]]
branch = "master"
@ -158,30 +151,6 @@
packages = ["."]
revision = "2658be15c5f05e76244154714161f17e3e77de2e"
[[projects]]
name = "github.com/mattn/go-colorable"
packages = ["."]
revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
version = "v0.0.9"
[[projects]]
name = "github.com/mattn/go-isatty"
packages = ["."]
revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
version = "v0.0.3"
[[projects]]
branch = "master"
name = "github.com/mgutz/ansi"
packages = ["."]
revision = "9520e82c474b0a04dd04f8a40959027271bab992"
[[projects]]
name = "github.com/mgutz/logxi"
packages = ["v1"]
revision = "aebf8a7d67ab4625e0fd4a665766fef9a709161b"
version = "v1"
[[projects]]
branch = "master"
name = "github.com/mitchellh/go-homedir"
@ -313,6 +282,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "591b8e75e4f2b6f6f2ea3ae177e4947e604378404813fa5046c7d3b47c3fb05c"
inputs-digest = "b931a497c04b2b7fccc2f3962172d83debc80221239075635e829449f433fdd0"
solver-name = "gps-cdcl"
solver-version = 1

View file

@ -26,12 +26,5 @@
[[constraint]]
name = "github.com/hashicorp/vault"
branch = "0.10-beta"
branch = "master"
[[constraint]]
name = "github.com/mgutz/logxi"
version = "1.0.0"
[[override]]
name = "github.com/golang/go"
version = "go1.10"

View file

@ -45,5 +45,7 @@ fmtcheck:
fmt:
gofmt -w $(GOFMT_FILES)
proto:
protoc *.proto --go_out=plugins=grpc:.
.PHONY: bin default generate test vet bootstrap fmt fmtcheck

View file

@ -125,7 +125,20 @@ func VersionedKVFactory(ctx context.Context, conf *logical.BackendConfig) (logic
return nil, err
}
if _, ok := conf.Config["upgrade"]; ok {
upgradeEntry, err := conf.StorageView.Get(ctx, path.Join(b.storagePrefix, "upgrading"))
if err != nil {
return nil, err
}
var upgradeInfo UpgradeInfo
if upgradeEntry != nil {
err := proto.Unmarshal(upgradeEntry.Value, &upgradeInfo)
if err != nil {
return nil, err
}
}
if !upgradeInfo.Done {
err := b.Upgrade(ctx, conf.StorageView)
if err != nil {
return nil, err

View file

@ -220,6 +220,9 @@ func (m *Version) GetDeletionTime() *google_protobuf.Timestamp {
type UpgradeInfo struct {
// Started time is when the upgrade was started.
StartedTime *google_protobuf.Timestamp `protobuf:"bytes,1,opt,name=started_time,json=startedTime" json:"started_time,omitempty"`
// done is set to true once the backend has been successfully
// upgraded.
Done bool `protobuf:"varint,2,opt,name=done" json:"done,omitempty"`
}
func (m *UpgradeInfo) Reset() { *m = UpgradeInfo{} }
@ -234,6 +237,13 @@ func (m *UpgradeInfo) GetStartedTime() *google_protobuf.Timestamp {
return nil
}
func (m *UpgradeInfo) GetDone() bool {
if m != nil {
return m.Done
}
return false
}
func init() {
proto.RegisterType((*Configuration)(nil), "kv.Configuration")
proto.RegisterType((*VersionMetadata)(nil), "kv.VersionMetadata")
@ -245,32 +255,33 @@ func init() {
func init() { proto.RegisterFile("types.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 428 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x93, 0xdf, 0x8a, 0xd3, 0x40,
0x18, 0xc5, 0xc9, 0x9f, 0xdd, 0xed, 0x7e, 0x93, 0xec, 0xca, 0x78, 0x53, 0x8a, 0x62, 0x0d, 0x88,
0xf5, 0x26, 0x0b, 0xeb, 0x8d, 0x0a, 0x8b, 0x17, 0xe2, 0x85, 0xa8, 0x20, 0x83, 0xeb, 0x6d, 0x99,
0xed, 0x7c, 0x2d, 0xa1, 0x6d, 0x26, 0xce, 0x4c, 0xca, 0xe6, 0x61, 0x7c, 0x06, 0x5f, 0xc1, 0x47,
0x93, 0x99, 0xcc, 0x74, 0xd7, 0x2a, 0x94, 0xe2, 0x5d, 0x38, 0xf9, 0x9d, 0x8f, 0xc3, 0xc9, 0x09,
0x10, 0xd3, 0x35, 0xa8, 0xcb, 0x46, 0x49, 0x23, 0x69, 0xbc, 0xdc, 0x8c, 0x9e, 0x2c, 0xa4, 0x5c,
0xac, 0xf0, 0xc2, 0x29, 0x37, 0xed, 0xfc, 0xc2, 0x54, 0x6b, 0xd4, 0x86, 0xaf, 0x9b, 0x1e, 0x2a,
0xae, 0x21, 0x7f, 0x27, 0xeb, 0x79, 0xb5, 0x68, 0x15, 0x37, 0x95, 0xac, 0xe9, 0x53, 0xc8, 0xd6,
0xfc, 0x76, 0xba, 0x41, 0xa5, 0x2b, 0x59, 0xeb, 0x61, 0x34, 0x8e, 0x26, 0x39, 0x23, 0x6b, 0x7e,
0xfb, 0xcd, 0x4b, 0x16, 0x99, 0x71, 0x3d, 0x55, 0xf8, 0xbd, 0xad, 0x14, 0x8a, 0x61, 0x3c, 0x8e,
0x26, 0x03, 0x46, 0x66, 0x5c, 0x33, 0x2f, 0x15, 0x3f, 0x23, 0x38, 0xf7, 0xfc, 0x67, 0x34, 0x5c,
0x70, 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27, 0xde, 0xc4, 0xaf, 0xa2, 0xe2, 0x47, 0x04,
0x27, 0xa1, 0x21, 0x0a, 0xa9, 0x7d, 0xed, 0xae, 0x65, 0x2c, 0xfd, 0xe7, 0x00, 0xe3, 0xff, 0x1c,
0x60, 0x72, 0xd8, 0x00, 0x8b, 0x4f, 0x40, 0xae, 0x9b, 0x85, 0xe2, 0x02, 0x3f, 0xd4, 0x73, 0x69,
0xe3, 0x68, 0xc3, 0xd5, 0x21, 0xff, 0x83, 0xe7, 0xad, 0x72, 0x73, 0xec, 0x80, 0x97, 0xbf, 0x03,
0x00, 0x00, 0xff, 0xff, 0x26, 0x20, 0x0a, 0x5c, 0xf4, 0x03, 0x00, 0x00,
// 436 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x93, 0xdf, 0x8a, 0x13, 0x31,
0x18, 0xc5, 0x99, 0x3f, 0xbb, 0xdb, 0xfd, 0x32, 0xb3, 0x2b, 0xf1, 0xa6, 0x14, 0xc5, 0x3a, 0x20,
0xd6, 0x9b, 0x59, 0x58, 0x6f, 0x54, 0x58, 0xbc, 0x10, 0x2f, 0x44, 0x04, 0x09, 0xae, 0xb7, 0x35,
0xdb, 0x7c, 0x2d, 0x43, 0xdb, 0xc9, 0x98, 0x64, 0xca, 0xce, 0xc3, 0xf8, 0x0c, 0xbe, 0x82, 0x8f,
0x26, 0xc9, 0x24, 0xdd, 0xb5, 0x0a, 0xa5, 0x78, 0x17, 0x4e, 0xcf, 0x09, 0xbf, 0x9e, 0x39, 0x01,
0x62, 0xba, 0x06, 0x75, 0xd9, 0x28, 0x69, 0x24, 0x8d, 0x97, 0x9b, 0xd1, 0x93, 0x85, 0x94, 0x8b,
0x15, 0x5e, 0x38, 0xe5, 0xa6, 0x9d, 0x5f, 0x98, 0x6a, 0x8d, 0xda, 0xf0, 0x75, 0xd3, 0x9b, 0x8a,
0x6b, 0xc8, 0xdf, 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, 0x6d, 0x7d, 0xa9, 0xf3, 0xe5,
0xbd, 0x1a, 0x6c, 0xbb, 0x55, 0x1e, 0x1d, 0x56, 0xe5, 0x15, 0x64, 0x6d, 0x23, 0xee, 0xe2, 0xc7,
0xfb, 0xe3, 0xde, 0xef, 0xe2, 0xbb, 0x13, 0x39, 0xd9, 0x3f, 0x91, 0xc1, 0x5f, 0x13, 0x19, 0x7d,
0x86, 0xfc, 0x8f, 0xba, 0xee, 0x37, 0x9e, 0xf6, 0x8d, 0xbf, 0x80, 0xa3, 0x0d, 0x5f, 0xb5, 0xe1,
0x53, 0x3f, 0xb4, 0x75, 0xef, 0xac, 0x8a, 0xf5, 0x8e, 0x37, 0xf1, 0xab, 0xa8, 0xf8, 0x11, 0xc1,
0x49, 0x68, 0x88, 0x42, 0x6a, 0x7f, 0x76, 0xb7, 0x65, 0x2c, 0xfd, 0xe7, 0x00, 0xe3, 0xff, 0x1c,
0x60, 0x72, 0xd8, 0x00, 0x8b, 0x6f, 0x40, 0xae, 0x9b, 0x85, 0xe2, 0x02, 0x3f, 0xd4, 0x73, 0x69,
0x71, 0xb4, 0xe1, 0xea, 0x90, 0xf7, 0xe0, 0xfd, 0x0e, 0xc7, 0xfe, 0x43, 0x59, 0xa3, 0x7f, 0x7d,
0xee, 0x7c, 0x73, 0xec, 0x42, 0x2f, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0xa2, 0xd2, 0xb5, 0x3c,
0x08, 0x04, 0x00, 0x00,
}

View file

@ -71,6 +71,10 @@ message Version {
message UpgradeInfo {
// Started time is when the upgrade was started.
google.protobuf.Timestamp started_time = 1;
// done is set to true once the backend has been successfully
// upgraded.
bool done = 2;
}

View file

@ -7,11 +7,13 @@ import (
"path"
"strings"
"sync/atomic"
"time"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"github.com/hashicorp/vault/helper/consts"
"github.com/hashicorp/vault/helper/locksutil"
"github.com/hashicorp/vault/helper/pluginutil"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
@ -28,7 +30,12 @@ func (b *versionedKVBackend) upgradeCheck(next framework.OperationFunc) framewor
func (b *versionedKVBackend) Upgrade(ctx context.Context, s logical.Storage) error {
if !b.System().LocalMount() && b.System().ReplicationState().HasState(consts.ReplicationPerformanceSecondary) {
b.Logger().Info("versioned k/v: upgrade not running on performace replication secondary")
b.Logger().Info("upgrade not running on performace replication secondary")
return nil
}
if pluginutil.InMetadataMode() {
b.Logger().Info("upgrade not running while plugin is in metadata mode")
return nil
}
@ -36,21 +43,17 @@ func (b *versionedKVBackend) Upgrade(ctx context.Context, s logical.Storage) err
return errors.New("upgrade already in process")
}
// Write upgrade canary
info, err := proto.Marshal(&UpgradeInfo{
upgradeInfo := &UpgradeInfo{
StartedTime: ptypes.TimestampNow(),
})
}
// Encode the canary
info, err := proto.Marshal(upgradeInfo)
if err != nil {
return err
}
err = s.Put(ctx, &logical.StorageEntry{
Key: path.Join(b.storagePrefix, "upgrading"),
Value: info,
})
if err != nil {
return err
}
ctx = context.Background()
upgradeKey := func(key string) error {
if strings.HasPrefix(key, b.storagePrefix) {
@ -114,35 +117,63 @@ func (b *versionedKVBackend) Upgrade(ctx context.Context, s logical.Storage) err
// potentially long process.
go func() {
b.Logger().Info("versioned k/v: collecting keys")
keys, err := logical.CollectKeys(ctx, s)
if err != nil {
b.Logger().Error("versioned k/v: upgrading resulted in error", "error", err)
return
}
b.Logger().Info("versioned k/v: done collecting keys", "num_keys", len(keys))
for i, key := range keys {
if b.Logger().IsTrace() && i%500 == 0 {
b.Logger().Trace("versioned k/v: upgrading keys", "progress", fmt.Sprintf("%d/%d", i, len(keys)))
}
err := upgradeKey(key)
if err != nil {
b.Logger().Error("versioned k/v: upgrading resulted in error", "error", err, "progress", fmt.Sprintf("%d/%d", i+1, len(keys)))
// Write the canary value and if we are read only wait until the setup
// process has finished.
READONLY_LOOP:
for {
err = s.Put(ctx, &logical.StorageEntry{
Key: path.Join(b.storagePrefix, "upgrading"),
Value: info,
})
switch {
case err == nil:
break READONLY_LOOP
case err.Error() == logical.ErrSetupReadOnly.Error():
time.Sleep(time.Second)
default:
b.Logger().Error("writing upgrade info resulted in an error", "error", err)
return
}
}
b.Logger().Info("versioned k/v: upgrading keys finished")
// Remove the upgrading canary
err = s.Delete(ctx, path.Join(b.storagePrefix, "upgrading"))
b.Logger().Info("collecting keys to upgrade")
keys, err := logical.CollectKeys(ctx, s)
if err != nil {
b.Logger().Error("versioned k/v: removing upgrade canary resulted in an error", "error", err)
b.Logger().Error("upgrading resulted in error", "error", err)
return
}
b.Logger().Info("done collecting keys", "num_keys", len(keys))
for i, key := range keys {
if b.Logger().IsDebug() && i%500 == 0 {
b.Logger().Debug("upgrading keys", "progress", fmt.Sprintf("%d/%d", i, len(keys)))
}
err := upgradeKey(key)
if err != nil {
b.Logger().Error("upgrading resulted in error", "error", err, "progress", fmt.Sprintf("%d/%d", i+1, len(keys)))
return
}
}
b.Logger().Info("upgrading keys finished")
// Write upgrade done value
upgradeInfo.Done = true
info, err := proto.Marshal(upgradeInfo)
if err != nil {
b.Logger().Error("encoding upgrade info resulted in an error", "error", err)
}
err = s.Put(ctx, &logical.StorageEntry{
Key: path.Join(b.storagePrefix, "upgrading"),
Value: info,
})
if err != nil {
b.Logger().Error("writing upgrade done resulted in an error", "error", err)
}
atomic.StoreUint32(b.upgrading, 0)
}()
return nil
}

6
vendor/vendor.json vendored
View file

@ -1327,10 +1327,10 @@
"revisionTime": "2018-03-21T19:18:39Z"
},
{
"checksumSHA1": "ZYuIUFGjAZ2rgy/zwdjfANFZc/U=",
"checksumSHA1": "8F+gyqMRQP4VAnf3x9AgYY7WvYM=",
"path": "github.com/hashicorp/vault-plugin-secrets-kv",
"revision": "76db4647de517c512e7f87b78c1afc84acf97918",
"revisionTime": "2018-03-22T02:53:20Z"
"revision": "99cddef3c472f5651339380aadaa050d21cd5e56",
"revisionTime": "2018-04-03T18:11:23Z"
},
{
"checksumSHA1": "vTfeYxi0Z1y176bjQaYh1/FpQ9s=",