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

Backport of Deleted namespace client counts is now shown when queried from admin namespace CE changes into release/1.18.x #29433

Merged
merged 2 commits into from
Jan 30, 2025
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/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)
}
Loading