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

Code Cleanup Around Audit Backends #20933

Merged
merged 4 commits into from
Jun 5, 2023
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
3 changes: 3 additions & 0 deletions changelog/20933.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
core: remove unnecessary *BarrierView field from backendEntry struct
```
4 changes: 2 additions & 2 deletions vault/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c *Core) enableAudit(ctx context.Context, entry *MountEntry, updateStorage
c.audit = newTable

// Register the backend
c.auditBroker.Register(entry.Path, backend, view, entry.Local)
c.auditBroker.Register(entry.Path, backend, entry.Local)
if c.logger.IsInfo() {
c.logger.Info("enabled audit backend", "path", entry.Path, "type", entry.Type)
}
Expand Down Expand Up @@ -416,7 +416,7 @@ func (c *Core) setupAudits(ctx context.Context) error {
}

// Mount the backend
broker.Register(entry.Path, backend, view, entry.Local)
broker.Register(entry.Path, backend, entry.Local)

successCount++
}
Expand Down
4 changes: 1 addition & 3 deletions vault/audit_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (

type backendEntry struct {
backend audit.Backend
view *BarrierView
local bool
}

Expand All @@ -41,12 +40,11 @@ func NewAuditBroker(log log.Logger) *AuditBroker {
}

// Register is used to add new audit backend to the broker
func (a *AuditBroker) Register(name string, b audit.Backend, v *BarrierView, local bool) {
func (a *AuditBroker) Register(name string, b audit.Backend, local bool) {
a.Lock()
defer a.Unlock()
a.backends[name] = backendEntry{
backend: b,
view: v,
local: local,
}
}
Expand Down
30 changes: 15 additions & 15 deletions vault/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestAudit_ReadOnlyViewDuringMount(t *testing.T) {
Path: "foo",
Type: "noop",
}
err := c.enableAudit(namespace.RootContext(nil), me, true)
err := c.enableAudit(namespace.RootContext(context.Background()), me, true)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand All @@ -59,7 +59,7 @@ func TestCore_EnableAudit(t *testing.T) {
Path: "foo",
Type: "noop",
}
err := c.enableAudit(namespace.RootContext(nil), me, true)
err := c.enableAudit(namespace.RootContext(context.Background()), me, true)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestCore_DisableAudit(t *testing.T) {
c, keys, _ := TestCoreUnsealed(t)
c.auditBackends["noop"] = corehelpers.NoopAuditFactory(nil)

existed, err := c.disableAudit(namespace.RootContext(nil), "foo", true)
existed, err := c.disableAudit(namespace.RootContext(context.Background()), "foo", true)
if existed && err != nil {
t.Fatalf("existed: %v; err: %v", existed, err)
}
Expand All @@ -249,12 +249,12 @@ func TestCore_DisableAudit(t *testing.T) {
Path: "foo",
Type: "noop",
}
err = c.enableAudit(namespace.RootContext(nil), me, true)
err = c.enableAudit(namespace.RootContext(context.Background()), me, true)
if err != nil {
t.Fatalf("err: %v", err)
}

existed, err = c.disableAudit(namespace.RootContext(nil), "foo", true)
existed, err = c.disableAudit(namespace.RootContext(context.Background()), "foo", true)
if !existed || err != nil {
t.Fatalf("existed: %v; err: %v", existed, err)
}
Expand Down Expand Up @@ -343,8 +343,8 @@ func TestAuditBroker_LogRequest(t *testing.T) {
b := NewAuditBroker(l)
a1 := corehelpers.TestNoopAudit(t, nil)
a2 := corehelpers.TestNoopAudit(t, nil)
b.Register("foo", a1, nil, false)
b.Register("bar", a2, nil, false)
b.Register("foo", a1, false)
b.Register("bar", a2, false)

auth := &logical.Auth{
ClientToken: "foo",
Expand Down Expand Up @@ -403,8 +403,8 @@ func TestAuditBroker_LogRequest(t *testing.T) {
if !reflect.DeepEqual(a.Req[0], req) {
t.Fatalf("Bad: %#v\n wanted %#v", a.Req[0], req)
}
if !reflect.DeepEqual(a.ReqErrs[0], reqErrs) {
t.Fatalf("Bad: %#v", a.ReqErrs[0])
if a.ReqErrs[0].Error() != reqErrs.Error() {
t.Fatalf("expected %v, got %v", a.ReqErrs[0].Error(), reqErrs.Error())
}
}

Expand All @@ -430,8 +430,8 @@ func TestAuditBroker_LogResponse(t *testing.T) {
b := NewAuditBroker(l)
a1 := corehelpers.TestNoopAudit(t, nil)
a2 := corehelpers.TestNoopAudit(t, nil)
b.Register("foo", a1, nil, false)
b.Register("bar", a2, nil, false)
b.Register("foo", a1, false)
b.Register("bar", a2, false)

auth := &logical.Auth{
NumUses: 10,
Expand Down Expand Up @@ -504,8 +504,8 @@ func TestAuditBroker_LogResponse(t *testing.T) {
if !reflect.DeepEqual(a.Resp[0], resp) {
t.Fatalf("Bad: %#v", a.Resp[0])
}
if !reflect.DeepEqual(a.RespErrs[0], respErr) {
t.Fatalf("Expected\n%v\nGot\n%#v", respErr, a.RespErrs[0])
if a.RespErrs[0].Error() != respErr.Error() {
t.Fatalf("expected %v, got %v", respErr, a.RespErrs[0])
}
}

Expand Down Expand Up @@ -537,8 +537,8 @@ func TestAuditBroker_AuditHeaders(t *testing.T) {
view := NewBarrierView(barrier, "headers/")
a1 := corehelpers.TestNoopAudit(t, nil)
a2 := corehelpers.TestNoopAudit(t, nil)
b.Register("foo", a1, nil, false)
b.Register("bar", a2, nil, false)
b.Register("foo", a1, false)
b.Register("bar", a2, false)

auth := &logical.Auth{
ClientToken: "foo",
Expand Down