Skip to content
Closed
Show file tree
Hide file tree
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: 23 additions & 10 deletions cmd/infra/aws/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,18 +1029,31 @@ func (o *CreateIAMOptions) CreateSharedOIDCRole(ctx context.Context, client iami
return "", fmt.Errorf("failed to create shared role: %w", err)
}

// Add all policies to the shared role as inline policies
// Add all policies to the shared role
for _, binding := range bindings {
policyName := fmt.Sprintf("%s-%s", roleName, binding.name)
_, err = client.PutRolePolicyWithContext(ctx, &iam.PutRolePolicyInput{
PolicyName: aws.String(policyName),
PolicyDocument: aws.String(binding.policy),
RoleName: aws.String(roleName),
})
if err != nil {
return "", fmt.Errorf("failed to add policy %q to shared role: %w", binding.name, err)
if o.UseROSAManagedPolicies && binding.rosaManagedPolicyARN != "" {
// Attach ROSA managed policy
_, err = client.AttachRolePolicyWithContext(ctx, &iam.AttachRolePolicyInput{
PolicyArn: aws.String(binding.rosaManagedPolicyARN),
RoleName: aws.String(roleName),
})
if err != nil {
return "", fmt.Errorf("failed to attach managed policy %q to shared role: %w", binding.rosaManagedPolicyARN, err)
}
logger.Info("Attached managed policy to shared role", "policy", binding.rosaManagedPolicyARN, "role", roleName)
} else {
// Add inline policy
policyName := fmt.Sprintf("%s-%s", roleName, binding.name)
_, err = client.PutRolePolicyWithContext(ctx, &iam.PutRolePolicyInput{
PolicyName: aws.String(policyName),
PolicyDocument: aws.String(binding.policy),
RoleName: aws.String(roleName),
})
if err != nil {
return "", fmt.Errorf("failed to add policy %q to shared role: %w", binding.name, err)
}
logger.Info("Added inline policy to shared role", "policy", binding.name, "role", roleName)
}
logger.Info("Added policy to shared role", "policy", binding.name, "role", roleName)
}

// Add assume role policy if needed
Expand Down
1 change: 1 addition & 0 deletions test/e2e/util/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func (o *Options) DefaultAWSOptions() hypershiftaws.RawCreateOptions {
MultiArch: o.ConfigurableClusterOptions.AWSMultiArch,
PublicOnly: true,
UseROSAManagedPolicies: true,
SharedRole: true,
}
if IsLessThan(semver.MustParse("4.16.0")) {
opts.PublicOnly = false
Expand Down