|
| 1 | +# Specifying the IAM Role for ROSA HCP Management Components |
| 2 | + |
| 3 | +When using an OpenShift or ROSA-HCP cluster as the management cluster, you can configure the CAPA controller to use IAM roles instead of storing AWS credentials. This uses OIDC federation to allow the CAPA controller service account to assume an IAM role. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- A management cluster (OpenShift or ROSA-HCP) with CAPI and CAPA installed |
| 8 | +- The management cluster must have an OIDC provider configured |
| 9 | + |
| 10 | +## Retrieve the OIDC Provider |
| 11 | + |
| 12 | +Extract the OIDC provider from the management cluster and set your AWS account ID: |
| 13 | + |
| 14 | +```shell |
| 15 | +export OIDC_PROVIDER=$(kubectl get authentication.config.openshift.io cluster -ojson | jq -r .spec.serviceAccountIssuer | sed 's/https:\/\///') |
| 16 | +export AWS_ACCOUNT_ID=<your-aws-account-id> |
| 17 | +``` |
| 18 | + |
| 19 | +## Create the Trust Policy |
| 20 | + |
| 21 | +Create a trust policy that allows the `capa-controller-manager` service account to assume the IAM role: |
| 22 | + |
| 23 | +```shell |
| 24 | +cat <<EOF > trust.json |
| 25 | +{ |
| 26 | + "Version": "2012-10-17", |
| 27 | + "Statement": [ |
| 28 | + { |
| 29 | + "Effect": "Allow", |
| 30 | + "Principal": { |
| 31 | + "Federated": "arn:aws:iam::${AWS_ACCOUNT_ID}:oidc-provider/${OIDC_PROVIDER}" |
| 32 | + }, |
| 33 | + "Action": "sts:AssumeRoleWithWebIdentity", |
| 34 | + "Condition": { |
| 35 | + "StringEquals": { |
| 36 | + "${OIDC_PROVIDER}:sub": "system:serviceaccount:capa-system:capa-controller-manager" |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + ] |
| 41 | +} |
| 42 | +EOF |
| 43 | +``` |
| 44 | + |
| 45 | + |
| 46 | +## Create the IAM Role |
| 47 | + |
| 48 | +Create the IAM role and attach the required AWS policies: |
| 49 | + |
| 50 | +```shell |
| 51 | +aws iam create-role --role-name "capa-manager-role" \ |
| 52 | + --assume-role-policy-document file://trust.json \ |
| 53 | + --description "IAM role for CAPA to assume" |
| 54 | + |
| 55 | +aws iam attach-role-policy --role-name capa-manager-role \ |
| 56 | + --policy-arn arn:aws:iam::aws:policy/AWSCloudFormationFullAccess |
| 57 | + |
| 58 | +aws iam attach-role-policy --role-name capa-manager-role \ |
| 59 | + --policy-arn arn:aws:iam::aws:policy/AmazonVPCFullAccess |
| 60 | +``` |
| 61 | + |
| 62 | +## Annotate the Service Account |
| 63 | + |
| 64 | +Retrieve the IAM role ARN and annotate the CAPA controller service account: |
| 65 | + |
| 66 | +```shell |
| 67 | +export APP_IAM_ROLE_ARN=$(aws iam get-role --role-name=capa-manager-role --query Role.Arn --output text) |
| 68 | + |
| 69 | +kubectl annotate serviceaccount -n capa-system capa-controller-manager \ |
| 70 | + eks.amazonaws.com/role-arn=$APP_IAM_ROLE_ARN |
| 71 | +``` |
| 72 | + |
| 73 | +Restart the CAPA controller to pick up the new role: |
| 74 | + |
| 75 | +```shell |
| 76 | +kubectl rollout restart deployment capa-controller-manager -n capa-system |
| 77 | +``` |
| 78 | + |
| 79 | +After this configuration, the CAPA controller will use the IAM role to manage AWS resources, and you can provision ROSA HCP clusters without storing AWS credentials in the management cluster. |
0 commit comments