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

sys/internal/counters/activity/monthly returns mount accessors in a field that should contain mount paths #18812

Closed
maxb opened this issue Jan 24, 2023 · 0 comments · Fixed by #18916
Labels

Comments

@maxb
Copy link
Contributor

maxb commented Jan 24, 2023

The activity reporting APIs return data mentioning mount paths using this structure:

vault/vault/activity_log.go

Lines 1482 to 1485 in 3ded138

type ResponseMount struct {
MountPath string `json:"mount_path"`
Counts *ResponseCounts `json:"counts"`
}

which is populated from this very similar structure:

type MountRecord struct {
MountPath string `json:"mount_path"`
Counts *CountsRecord `json:"counts"`
}

The MountPath field is filled in in various places. In these two, it is actually filled in with mount paths:

vault/vault/activity_log.go

Lines 2168 to 2181 in 3ded138

for mountAccessor, mountData := range entry.Mounts {
valResp := a.core.router.ValidateMountByAccessor(mountAccessor)
if valResp == nil {
// Only persist valid mounts
continue
}
mountRecord = append(mountRecord, &activity.MountRecord{
MountPath: valResp.MountPath,
Counts: &activity.CountsRecord{
EntityClients: len(mountData.Counts.Entities),
NonEntityClients: int(mountData.Counts.Tokens) + len(mountData.Counts.NonEntities),
},
})
}

vault/vault/activity_log.go

Lines 2341 to 2361 in 3ded138

for mountAccessor, mountData := range nsMap[nsID].Mounts {
var displayPath string
if mountAccessor == "" {
displayPath = "no mount accessor (pre-1.10 upgrade?)"
} else {
valResp := a.core.router.ValidateMountByAccessor(mountAccessor)
if valResp == nil {
displayPath = fmt.Sprintf("deleted mount; accessor %q", mountAccessor)
} else {
displayPath = valResp.MountPath
}
}
mountRecord = append(mountRecord, &activity.MountRecord{
MountPath: displayPath,
Counts: &activity.CountsRecord{
EntityClients: len(mountData.Counts.Entities),
NonEntityClients: int(mountData.Counts.Tokens) + len(mountData.Counts.NonEntities),
},
})
}

but in this code:

func (a *ActivityLog) transformActivityLogMounts(mts map[string]*processMount) []*activity.MountRecord {
mounts := make([]*activity.MountRecord, 0)
for mountpath, mountCounts := range mts {
mount := activity.MountRecord{
MountPath: mountpath,
Counts: &activity.CountsRecord{
EntityClients: len(mountCounts.Counts.Entities),
NonEntityClients: len(mountCounts.Counts.NonEntities) + int(mountCounts.Counts.Tokens),
},
}
mounts = append(mounts, &mount)
}
return mounts
}

the name given to the local variable would have you believe it is being filled with the mount path, but if you check the map it is being passed, it is actually a map keyed on mount accessor not path. This has the result of mount accessors erroneously showing up in some fields supposed to contain mount paths, when querying the current month's data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants