|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * authentication/assuming-an-aws-iam-role-for-a-service-account.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="creating-a-service-account-in-your-project_{context}"] |
| 7 | += Creating a service account in your project |
| 8 | + |
| 9 | +Add a service account in your user-defined project. Include an `eks.amazonaws.com/role-arn` annotation in the service account configuration that references the Amazon Resource Name (ARN) for the AWS Identity and Access Management (IAM) role that you want the service account to assume. |
| 10 | + |
| 11 | +.Prerequisites |
| 12 | + |
| 13 | +* You have created an AWS IAM role for your service account. For more information, see _Setting up an AWS IAM role for a service account_. |
| 14 | +* You have access to a {product-title} with AWS Security Token Service (STS) cluster. Admin-level user privileges are not required. |
| 15 | +* You have installed the OpenShift CLI (`oc`). |
| 16 | +
|
| 17 | +.Procedure |
| 18 | + |
| 19 | +. In your {product-title} cluster, create a project: |
| 20 | ++ |
| 21 | +[source,terminal] |
| 22 | +---- |
| 23 | +$ oc new-project <project_name> <1> |
| 24 | +---- |
| 25 | +<1> Replace `<project_name>` with the name of your project. The name must match the project name that you specified in your AWS IAM role configuration. |
| 26 | ++ |
| 27 | +[NOTE] |
| 28 | +==== |
| 29 | +You are automatically switched to the project when it is created. |
| 30 | +==== |
| 31 | + |
| 32 | +. Create a file named `test-service-account.yaml` with the following service account configuration: |
| 33 | ++ |
| 34 | +[source,yaml] |
| 35 | +---- |
| 36 | +apiVersion: v1 |
| 37 | +kind: ServiceAccount |
| 38 | +metadata: |
| 39 | + name: <service_account_name> <1> |
| 40 | + namespace: <project_name> <2> |
| 41 | + annotations: |
| 42 | + eks.amazonaws.com/role-arn: "<aws_iam_role_arn>" <3> |
| 43 | +---- |
| 44 | +// Add these annotations in the preceding code block later: |
| 45 | +// eks.amazonaws.com/sts-regional-endpoints: "true" <4> |
| 46 | +// eks.amazonaws.com/token-expiration: "86400" <5> |
| 47 | +<1> Replace `<service_account_name>` with the name of your service account. The name must match the service account name that you specified in your AWS IAM role configuration. |
| 48 | +<2> Replace `<project_name>` with the name of your project. The name must match the project name that you specified in your AWS IAM role configuration. |
| 49 | +<3> Specifies the ARN of the AWS IAM role that the service account assumes for use within your pod. Replace `<aws_iam_role_arn>` with the ARN for the AWS IAM role that you created for your service account. The format of the role ARN is `arn:aws:iam::<aws_account_id>:role/<aws_iam_role_name>`. |
| 50 | +// Add these call outs when the additional annotations are added later: |
| 51 | +//<4> Optional: When set to `true`, the `AWS_STS_REGIONAL_ENDPOINTS=regional` environment variable is defined in the pod and AWS STS requests are sent to endpoints for the active region. When this option is not set to `true`, the AWS STS requests are by default sent to the global endpoint \https://sts.amazonaws.com. For more information, see link:https://docs.aws.amazon.com/sdkref/latest/guide/feature-sts-regionalized-endpoints.html[AWS STS Regionalized endpoints] in the AWS documentation. |
| 52 | +//<5> Optional: Specifies the token expiration time in seconds. The default is `86400`. |
| 53 | + |
| 54 | +. Create the service account in your project: |
| 55 | ++ |
| 56 | +[source,terminal] |
| 57 | +---- |
| 58 | +$ oc create -f test-service-account.yaml |
| 59 | +---- |
| 60 | ++ |
| 61 | +.Example output: |
| 62 | +[source,terminal] |
| 63 | +---- |
| 64 | +serviceaccount/<service_account_name> created |
| 65 | +---- |
| 66 | + |
| 67 | +. Review the details of the service account: |
| 68 | ++ |
| 69 | +[source,terminal] |
| 70 | +---- |
| 71 | +$ oc describe serviceaccount <service_account_name> <1> |
| 72 | +---- |
| 73 | +<1> Replace `<service_account_name>` with the name of your service account. |
| 74 | ++ |
| 75 | +.Example output: |
| 76 | ++ |
| 77 | +[source,terminal] |
| 78 | +---- |
| 79 | +Name: <service_account_name> <1> |
| 80 | +Namespace: <project_name> <2> |
| 81 | +Labels: <none> |
| 82 | +Annotations: eks.amazonaws.com/role-arn: <aws_iam_role_arn> <3> |
| 83 | +Image pull secrets: <service_account_name>-dockercfg-rnjkq |
| 84 | +Mountable secrets: <service_account_name>-dockercfg-rnjkq |
| 85 | +Tokens: <service_account_name>-token-4gbjp |
| 86 | +Events: <none> |
| 87 | +---- |
| 88 | +// Add these annotations in the preceding code block later: |
| 89 | +// eks.amazonaws.com/sts-regional-endpoints: true <3> |
| 90 | +// eks.amazonaws.com/token-expiration: 86400 <3> |
| 91 | +<1> Specifies the name of the service account. |
| 92 | +<2> Specifies the project that contains the service account. |
| 93 | +<3> Lists the annotation for the ARN of the AWS IAM role that the service account assumes. |
| 94 | +// Update the preceding call out to the following when the additional annotations are added later: |
| 95 | +//<3> Lists the annotations for the ARN of the AWS IAM role that the service account assumes, the optional regional endpoint configuration, and the optional token expiration specification. |
0 commit comments