Skip to content

Commit

Permalink
cherry-picking commit (#29433)
Browse files Browse the repository at this point in the history
Co-authored-by: akshya96 <[email protected]>
  • Loading branch information
1 parent a6aa444 commit 671b4c2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog/29432.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
activity: Show activity records from clients created in deleted namespaces when activity log is queried from admin namespace.
```
5 changes: 3 additions & 2 deletions vault/activity_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -1801,8 +1801,9 @@ func (c *Core) ActivityLogInjectResponse(ctx context.Context, pq *activity.Preco

func (a *ActivityLog) includeInResponse(query *namespace.Namespace, record *namespace.Namespace) bool {
if record == nil {
// Deleted namespace, only include in root queries
return query.ID == namespace.RootNamespaceID
// Deleted namespace, only include in root or admin namespace (if configured) queries
adminNsPath := namespace.Canonicalize(a.core.administrativeNamespacePath())
return query.ID == namespace.RootNamespaceID || (adminNsPath != "" && query.Path == adminNsPath)
}
return record.HasParent(query)
}
Expand Down
3 changes: 2 additions & 1 deletion vault/activity_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,8 @@ func (f *fakeResponseWriter) WriteHeader(statusCode int) {
// their parents.
func TestActivityLog_IncludeNamespace(t *testing.T) {
root := namespace.RootNamespace
a := &ActivityLog{}
core, _, _ := TestCoreUnsealed(t)
a := core.activityLog

nsA := &namespace.Namespace{
ID: "aaaaa",
Expand Down
9 changes: 9 additions & 0 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -3610,6 +3610,15 @@ func (c *Core) LogFormat() string {
return conf.(*server.Config).LogFormat
}

// administrativeNamespacePath returns the configured administrative namespace path.
func (c *Core) administrativeNamespacePath() string {
conf := c.rawConfig.Load()
if conf == nil {
return ""
}
return conf.(*server.Config).AdministrativeNamespacePath
}

// LogLevel returns the log level provided by level provided by config, CLI flag, or env
func (c *Core) LogLevel() string {
return c.logLevel
Expand Down
13 changes: 13 additions & 0 deletions vault/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3696,3 +3696,16 @@ func TestBarrier_DeadlockDetection(t *testing.T) {
t.Fatal("barrierLock doesn't have deadlock detection enabled, it should")
}
}

// Test_administrativeNamespacePath verifies if administrativeNamespacePath function returns the configured administrative namespace path
func Test_administrativeNamespacePath(t *testing.T) {
adminNamespacePath := "admin"
coreConfig := &CoreConfig{
RawConfig: &server.Config{
SharedConfig: &configutil.SharedConfig{AdministrativeNamespacePath: adminNamespacePath},
},
AdministrativeNamespacePath: adminNamespacePath,
}
core, _, _ := TestCoreUnsealedWithConfig(t, coreConfig)
require.Equal(t, core.administrativeNamespacePath(), adminNamespacePath)
}

0 comments on commit 671b4c2

Please sign in to comment.