AWS IAM Openid Connect Provider
This page shows how to write Terraform and CloudFormation for IAM Openid Connect Provider and write them securely.
aws_iam_openid_connect_provider (Terraform)
The Openid Connect Provider in IAM can be configured in Terraform with the resource name aws_iam_openid_connect_provider
. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_iam_openid_connect_provider" "cluster" {
client_id_list = ["sts.amazonaws.com"]
thumbprint_list = [data.external.thumb.result.thumbprint]
url = aws_eks_cluster.cluster.identity.0.oidc.0.issuer
}
resource "aws_iam_openid_connect_provider" "EKS_OIDC" {
url = data.aws_eks_cluster.EKS_CLUSTER.identity[0].oidc[0].issuer
client_id_list = [
"sts.amazonaws.com",
]
resource "aws_iam_openid_connect_provider" "cluster" {
client_id_list = ["sts.amazonaws.com"]
thumbprint_list = [data.tls_certificate.cert.certificates[0].sha1_fingerprint]
url = aws_eks_cluster.cluster.identity[0].oidc[0].issuer
}
resource "aws_iam_openid_connect_provider" "main" {
client_id_list = ["sts.amazonaws.com"]
thumbprint_list = [data.external.thumb.result.thumbprint]
url = aws_eks_cluster.main.identity.0.oidc.0.issuer
}
resource "aws_iam_openid_connect_provider" "oidc_provider" {
count = var.enable_irsa ? 1 : 0
client_id_list = ["sts.amazonaws.com"]
thumbprint_list = [var.eks_oidc_thumbprint]
url = flatten(concat(aws_eks_cluster.cluster[*].identity[*].oidc.0.issuer, [""]))[0]
}
Parameters
-
arn
optional computed - string -
client_id_list
required - list of string -
id
optional computed - string -
tags
optional - map from string to string -
thumbprint_list
required - list of string -
url
required - string
Explanation in Terraform Registry
Provides an IAM OpenID Connect provider.
Tips: Best Practices for The Other AWS IAM Resources
In addition to the aws_iam_account_password_policy, AWS IAM has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_iam_account_password_policy
Ensure AWS IAM account password policies requires long passwords
It's better to enforce the use of long and complex passwords to reduce the risk of bruteforce attacks.
AWS::IAM::OIDCProvider (CloudFormation)
The OIDCProvider in IAM can be configured in CloudFormation with the resource name AWS::IAM::OIDCProvider
. The following sections describe 6 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::IAM::OIDCProvider
Properties:
Url: https://token.actions.githubusercontent.com
ClientIdList: [sigstore]
ThumbprintList: [a031c46782e6e6c662c2c87c76da9aa62ccabd8e]
Type: AWS::IAM::OIDCProvider
Properties:
Url: https://token.actions.githubusercontent.com
ClientIdList: [sigstore]
ThumbprintList: [a031c46782e6e6c662c2c87c76da9aa62ccabd8e]
Type: AWS::IAM::OIDCProvider
Properties:
Url: https://token.actions.githubusercontent.com
ClientIdList: [sigstore]
ThumbprintList: [a031c46782e6e6c662c2c87c76da9aa62ccabd8e]
Type: AWS::IAM::OIDCProvider
Properties:
Url: https://token.actions.githubusercontent.com
ThumbprintList: [a031c46782e6e6c662c2c87c76da9aa62ccabd8e]
ClientIdList: [sts.amazonaws.com]
Type: AWS::IAM::OIDCProvider
Properties:
Url: https://token.actions.githubusercontent.com
ClientIdList:
- sts.amazonaws.com
ThumbprintList:
"AWS::IAM::OIDCProvider": {
"Type": "AWS::IAM::OIDCProvider",
"Properties": {}
},
"AWS::Greengrass::LoggerDefinitionVersion": {
"Type": "AWS::Greengrass::LoggerDefinitionVersion",
Parameters
-
ClientIdList
optional - List -
Url
optional - String -
ThumbprintList
required - List -
Tags
optional - List of Tag
Explanation in CloudFormation Registry
Creates an IAM entity to describe an identity provider (IdP) that supports OpenID Connect (OIDC).
The OIDC provider that you create with this operation can be used as a principal in a role's trust policy. Such a policy establishes a trust relationship between AWS and the OIDC provider.
When you create the IAM OIDC provider, you specify the following:+ The URL of the OIDC identity provider (IdP) to trust+ A list of client IDs (also known as audiences) that identify the application or applications that are allowed to authenticate using the OIDC provider+ A list of thumbprints of one or more server certificates that the IdP usesYou get all of this information from the OIDC IdP that you want to use to access AWS.
Note The trust for the OIDC provider is derived from the IAM provider that this operation creates. Therefore, it is best to limit access to the CreateOpenIDConnectProvider operation to highly privileged users.
Frequently asked questions
What is AWS IAM Openid Connect Provider?
AWS IAM Openid Connect Provider is a resource for IAM of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS IAM Openid Connect Provider?
For Terraform, the osvaldotoja/eks-irsa, Kubernetes26/EKS_Modules%20OIDC_Provider.tf#L15) and brianbinbin/tf-eks source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the Snails8/terraform-ecs-nat-sample, Snails8/terraform-sample-ecs-public and Snails8/terraform-ecs-prd-laravel source code examples are useful. See the CloudFormation Example section for further details.