Skip to content

Commit 44f9c3a

Browse files
vishranaashutosh-narkar
authored andcommitted
Steps to use AWS Web Identity Credentials with k8
Signed-off-by: vishrana538 <[email protected]>
1 parent 3320616 commit 44f9c3a

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

docs/content/management-bundles.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,79 @@ Both methods are going to need a policy for either the service account or the IA
680680
3. Once the policy has been created, it can be assigned to the role.
681681
4. With the role created, go to the EC2 instance view. Select an instance where OPA will run and select "Actions" -> "Security" -> "Modify IAM role". Select the role created in previous steps.
682682

683+
##### Web Identity Credentials
684+
685+
Using EKS IAM Roles for Service Account (Web Identity) Credential.
686+
687+
Below are steps to use OpenID connect provider and kubernetes.
688+
689+
1. Go to the "IAM" section of the AWS console.
690+
2. Click Add provider and select OpenID connect.
691+
3. For Provider URL enter the one belonging to your chosen kubernetes cluster.
692+
4. Click on Get thumbprint
693+
5. For the audience enter: sts.amazonaws.com
694+
6. Add the provider.
695+
7. Once the provider is added, copy the ARN for the identity provider. Here's an example ARN: arn:aws:iam::<your AWS account ID>:oidc-provider/oidc.eks.ap-northeast-1.amazonaws.com/id/DFGHJKKJHGF34HFDFGHY44TRFDE4RGDF
696+
8. Create an IAM role (eg: app_dev_role) with the policy created above and assign it to the kubernetes service account.
697+
9. Go to Trust relationships inside the created role and click Edit trust relationship and enter the following policy document.
698+
```json
699+
{
700+
"Version": "2012-10-17",
701+
"Statement": [
702+
{
703+
"Effect": "Allow",
704+
"Principal": {
705+
"Federated": "<the ARN of the Identity provider from step 7, e.g. arn:aws:iam::123456789012:oidc-provider/oidc.eks.ap-northeast-1.amazonaws.com/id/DFGHJKKJHGF34HFDFGHY44TRFDE4RGDF where 123456789012 is the account ID of your AWS account, and DFGHJK...4RGDF is the OpenID Connect URL's end>"
706+
},
707+
"Action": "sts:AssumeRoleWithWebIdentity",
708+
"Condition": {
709+
"StringEquals": {
710+
"<the OpenID connect URL, e.g. oidc.eks.ap-northeast-1.amazonaws.com/id/B7060B6E991747ADDDC61ADD4B7875CF>:sub": "system:serviceaccount:<kubernetes namespace, e.g. app-dev>:<the kubernetes serviceaccount name, eg: app-dev-service-account>"
711+
}
712+
}
713+
}
714+
]
715+
}
716+
```
717+
10. Create the kubernetes service account.
718+
```yaml
719+
apiVersion: v1
720+
kind: ServiceAccount
721+
metadata:
722+
annotations:
723+
eks.amazonaws.com/role-arn: <the ARN of the IAM role from your account, e.g. arn:aws:iam::<aws_account eg, 123456789012>:role/app_dev_role>
724+
name: <service account name, e.g. app-dev-service-account>
725+
namespace: <k8 namespace, e.g. app-dev>
726+
automountServiceAccountToken: false
727+
```
728+
11. Configure your kubernetes resources to use this service account.
729+
```yaml
730+
apiVersion: apps/v1
731+
kind: Deployment
732+
metadata:
733+
******
734+
spec:
735+
******
736+
template:
737+
*******
738+
spec:
739+
serviceAccountName: app-dev-service-account # <--- like this
740+
automountServiceAccountToken: true
741+
containers:
742+
******
743+
```
744+
745+
You should now be able to access AWS services from your kubernetes cluster.
746+
747+
The above steps should add the following variable to the pod.
748+
749+
```bash
750+
AWS_ROLE_ARN=<the ARN of the IAM role from your account, e.g. arn:aws:iam::123456789012:role/app_dev_role>
751+
AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token
752+
```
753+
754+
Please read [IAM roles for service accounts](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html) for more details.
755+
683756
##### Testing Authentication
684757

685758
Use the [AWS CLI tools](https://aws.amazon.com/cli/) (see ["Upload Bundle"](#upload-bundle) below).
@@ -736,6 +809,26 @@ bundles:
736809

737810
**NOTE:** the S3 `url` is the bucket's regional endpoint.
738811

812+
##### Web Identity Credentials
813+
814+
```yaml
815+
services:
816+
s3:
817+
url: https://my-example-opa-bucket.s3.eu-north-1.amazonaws.com
818+
credentials:
819+
s3_signing:
820+
web_identity_credentials:
821+
aws_region: eu-north-1
822+
session_name: my-open-policy-agent # Optional. Default: open-policy-agent
823+
824+
bundles:
825+
authz:
826+
service: s3
827+
resource: bundle.tar.gz
828+
```
829+
830+
**NOTE:** the S3 `url` is the bucket's regional endpoint.
831+
739832
##### Credential Provider Chaining
740833

741834
Multiple AWS credential providers can be configured. OPA will follow an *internally defined* order to try each of the credential provider given in the configuration till success. Following order of precedence is followed when multiple credential provider is given in the configuration

0 commit comments

Comments
 (0)