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

Update framework forwarding logic to handle nil system views #8114

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions sdk/framework/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,17 @@ func (b *Backend) HandleRequest(ctx context.Context, req *logical.Request) (*log
if op, ok := path.Operations[req.Operation]; ok {

// Check whether this operation should be forwarded
replState := b.System().ReplicationState()
props := op.Properties()
if sysView := b.System(); sysView != nil {
replState := sysView.ReplicationState()
props := op.Properties()

if props.ForwardPerformanceStandby && replState.HasState(consts.ReplicationPerformanceStandby) {
return nil, logical.ErrReadOnly
}
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
if props.ForwardPerformanceSecondary && !sysView.LocalMount() && replState.HasState(consts.ReplicationPerformanceSecondary) {
return nil, logical.ErrReadOnly
}
}

callback = op.Handler()
Expand Down
9 changes: 9 additions & 0 deletions sdk/framework/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func TestBackendHandleRequest_Forwarding(t *testing.T) {
isStandby bool
isSecondary bool
expectFwd bool
nilSysView bool
}{
"no forward": {
expectFwd: false,
Expand Down Expand Up @@ -159,6 +160,10 @@ func TestBackendHandleRequest_Forwarding(t *testing.T) {
isSecondary: true,
expectFwd: false,
},
"nil system view": {
nilSysView: true,
expectFwd: false,
},
}

for name, test := range tests {
Expand Down Expand Up @@ -193,6 +198,10 @@ func TestBackendHandleRequest_Forwarding(t *testing.T) {
},
}

if test.nilSysView {
b.system = nil
}

_, err := b.HandleRequest(context.Background(), &logical.Request{
Operation: logical.ReadOperation,
Path: "foo",
Expand Down
16 changes: 9 additions & 7 deletions vendor/github.com/hashicorp/vault/sdk/framework/backend.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.