Skip to content

Commit 463e878

Browse files
authored
Fix admin check for root aws users (#940)
1 parent 4cee134 commit 463e878

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Diff for: pkg/lib/aws/iam.go

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package aws
1818

1919
import (
20+
"strings"
21+
2022
"github.com/aws/aws-sdk-go/service/iam"
2123
"github.com/cortexlabs/cortex/pkg/lib/errors"
2224
)
@@ -50,6 +52,7 @@ func (c *Client) GetGroupsForUser(userName string) ([]iam.Group, error) {
5052
return groups, nil
5153
}
5254

55+
// Note: root users don't have attached policies, but do have full access
5356
func (c *Client) GetManagedPoliciesForUser(userName string) ([]iam.AttachedPolicy, error) {
5457
var policies []iam.AttachedPolicy
5558

@@ -89,6 +92,16 @@ func (c *Client) IsAdmin() bool {
8992
return false
9093
}
9194

95+
// Root users may not have a user name
96+
if user.UserName == nil {
97+
return true
98+
}
99+
100+
// Root users may have a user name
101+
if user.Arn == nil || strings.HasSuffix(*user.Arn, ":root") {
102+
return true
103+
}
104+
92105
policies, err := c.GetManagedPoliciesForUser(*user.UserName)
93106
if err != nil {
94107
return false

0 commit comments

Comments
 (0)