|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * rosa_backing_up_and_restoring_applications/backing-up-applications.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="oadp-preparing-aws-credentials_{context}"] |
| 7 | += Preparing AWS credentials |
| 8 | + |
| 9 | +An AWS account must be ready to accept an OADP installation. |
| 10 | + |
| 11 | +.Procedure |
| 12 | +. Create the following environment variables by running the following commands: |
| 13 | ++ |
| 14 | +[NOTE] |
| 15 | +==== |
| 16 | +Change the cluster name to match your ROSA cluster, and ensure you are logged into the cluster as an administrator. Ensure that all fields are outputted correctly before continuing. |
| 17 | +==== |
| 18 | ++ |
| 19 | +[source,terminal] |
| 20 | +---- |
| 21 | +$ export CLUSTER_NAME=my-cluster <1> |
| 22 | +export ROSA_CLUSTER_ID-$(rosa describe cluster -c ${CLUSTER_NAME} --output json | jq -r .id) |
| 23 | +export REGION=$(rosa describe cluster -c ${CLUSTER_NAME} --output json | jq -r .region.id) |
| 24 | +export OIDC_ENDPOINT=$(oc get authentication.config.openshift.io cluster -o jsonpath='{.spec.serviceAccountIssuer}' | sed 's|^https://||') |
| 25 | +export AWS_ACCOUNT_ID='aws sts get-caller-identity --query Account --output text' |
| 26 | +export CLUSTER_VERSION='rosa describe cluster -c ${CLUSTER_NAME} -o json | jq -r .version.raw_id | but -f -2 -d '.' ' |
| 27 | +export ROLE_NAME="${CLUSTER_NAME}-openshift-oadp-aws-cloud-credentials" |
| 28 | +export SCRATCH="/tmp/${CLUSTER_NAME}/oadp" |
| 29 | +mkdir -p ${SCRATCH} |
| 30 | +echo "Cluster ID: ${ROSA_CLUSTER_ID}, Region: ${REGION}, OIDC Endpoint: |
| 31 | +${OIDC_ENDPOINT}, AWS Account ID: ${AWS_ACCOUNT_ID}" |
| 32 | +---- |
| 33 | ++ |
| 34 | +<1> Replace `my-cluster` with your ROSA cluster name. |
| 35 | + |
| 36 | +. On the AWS account, create an IAM policy to allow access to S3. |
| 37 | + |
| 38 | +.. Check to see if the policy exists by running the following command: |
| 39 | ++ |
| 40 | +[source,terminal] |
| 41 | +---- |
| 42 | +$ POLICY_ARN=$(aws iam list-policies --query "Policies[?PolicyName=='RosaOadpVer1'].{ARN:Arn}" -- output text) <1> |
| 43 | +---- |
| 44 | ++ |
| 45 | +<1> Replace `RosaOadp` with your policy name. |
| 46 | + |
| 47 | +.. Use the following command to create the policy JSON file and then create the policy in ROSA. |
| 48 | ++ |
| 49 | +[NOTE] |
| 50 | +==== |
| 51 | +If the policy ARN is not found, the command will create the policy. If the policy ARN already exists, the `if` statement will intentionally skip the policy creation. |
| 52 | +==== |
| 53 | ++ |
| 54 | +[source,terminal] |
| 55 | +---- |
| 56 | +$ if [[ -z "${POLICY_ARN}" ]]; then |
| 57 | +cat << EOF > ${SCRATCH}/policy.json <1> |
| 58 | +{ |
| 59 | +"Version": "2012-10-17", |
| 60 | +"Statement": [ |
| 61 | + { |
| 62 | + "Effect": "Allow", |
| 63 | + "Action": [ |
| 64 | + "s3:CreateBucket",$ echo ${POLICY_ARN} |
| 65 | + "s3:DeleteBucket",cd openshift-docs |
| 66 | + "s3:PutBucketTegging", |
| 67 | + "s3:GetBucketTegging", |
| 68 | + "s3:PutEncryptionConfiguration", |
| 69 | + "s3:GetEncryptionConfiguration", |
| 70 | + "s3:PutLifecycleConfiguration", |
| 71 | + "s3:GetLifecycleConfiguration", |
| 72 | + "s3:GetBucketLocation", |
| 73 | + "s3:ListBucket", |
| 74 | + "s3:GetObject", |
| 75 | + "s3:PutObject", |
| 76 | + "s3:DeleteOgject", |
| 77 | + "s3:ListBucketMultipartUpLoads", |
| 78 | + "s3:AbortMultipartUpLoads", |
| 79 | + "s3:ListMultipartUpLoadParts", |
| 80 | + "s3:DescribeSnapshots", |
| 81 | + "ec2:DescribeVolumes", |
| 82 | + "ec2:DescribeVolumeAttribute", |
| 83 | + "ec2:DescribeVolumesModifications", |
| 84 | + "ec2:DescribeVolumeStatus", |
| 85 | + "ec2:CreateTags", |
| 86 | + "ec2:CreateVolume", |
| 87 | + "ec2:CreateSnapshot", |
| 88 | + "ec2:DeleteSnapshot", |
| 89 | + ] |
| 90 | + "Resource": "*" |
| 91 | + } |
| 92 | + ]} |
| 93 | +EOF |
| 94 | +POLICY_ARN=$(aws iam create-policy --policy-mane "RosaOadpVer1" \ |
| 95 | +--policy-document file:///${SCRATCH}/policy.json --query Policy.Arn \ |
| 96 | +--tags Key=rosa_openshift_version,Value=${CLUSTER_VERSION} Key-rosa_role_prefix,Value=ManagedOpenShift Key=operator_namespace,Value=openshift-oadp Key=operator_name,Value=openshift-oadp \ |
| 97 | +--output text) |
| 98 | +fi |
| 99 | +---- |
| 100 | ++ |
| 101 | +<1> `SCRATCH` is a name for a temporary directory created for the environment variables. |
| 102 | + |
| 103 | +.. View the policy ARN by running the following command: |
| 104 | ++ |
| 105 | +[source,terminal] |
| 106 | +---- |
| 107 | +$ echo ${POLICY_ARN} |
| 108 | +---- |
| 109 | + |
| 110 | + |
| 111 | +. Create an IAM role trust policy for the cluster: |
| 112 | + |
| 113 | +.. Create the trust policy file by running the following command: |
| 114 | ++ |
| 115 | +[source,terminal] |
| 116 | +---- |
| 117 | +$ cat <<EOF > ${SCRATCH}/trust-policy.json |
| 118 | +{ |
| 119 | + "Version": :2012-10-17", |
| 120 | + "Statement": [{ |
| 121 | + "Effect": "Allow", |
| 122 | + "Principal": { |
| 123 | + "Federated": "arn:aws:iam::${AWS_ACCOUNT_ID}:oidc-provider/${OIDC_ENDPOINT}" |
| 124 | + }, |
| 125 | + "Action": "sts:AssumeRoleWithWebIdentity", |
| 126 | + "Condition": { |
| 127 | + "StringEquals": { |
| 128 | + "${OIDC_ENDPOINT}:sub": [ |
| 129 | + "system:serviceaccount:openshift-adp:openshift-adp-controller-manager", |
| 130 | + "system:serviceaccount:openshift-adp:velero:] |
| 131 | + } |
| 132 | + } |
| 133 | + }] |
| 134 | +} |
| 135 | +EOF |
| 136 | +---- |
| 137 | + |
| 138 | +.. Create the role by running the following command: |
| 139 | ++ |
| 140 | +[source,terminal] |
| 141 | +---- |
| 142 | +$ ROLE_ARN=$(aws iam create-role --role-name \ |
| 143 | + "${ROLE_NAME}" \ |
| 144 | + --assume-role-policy-document file://${SCRATCH}/trust-policy.json \ |
| 145 | + --tags Key+rosa_cluster_id,Value=${ROSA_CLUSTER_ID} |
| 146 | +Key=rosa_openshift_verson,Value=${CLUSTER_VERSION} |
| 147 | +Key=rosa_role_prefix,Value=ManagedOpenShift |
| 148 | +Key=operator_namespace,Value=openshift-adp |
| 149 | +Key=operator_name,Value-openshift-oadp \ |
| 150 | + --query Role.Arn --output text) |
| 151 | +---- |
| 152 | + |
| 153 | +.. View the role ARN by running the following command: |
| 154 | ++ |
| 155 | +[source,terminal] |
| 156 | +---- |
| 157 | +$ echo ${ROLE_ARN} |
| 158 | +---- |
| 159 | + |
| 160 | +. Attach the IAM policy to the IAM role by running the following command: |
| 161 | ++ |
| 162 | +[source,terminal] |
| 163 | +---- |
| 164 | +$ aws iam attach-role-policy --role-name "${ROLE_NAME}" \ |
| 165 | + --policy-arn ${POLICY_ARN} |
| 166 | +---- |
| 167 | + |
| 168 | +.Next steps |
| 169 | + |
| 170 | +* Continue to _Installing the OADP Operator and providing the IAM role_. |
0 commit comments