Skip to content

Commit

Permalink
backport of commit dcd737b (#29387)
Browse files Browse the repository at this point in the history
Co-authored-by: divyaac <[email protected]>
  • Loading branch information
1 parent 1bc9dbf commit 4e8e62e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
3 changes: 3 additions & 0 deletions changelog/29376.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
activity: Include activity records from clients created by deleted or disabled auth mounts in Export API response.
```
27 changes: 17 additions & 10 deletions vault/activity_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3172,16 +3172,6 @@ func (a *ActivityLog) writeExport(ctx context.Context, rw http.ResponseWriter, f
return fmt.Errorf("failed to process local entity alias")
}

record.MountType, ok = alias["mount_type"].(string)
if !ok {
return fmt.Errorf("failed to process mount type")
}

record.MountPath, ok = alias["mount_path"].(string)
if !ok {
return fmt.Errorf("failed to process mount path")
}

entityAliasMetadata, ok := alias["metadata"].(map[string]string)
if !ok {
return fmt.Errorf("failed to process entity alias metadata")
Expand All @@ -3199,6 +3189,23 @@ func (a *ActivityLog) writeExport(ctx context.Context, rw http.ResponseWriter, f
if entityAliasCustomMetadata != nil {
record.EntityAliasCustomMetadata = entityAliasCustomMetadata
}

valResp := a.core.router.ValidateMountByAccessor(e.MountAccessor)
if valResp == nil {
record.MountType = ""
record.MountPath = fmt.Sprintf(DeletedMountFmt, e.MountAccessor)
} else {
record.MountType, ok = alias["mount_type"].(string)
if !ok {
return fmt.Errorf("failed to process mount type")
}
record.MountPath, ok = alias["mount_path"].(string)
if !ok {
return fmt.Errorf("failed to process mount path")
}

}

}
} else {
// fetch mount directly to ensure mount type and path are populated
Expand Down
2 changes: 1 addition & 1 deletion vault/activity_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4110,7 +4110,7 @@ func TestActivityLog_partialMonthClientCountWithMultipleMountPaths(t *testing.T)
// these are the paths that are expected and correspond with the entity records created above
expectedPaths := []string{
noMountAccessor,
fmt.Sprintf(deletedMountFmt, "deleted"),
fmt.Sprintf(DeletedMountFmt, "deleted"),
path,
}
for _, expectedPath := range expectedPaths {
Expand Down
4 changes: 2 additions & 2 deletions vault/activity_log_util_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func (a *ActivityLog) sortActivityLogMonthsResponse(months []*ResponseMonth) {

const (
noMountAccessor = "no mount accessor (pre-1.10 upgrade?)"
deletedMountFmt = "deleted mount; accessor %q"
DeletedMountFmt = "deleted mount; accessor %q"
DeletedNamespaceFmt = "deleted namespace %q"
)

Expand All @@ -405,7 +405,7 @@ func (a *ActivityLog) mountAccessorToMountPath(mountAccessor string) string {
} else {
valResp := a.core.router.ValidateMountByAccessor(mountAccessor)
if valResp == nil {
displayPath = fmt.Sprintf(deletedMountFmt, mountAccessor)
displayPath = fmt.Sprintf(DeletedMountFmt, mountAccessor)
} else {
displayPath = valResp.MountPath
if !strings.HasSuffix(displayPath, "/") {
Expand Down
2 changes: 1 addition & 1 deletion vault/activity_log_util_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ func Test_ActivityLog_ComputeCurrentMonth_NamespaceMounts(t *testing.T) {
correctMountPaths := func(namespaces []*activity.MonthlyNamespaceRecord) {
for _, ns := range namespaces {
for _, mount := range ns.Mounts {
mount.MountPath = fmt.Sprintf(deletedMountFmt, mount.MountPath)
mount.MountPath = fmt.Sprintf(DeletedMountFmt, mount.MountPath)
}
}
}
Expand Down

0 comments on commit 4e8e62e

Please sign in to comment.