-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat(oss): enable bucket access for ram role #194
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -258,7 +258,7 @@ func revokePermissionsFromPolicy(policyString string, g domain.Grant) (string, e | |||||
return "", err | ||||||
} | ||||||
|
||||||
principalAccountID, err := getPrincipalFromAccountID(g.AccountID) | ||||||
principalAccountID, err := getPrincipalFromAccountID(g.AccountID, g.AccountType) | ||||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
|
@@ -310,7 +310,7 @@ func updatePolicyToGrantPermissions(policy string, g domain.Grant) (string, erro | |||||
return "", err | ||||||
} | ||||||
|
||||||
principalAccountID, err := getPrincipalFromAccountID(g.AccountID) | ||||||
principalAccountID, err := getPrincipalFromAccountID(g.AccountID, g.AccountType) | ||||||
if err != nil { | ||||||
return "", err | ||||||
} | ||||||
|
@@ -462,18 +462,42 @@ func getAccountIDFromResource(resource *domain.Resource) (string, error) { | |||||
return urnParts[2], nil | ||||||
} | ||||||
|
||||||
func getPrincipalFromAccountID(accountID string) (string, error) { | ||||||
accountIDParts := strings.Split(accountID, "$") | ||||||
if len(accountIDParts) < 2 { | ||||||
return "", fmt.Errorf("invalid accountID format") | ||||||
} | ||||||
func getPrincipalFromAccountID(accountID, accountType string) (string, error) { | ||||||
// AccountTypeRAMUser = RAM$<uid>:<sub-account-id> | ||||||
// AccountTypeRAMRole = acs:ram::<uid>:role/<role-name> | ||||||
if accountType == AccountTypeRAMUser { | ||||||
accountIDParts := strings.Split(accountID, "$") | ||||||
if len(accountIDParts) < 2 { | ||||||
return "", fmt.Errorf("invalid accountID format") | ||||||
} | ||||||
|
||||||
subParts := strings.Split(accountIDParts[1], ":") | ||||||
if len(subParts) < 2 { | ||||||
return "", fmt.Errorf("invalid accountID format") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
return subParts[1], nil | ||||||
} else if accountType == AccountTypeRAMRole { | ||||||
|
||||||
subParts := strings.Split(accountIDParts[1], ":") | ||||||
if len(subParts) < 2 { | ||||||
return "", fmt.Errorf("invalid accountID format") | ||||||
accountIDParts := strings.Split(accountID, ":") | ||||||
if len(accountIDParts) < 5 { | ||||||
return "", fmt.Errorf("invalid accountID format") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
mainAccountID := accountIDParts[3] | ||||||
roleNameParts := strings.Split(accountIDParts[4], "/") | ||||||
if len(roleNameParts) < 2 { | ||||||
return "", fmt.Errorf("invalid accountID format") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
roleName := roleNameParts[1] | ||||||
|
||||||
// STS ARN - arn:sts::<uid>:assumed-role/<role-name>/* | ||||||
return fmt.Sprintf("arn:sts::%s:assumed-role/%s/*", mainAccountID, roleName), nil | ||||||
} | ||||||
|
||||||
return subParts[1], nil | ||||||
return "", fmt.Errorf("invalid account type") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
} | ||||||
|
||||||
func unmarshalPolicy(policy string) (Policy, error) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.