Skip to content
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

OCM-11325 | test: Update assume role policy for shared-vpc role #73

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pkg/aws/aws_client/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,36 @@ func (client *AWSClient) CreateRoleForAdditionalPrincipals(roleName string, inst

return client.CreateRole(roleName, string(assumeRolePolicyDocument), "", make(map[string]string), "/")
}

func (client *AWSClient) UpdateAssumeRolePolicy(roleName string, assumeRolePolicyDocument string) error {
input := &iam.UpdateAssumeRolePolicyInput{
RoleName: &roleName,
PolicyDocument: &assumeRolePolicyDocument,
}

_, err := client.IamClient.UpdateAssumeRolePolicy(context.TODO(), input)
if err != nil {
return err
}
return nil
}

func (client *AWSClient) UpdateAssumeRolePolicyForSharedVPCRole(roleName string, installerRoleArn string,
ingressOperatorRoleArn string) error {
statement := map[string]interface{}{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": map[string]interface{}{
"AWS": []string{installerRoleArn, ingressOperatorRoleArn},
},
"Action": "sts:AssumeRole",
}

assumeRolePolicyDocument, err := completeRolePolicyDocument(statement)
if err != nil {
log.LogError("Failed to convert Role Policy Document into JSON: %s", err.Error())
return err
}
err = client.UpdateAssumeRolePolicy(roleName, assumeRolePolicyDocument)
return err
}
Loading