Mastering Terraform: A Practical Guide to Building and Deploying Infrastructure on AWS, Azure, and GCP by Mark Tinderholt
Author:Mark Tinderholt [Tinderholt, Mark]
Language: eng
Format: epub
Tags: Computers, Software Development & Engineering, Systems Analysis & Design, Tools, System Administration, Linux & UNIX Administration
ISBN: 9781835088968
Google: P5kUEQAAQBAJ
Publisher: Packt Publishing Ltd
Published: 2024-07-25T22:00:00+00:00
Workload identity
With the cluster provisioned, we need to get the OIDC issuer certificate from the cluster so that we can use it to configure the OpenID Connect provider with AWS IAM. The following code uses the tls_certificate data source from the tls utility provider, which we covered in Chapter 3, to obtain additional metadata about the certificate:
data âtls_certificateâ âcontainer_cluster_oidcâ { url = aws_eks_cluster.main.identity[0].oidc[0].issuer }
With this additional metadata, we can use the aws_iam_openid_connect_provider resource to connect the cluster to the AWS IAM OIDC provider by referencing sts.amazonaws.com:
resource âaws_iam_openid_connect_providerâ âcontainer_cluster_oidcâ { client_id_list = [âsts.amazonaws.comâ] thumbprint_list = [data.tls_certificate.container_cluster_oidc.certificates[0].sha1_fingerprint] url = data.tls_certificate.container_cluster_oidc.url }
Weâve already set up several IAM roles, including one for the EKS cluster and another for the worker nodes of the cluster. Therefore, I wonât reiterate the creation of the aws_iam_role resource for the workload identity. However, this new role does need to have a very distinct assumption policy. The workload identity IAM role needs to reference the OIDC provider and a yet-to-be-provisioned Kubernetes service account:
data âaws_iam_policy_documentâ âworkload_identity_assume_role_policyâ { statement { actions = [âsts:AssumeRoleWithWebIdentityâ] effect = âAllowâ condition { test = âStringEqualsâ variable = â${replace(aws_iam_openid_connect_provider.container_cluster_oidc.url, âhttps://â, ââ)}:subâ values = [âsystem:serviceaccount:${var.k8s_namespace}:${var.k8s_service_account_name}â] } principals { identifiers = [aws_iam_openid_connect_provider.container_cluster_oidc.arn] type = âFederatedâ } } }
As you can see, in the preceding code, the service account follows a very specific naming convention: system:serviceaccount:<namespace>:<service-account-name>. We replace <namespace> with the name of the Kubernetes namespace and likewise, we replace <service-account-name> with the name of the service account. Itâs important to point out that we are referencing resources that do not exist yet. As such, the reference to them within the workload identity IAM roleâs assumption policy is a pointer or a placeholder to this yet-to-be-created resource. Both the Kubernetes namespace and the service account are resources that will need to be created within the Kubernetes control plane. Weâll tackle that in the next section using the kubernetes Terraform provider.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Disaster & Recovery | Email Administration |
Linux & UNIX Administration | Storage & Retrieval |
Windows Administration |
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7593)
Grails in Action by Glen Smith Peter Ledbrook(7506)
Configuring Windows Server Hybrid Advanced Services Exam Ref AZ-801 by Chris Gill(5002)
Azure Containers Explained by Wesley Haakman & Richard Hooper(4915)
Kotlin in Action by Dmitry Jemerov(4862)
Running Windows Containers on AWS by Marcio Morales(4439)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4284)
Microsoft 365 Identity and Services Exam Guide MS-100 by Aaron Guilmette(4043)
The Age of Surveillance Capitalism by Shoshana Zuboff(3666)
Combating Crime on the Dark Web by Nearchos Nearchou(3617)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3358)
The Ruby Workshop by Akshat Paul Peter Philips Dániel Szabó and Cheyne Wallace(3267)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3164)
Mastering Python for Networking and Security by José Manuel Ortega(3152)
Blockchain Basics by Daniel Drescher(3088)
Microsoft Cybersecurity Architect Exam Ref SC-100 by Dwayne Natwick(2870)
Python for Security and Networking - Third Edition by José Manuel Ortega(2828)
TCP IP by Todd Lammle(2801)
From CIA to APT: An Introduction to Cyber Security by Edward G. Amoroso & Matthew E. Amoroso(2621)