Add path attributes to indicate when operations should forward (#7175)

This commit is contained in:
Jim Kalafut
2020-01-07 14:04:08 -08:00
committed by GitHub
parent b2371195d2
commit 2072ae6928
3 changed files with 134 additions and 14 deletions

View File

@@ -15,7 +15,8 @@ import (
"github.com/hashicorp/errwrap"
log "github.com/hashicorp/go-hclog"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/vault/sdk/helper/consts"
"github.com/hashicorp/vault/sdk/helper/entropy"
"github.com/hashicorp/vault/sdk/helper/errutil"
"github.com/hashicorp/vault/sdk/helper/license"
@@ -225,6 +226,19 @@ func (b *Backend) HandleRequest(ctx context.Context, req *logical.Request) (*log
if path.Operations != nil {
if op, ok := path.Operations[req.Operation]; ok {
// Check whether this operation should be forwarded
replState := b.System().ReplicationState()
props := op.Properties()
if props.ForwardPerformanceStandby && replState.HasState(consts.ReplicationPerformanceStandby) {
return nil, logical.ErrReadOnly
}
if props.ForwardPerformanceSecondary && !b.System().LocalMount() && replState.HasState(consts.ReplicationPerformanceSecondary) {
return nil, logical.ErrReadOnly
}
callback = op.Handler()
}
} else {