Skip to content

Commit

Permalink
backport of commit b48b383 (#17557)
Browse files Browse the repository at this point in the history
Co-authored-by: Hamid Ghaf <83242695+hghaf099@users.noreply.github.com>
  • Loading branch information
hc-github-team-secure-vault-core and hghaf099 committed Oct 14, 2022
1 parent 73ef3a1 commit 50a9f4f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/17532.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
core: prevent memory leak when using control group factors in a policy
```
6 changes: 5 additions & 1 deletion vault/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ func NewACL(ctx context.Context, policies []*Policy) (*ACL, error) {
if pc.Permissions.ControlGroup != nil {
if len(pc.Permissions.ControlGroup.Factors) > 0 {
if existingPerms.ControlGroup == nil {
existingPerms.ControlGroup = pc.Permissions.ControlGroup
cg, err := pc.Permissions.ControlGroup.Clone()
if err != nil {
return nil, err
}
existingPerms.ControlGroup = cg
} else {
for _, authz := range pc.Permissions.ControlGroup.Factors {
existingPerms.ControlGroup.Factors = append(existingPerms.ControlGroup.Factors, authz)
Expand Down
11 changes: 11 additions & 0 deletions vault/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ type ControlGroup struct {
Factors []*ControlGroupFactor
}

func (c *ControlGroup) Clone() (*ControlGroup, error) {
clonedControlGroup, err := copystructure.Copy(c)
if err != nil {
return nil, err
}

cg := clonedControlGroup.(*ControlGroup)

return cg, nil
}

type ControlGroupFactor struct {
Name string
Identity *IdentityFactor `hcl:"identity"`
Expand Down

0 comments on commit 50a9f4f

Please sign in to comment.