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

* Export API Bug

* Revert "Export API Bug"

This reverts commit 044597748d8b2c726996e515ffff3e0dea9d30a8.

* Export API Bug

* Added changelog

* Update changelog/29376.txt

Co-authored-by: Violet Hynes <violet.hynes@hashicorp.com>

* Revert "Export API Bug"

This reverts commit 9cdd28c59ea4907f8a44c20a4a048045d56d9d12.

* Export API Bug Change

* Edited one more deletedMount to renamed

---------

Co-authored-by: Violet Hynes <violet.hynes@hashicorp.com>
This commit is contained in:
divyaac
2025-01-22 10:38:43 -08:00
committed by GitHub
parent 3fd8a31614
commit dcd737b32b
5 changed files with 24 additions and 14 deletions

3
changelog/29376.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:bug
activity: Include activity records from clients created by deleted or disabled auth mounts in Export API response.
```

View File

@@ -3172,16 +3172,6 @@ func (a *ActivityLog) writeExport(ctx context.Context, rw http.ResponseWriter, f
return fmt.Errorf("failed to process local entity alias") 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) entityAliasMetadata, ok := alias["metadata"].(map[string]string)
if !ok { if !ok {
return fmt.Errorf("failed to process entity alias metadata") return fmt.Errorf("failed to process entity alias metadata")
@@ -3199,6 +3189,23 @@ func (a *ActivityLog) writeExport(ctx context.Context, rw http.ResponseWriter, f
if entityAliasCustomMetadata != nil { if entityAliasCustomMetadata != nil {
record.EntityAliasCustomMetadata = entityAliasCustomMetadata 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 { } else {
// fetch mount directly to ensure mount type and path are populated // fetch mount directly to ensure mount type and path are populated

View File

@@ -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 // these are the paths that are expected and correspond with the entity records created above
expectedPaths := []string{ expectedPaths := []string{
noMountAccessor, noMountAccessor,
fmt.Sprintf(deletedMountFmt, "deleted"), fmt.Sprintf(DeletedMountFmt, "deleted"),
path, path,
} }
for _, expectedPath := range expectedPaths { for _, expectedPath := range expectedPaths {

View File

@@ -392,7 +392,7 @@ func (a *ActivityLog) sortActivityLogMonthsResponse(months []*ResponseMonth) {
const ( const (
noMountAccessor = "no mount accessor (pre-1.10 upgrade?)" noMountAccessor = "no mount accessor (pre-1.10 upgrade?)"
deletedMountFmt = "deleted mount; accessor %q" DeletedMountFmt = "deleted mount; accessor %q"
DeletedNamespaceFmt = "deleted namespace %q" DeletedNamespaceFmt = "deleted namespace %q"
) )
@@ -405,7 +405,7 @@ func (a *ActivityLog) mountAccessorToMountPath(mountAccessor string) string {
} else { } else {
valResp := a.core.router.ValidateMountByAccessor(mountAccessor) valResp := a.core.router.ValidateMountByAccessor(mountAccessor)
if valResp == nil { if valResp == nil {
displayPath = fmt.Sprintf(deletedMountFmt, mountAccessor) displayPath = fmt.Sprintf(DeletedMountFmt, mountAccessor)
} else { } else {
displayPath = valResp.MountPath displayPath = valResp.MountPath
if !strings.HasSuffix(displayPath, "/") { if !strings.HasSuffix(displayPath, "/") {

View File

@@ -978,7 +978,7 @@ func Test_ActivityLog_ComputeCurrentMonth_NamespaceMounts(t *testing.T) {
correctMountPaths := func(namespaces []*activity.MonthlyNamespaceRecord) { correctMountPaths := func(namespaces []*activity.MonthlyNamespaceRecord) {
for _, ns := range namespaces { for _, ns := range namespaces {
for _, mount := range ns.Mounts { for _, mount := range ns.Mounts {
mount.MountPath = fmt.Sprintf(deletedMountFmt, mount.MountPath) mount.MountPath = fmt.Sprintf(DeletedMountFmt, mount.MountPath)
} }
} }
} }