Skip to content

Instantly share code, notes, and snippets.

@niedbalski
Created December 5, 2023 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niedbalski/13637f039f315babc47f582f13a2bb7e to your computer and use it in GitHub Desktop.
Save niedbalski/13637f039f315babc47f582f13a2bb7e to your computer and use it in GitHub Desktop.
1. Set Up an OIDC Identity Provider in AWS
Create an OIDC Identity Provider in AWS IAM:
Navigate to the IAM section in the AWS Management Console.
Choose "Identity Providers," then "Create Provider."
Select "OpenID Connect" as the provider type.
For the provider URL, you need the OIDC discovery endpoint URL from your k3s cluster. This URL is typically obtained from your Kubernetes cluster's API server configuration.
Add the thumbprint of the OIDC provider's SSL certificate.
2. Configure k3s for OIDC
Configure k3s with OIDC Details:
You need to start the k3s server with additional flags to enable OIDC authentication:
--oidc-issuer-url: The URL of the OIDC issuer.
--oidc-client-id: A client ID that exists in your AWS IAM OIDC provider.
--oidc-username-claim, --oidc-groups-claim: Optional flags to specify which JWT claims map to Kubernetes user and group names.
Restart k3s to apply these settings.
3. Create IAM Roles for Kubernetes Service Accounts
Create IAM Roles:
In AWS IAM, create roles that your Kubernetes service accounts will assume.
Define a trust relationship for each role to allow the OIDC provider (and by extension, specific Kubernetes service accounts) to assume the role.
4. Associate IAM Roles with Kubernetes Service Accounts
Create/Modify Kubernetes Service Accounts:
In your k3s cluster, create or modify Kubernetes service accounts and annotate them with the ARN of the corresponding IAM role.
The annotation is typically in the format eks.amazonaws.com/role-arn: <role-ARN>.
5. Deploy Applications with Service Accounts
Use Service Accounts in Workloads:
Modify your Kubernetes workloads to use these service accounts.
When these pods run, they will assume the permissions granted by the IAM role associated with their service account.
6. Test and Validate
Testing:
Deploy a test application in your k3s cluster that requires AWS API access.
Verify that the application can access AWS resources according to the permissions defined in the IAM role.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment