diff --git a/vault/activity_log.go b/vault/activity_log.go index d206985cc0..f52519a61b 100644 --- a/vault/activity_log.go +++ b/vault/activity_log.go @@ -1571,16 +1571,16 @@ func (a *ActivityLog) receivedFragment(fragment *activity.LogFragment) { } type ResponseCounts struct { - DistinctEntities int `json:"distinct_entities"` - EntityClients int `json:"entity_clients"` - NonEntityTokens int `json:"non_entity_tokens"` - NonEntityClients int `json:"non_entity_clients"` + DistinctEntities int `json:"distinct_entities" mapstructure:"distinct_entities"` + EntityClients int `json:"entity_clients" mapstructure:"entity_clients"` + NonEntityTokens int `json:"non_entity_tokens" mapstructure:"non_entity_tokens"` + NonEntityClients int `json:"non_entity_clients" mapstructure:"non_entity_clients"` Clients int `json:"clients"` } type ResponseNamespace struct { - NamespaceID string `json:"namespace_id"` - NamespacePath string `json:"namespace_path"` + NamespaceID string `json:"namespace_id" mapstructure:"namespace_id"` + NamespacePath string `json:"namespace_path" mapstructure:"namespace_path"` Counts ResponseCounts `json:"counts"` Mounts []*ResponseMount `json:"mounts"` } @@ -1598,7 +1598,7 @@ type ResponseNewClients struct { } type ResponseMount struct { - MountPath string `json:"mount_path"` + MountPath string `json:"mount_path" mapstructure:"mount_path"` Counts *ResponseCounts `json:"counts"` } diff --git a/vault/logical_system_activity_write_testonly.go b/vault/logical_system_activity_write_testonly.go index e890d87d46..62f7366887 100644 --- a/vault/logical_system_activity_write_testonly.go +++ b/vault/logical_system_activity_write_testonly.go @@ -9,6 +9,7 @@ import ( "context" "fmt" "io" + "strings" "sync" "time" @@ -226,6 +227,7 @@ func (m *multipleMonthsActivityClients) processMonth(ctx context.Context, core * m.months[month.GetMonthsAgo()].generationParameters = month add := func(c []*generation.Client, segmentIndex *int) error { for _, clients := range c { + mountAccessor := defaultMountAccessorRootNS if clients.Namespace == "" { clients.Namespace = namespace.RootNamespaceID @@ -234,34 +236,41 @@ func (m *multipleMonthsActivityClients) processMonth(ctx context.Context, core * clients.ClientType = entityActivityType } - // verify that the namespace exists - ns, err := core.NamespaceByID(ctx, clients.Namespace) - if err != nil { - return err + if clients.Namespace != namespace.RootNamespaceID && !strings.HasSuffix(clients.Namespace, "/") { + clients.Namespace += "/" } + // verify that the namespace exists + ns := core.namespaceByPath(clients.Namespace) + if ns.ID == namespace.RootNamespaceID && clients.Namespace != namespace.RootNamespaceID { + return fmt.Errorf("unable to find namespace %s", clients.Namespace) + } + clients.Namespace = ns.ID // verify that the mount exists if clients.Mount != "" { + if !strings.HasSuffix(clients.Mount, "/") { + clients.Mount += "/" + } nctx := namespace.ContextWithNamespace(ctx, ns) mountEntry := core.router.MatchingMountEntry(nctx, clients.Mount) if mountEntry == nil { - return fmt.Errorf("unable to find matching mount in namespace %s", clients.Namespace) + return fmt.Errorf("unable to find matching mount in namespace %s", ns.Path) } + mountAccessor = mountEntry.Accessor } - mountAccessor := defaultMountAccessorRootNS if clients.Namespace != namespace.RootNamespaceID && clients.Mount == "" { // if we're not using the root namespace, find a mount on the namespace that we are using found := false for _, mount := range mounts { - if mount.NamespaceID == clients.Namespace { + if mount.NamespaceID == ns.ID { mountAccessor = mount.Accessor found = true break } } if !found { - return fmt.Errorf("unable to find matching mount in namespace %s", clients.Namespace) + return fmt.Errorf("unable to find matching mount in namespace %s", ns.Path) } } diff --git a/vault/logical_system_activity_write_testonly_test.go b/vault/logical_system_activity_write_testonly_test.go index 3747016419..fd2ce2b38d 100644 --- a/vault/logical_system_activity_write_testonly_test.go +++ b/vault/logical_system_activity_write_testonly_test.go @@ -215,6 +215,16 @@ func Test_multipleMonthsActivityClients_processMonth(t *testing.T) { }, numMonths: 1, }, + { + name: "mount missing slash", + clients: &generation.Data{ + Clients: &generation.Data_All{All: &generation.Clients{Clients: []*generation.Client{{ + Namespace: namespace.RootNamespaceID, + Mount: "identity", + }}}}, + }, + numMonths: 1, + }, { name: "specified namespace exists, mount empty", clients: &generation.Data{