github-vet / github-vet/rangeloop-pointer-findings
app-sre/vault-manager: toplevel/auth/auth.go; 88 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [app-sre/vault-manager](https://www.github.com/app-sre/vault-manager) at [toplevel/auth/auth.go](https://github.com/app-sre/vault-manager/blob/bd9d33af19041e467f5df3f10c3c1511a7f1815c/toplevel/auth/auth.go#L134-L221)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable e used in defer or goroutine at line 154
[Click here to see the code in its original context.](https://github.com/app-sre/vault-manager/blob/bd9d33af19041e467f5df3f10c3c1511a7f1815c/toplevel/auth/auth.go#L134-L221)
Click here to show the 88 line(s) of Go which triggered the analyzer.
```go
for _, e := range entries {
if e.Type == "github" {
//Build a array of existing policy mappings for current auth mount
existingPolicyMappings := make([]policyMapping, 0)
teamsList := vault.ListSecrets(filepath.Join("/auth", e.Path, "map/teams"))
if teamsList != nil {
var mutex = &sync.Mutex{}
teams := teamsList.Data["keys"].([]interface{})
bwg := utils.NewBoundedWaitGroup(threadPoolSize)
// fill existing policy mappings array in parallel
for team := range teams {
bwg.Add(1)
go func(team int) {
policyMappingPath := filepath.Join("/auth/", e.Path, "map/teams", teams[team].(string))
policiesMappedToEntity := vault.ReadSecret(policyMappingPath).Data["value"].(string)
policies := make([]map[string]interface{}, 0)
for _, policy := range strings.Split(policiesMappedToEntity, ",") {
policies = append(policies, map[string]interface{}{"name": policy})
}
mutex.Lock()
existingPolicyMappings = append(existingPolicyMappings,
policyMapping{GithubTeam: map[string]interface{}{"team": teams[team]}, Policies: policies})
defer bwg.Done()
defer mutex.Unlock()
}(team)
}
bwg.Wait()
}
// remove all gh user policy mappings from vault
usersList := vault.ListSecrets(filepath.Join("/auth", e.Path, "map/users"))
if usersList != nil {
users := usersList.Data["keys"].([]interface{})
bwg := utils.NewBoundedWaitGroup(threadPoolSize)
// remove existing gh user policy mappings in parallel
for user := range users {
bwg.Add(1)
go func(user int) {
policyMappingPath := filepath.Join("/auth/", e.Path, "map/users", users[user].(string))
deletePolicyMapping(policyMappingPath, dryRun)
defer bwg.Done()
}(user)
}
bwg.Wait()
}
policiesMappingsToBeApplied, policiesMappingsToBeDeleted := vault.DiffItems(policyMappingsAsItems(e.PolicyMappings), policyMappingsAsItems(existingPolicyMappings))
// apply policy mappings
for _, pm := range policiesMappingsToBeApplied {
var policies []string
for _, policy := range pm.(policyMapping).Policies {
policies = append(policies, policy["name"].(string))
}
ghTeamName := pm.(policyMapping).GithubTeam["team"].(string)
path := filepath.Join("/auth", e.Path, "map/teams", ghTeamName)
data := map[string]interface{}{"key": ghTeamName, "value": strings.Join(policies, ",")}
writePolicyMapping(path, data, dryRun)
}
// delete policy mappings
for _, pm := range policiesMappingsToBeDeleted {
path := filepath.Join("/auth", e.Path, "map/teams", pm.(policyMapping).GithubTeam["team"].(string))
deletePolicyMapping(path, dryRun)
}
}
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: bd9d33af19041e467f5df3f10c3c1511a7f1815c
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.