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

VAULT-21710 - prevent duplicate audit file_path targets #28751

Merged
merged 9 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions vault/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ func (c *Core) enableAudit(ctx context.Context, entry *MountEntry, updateStorage
case strings.HasPrefix(entry.Path, ent.Path):
return fmt.Errorf("path already in use: %w", audit.ErrExternalOptions)
}

// Check if argument file_path vs current vault file_path
if entry.Options["file_path"] == ent.Options["file_path"] {
return fmt.Errorf("file_path already in use: %w", audit.ErrExternalOptions)
}
}

// Generate a new UUID and view
Expand Down
39 changes: 39 additions & 0 deletions vault/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,45 @@
}
}

func TestCore_EnableExistingAudit(t *testing.T) {

Check failure on line 108 in vault/audit_test.go

View workflow job for this annotation

GitHub Actions / Code checks

Test TestCore_EnableExistingAudit is missing a go doc
c, _, _ := TestCoreUnsealed(t)

me := &MountEntry{
Table: auditTableType,
Path: "foo",
Type: audit.TypeFile,
Options: map[string]string{
"file_path": "stdout",
},
}

me2 := &MountEntry{
Table: auditTableType,
Path: "foo2",
Type: audit.TypeFile,
Options: map[string]string{
"file_path": "stdout",
},
}

// Enable first audit backend
err := c.enableAudit(namespace.RootContext(context.Background()), me, true)
if err != nil {
t.Errorf("failed to enable audit for path 'foo': %v", err)
}

// Check if the first audit backend is registered
if !c.auditBroker.IsRegistered("foo/") {
t.Errorf("audit backend for path 'foo/' is not registered")
}

// Enable second audit backend
err = c.enableAudit(namespace.RootContext(context.Background()), me2, true)
if err == nil {
t.Errorf("Should not be able to enable audit for path 'foo2' due to duplication: %v", err)
}
}

func TestCore_EnableAudit_MixedFailures(t *testing.T) {
c, _, _ := TestCoreUnsealed(t)

Expand Down
Loading