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 8 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/28751.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
audit: Prevent the audit process from allowing duplicate file path targets
```
7 changes: 7 additions & 0 deletions vault/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ 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.Type == "file" {
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
43 changes: 43 additions & 0 deletions vault/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,49 @@ func TestCore_EnableAudit(t *testing.T) {
}
}

// TestCore_EnableExistingAudit tests the handling of enabling existing audit backends,
// specifically checking for duplicate file paths in audit options across multiple paths.
func TestCore_EnableExistingAudit(t *testing.T) {
c, _, _ := TestCoreUnsealed(t)

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

// Second audit backend entry
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