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

VLT-32875 Export API panics when mount is deleted #7288 #29376

Merged
merged 8 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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/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
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some references to deletedMountFmt in vault/activity_log_util_common_test.go that will need to be updated also (and maybe elsewhere).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this!! I don't know how my Goland didn't get this :(

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
Loading