Skip to content

Commit

Permalink
update role policy for api-gateway when creating new gateway (#4003)
Browse files Browse the repository at this point in the history
* update role policy for api-gateway when creating new gateway

* changelog
  • Loading branch information
jm96441n authored May 17, 2024
1 parent a7eabc0 commit 8f12103
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/4003.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
api-gateway: fix bug where multiple logical APIGateways would share the same ACL policy.
```
18 changes: 17 additions & 1 deletion control-plane/api-gateway/cache/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,26 @@ func (c *Cache) ensureRole(client *api.Client, gatewayName string) (string, erro

_, _, err = client.ACL().RoleCreate(role, &api.WriteOptions{})
if err != nil && !isRoleExistsErr(err, aclRoleName) {
//don't error out in the case that the role already exists.
// don't error out in the case that the role already exists.
return "", err
}

if err != nil && isRoleExistsErr(err, aclRoleName) {
role, _, err := client.ACL().RoleReadByName(role.Name, &api.QueryOptions{})
if err != nil {
return "", err
}

role.Policies = []*api.ACLLink{{ID: policyID}}
role, _, err = client.ACL().RoleUpdate(role, &api.WriteOptions{})
if err != nil {
return "", err
}

c.gatewayNameToRole[gatewayName] = role
return aclRoleName, err
}

c.gatewayNameToRole[gatewayName] = role
return aclRoleName, nil
}
Expand Down

0 comments on commit 8f12103

Please sign in to comment.