PodIdentityAssociation class
Resource for managing an AWS EKS (Elastic Kubernetes) Pod Identity Association.
Creates an EKS Pod Identity association between a service account in an Amazon EKS cluster and an IAM role with EKS Pod Identity. Use EKS Pod Identity to give temporary IAM credentials to pods and the credentials are rotated automatically.
Amazon EKS Pod Identity associations provide the ability to manage credentials for your applications, similar to the way that EC2 instance profiles provide credentials to Amazon EC2 instances.
If a pod uses a service account that has an association, Amazon EKS sets environment variables in the containers of the pod. The environment variables configure the Amazon Web Services SDKs, including the Command Line Interface, to use the EKS Pod Identity credentials.
Pod Identity is a simpler method than IAM roles for service accounts, as this method doesn’t use OIDC identity providers. Additionally, you can configure a role for Pod Identity once, and reuse it across clusters.
Example Usage
With Inline Session Policy
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.eks.PodIdentityAssociation("example", {
clusterName: exampleAwsEksCluster.name,
namespace: "example",
serviceAccount: "example-sa",
roleArn: exampleAwsIamRole.arn,
disableSessionTags: true,
policy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Action: ["s3:GetObject"],
Resource: "arn:aws:s3:::my-bucket/*",
}],
}),
});
import pulumi
import json
import pulumi_aws as aws
example = aws.eks.PodIdentityAssociation("example",
cluster_name=example_aws_eks_cluster["name"],
namespace="example",
service_account="example-sa",
role_arn=example_aws_iam_role["arn"],
disable_session_tags=True,
policy=json.dumps({
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["s3:GetObject"],
"Resource": "arn:aws:s3:::my-bucket/*",
}],
}))
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new Aws.Eks.PodIdentityAssociation("example", new()
{
ClusterName = exampleAwsEksCluster.Name,
Namespace = "example",
ServiceAccount = "example-sa",
RoleArn = exampleAwsIamRole.Arn,
DisableSessionTags = true,
Policy = JsonSerializer.Serialize(new Dictionary<string, object?>
{
["Version"] = "2012-10-17",
["Statement"] = new[]
{
new Dictionary<string, object?>
{
["Effect"] = "Allow",
["Action"] = new[]
{
"s3:GetObject",
},
["Resource"] = "arn:aws:s3:::my-bucket/*",
},
},
}),
});
});
package main
import (
"encoding/json"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/eks"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
tmpJSON0, err := json.Marshal(map[string]interface{}{
"Version": "2012-10-17",
"Statement": []map[string]interface{}{
map[string]interface{}{
"Effect": "Allow",
"Action": []string{
"s3:GetObject",
},
"Resource": "arn:aws:s3:::my-bucket/*",
},
},
})
if err != nil {
return err
}
json0 := string(tmpJSON0)
_, err = eks.NewPodIdentityAssociation(ctx, "example", &eks.PodIdentityAssociationArgs{
ClusterName: pulumi.Any(exampleAwsEksCluster.Name),
Namespace: pulumi.String("example"),
ServiceAccount: pulumi.String("example-sa"),
RoleArn: pulumi.Any(exampleAwsIamRole.Arn),
DisableSessionTags: pulumi.Bool(true),
Policy: pulumi.String(json0),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_eks_podidentityassociation" "example" {
cluster_name = exampleAwsEksCluster.name
namespace = "example"
service_account = "example-sa"
role_arn = exampleAwsIamRole.arn
disable_session_tags = true
policy = jsonencode({
"Version" = "2012-10-17"
"Statement" = [{
"Effect" = "Allow"
"Action" = ["s3:GetObject"]
"Resource" = "arn:aws:s3:::my-bucket/*"
}]
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.eks.PodIdentityAssociation;
import com.pulumi.aws.eks.PodIdentityAssociationArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new PodIdentityAssociation("example", PodIdentityAssociationArgs.builder()
.clusterName(exampleAwsEksCluster.name())
.namespace("example")
.serviceAccount("example-sa")
.roleArn(exampleAwsIamRole.arn())
.disableSessionTags(true)
.policy(serializeJson(
jsonObject(
jsonProperty("Version", "2012-10-17"),
jsonProperty("Statement", jsonArray(jsonObject(
jsonProperty("Effect", "Allow"),
jsonProperty("Action", jsonArray("s3:GetObject")),
jsonProperty("Resource", "arn:aws:s3:::my-bucket/*")
)))
)))
.build());
}
}
resources:
example:
type: aws:eks:PodIdentityAssociation
properties:
clusterName: ${exampleAwsEksCluster.name}
namespace: example
serviceAccount: example-sa
roleArn: ${exampleAwsIamRole.arn}
disableSessionTags: true
policy:
fn::toJSON:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource: arn:aws:s3:::my-bucket/*
Basic Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const assumeRole = aws.iam.getPolicyDocument({
statements: [{
principals: [{
type: "Service",
identifiers: ["pods.eks.amazonaws.com"],
}],
effect: "Allow",
actions: [
"sts:AssumeRole",
"sts:TagSession",
],
}],
});
const example = new aws.iam.Role("example", {
name: "eks-pod-identity-example",
assumeRolePolicy: assumeRole.then(assumeRole => assumeRole.json),
});
const exampleS3 = new aws.iam.RolePolicyAttachment("example_s3", {
policyArn: "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess",
role: example.name,
});
const examplePodIdentityAssociation = new aws.eks.PodIdentityAssociation("example", {
clusterName: exampleAwsEksCluster.name,
namespace: "example",
serviceAccount: "example-sa",
roleArn: example.arn,
});
import pulumi
import pulumi_aws as aws
assume_role = aws.iam.get_policy_document(statements=[{
"principals": [{
"type": "Service",
"identifiers": ["pods.eks.amazonaws.com"],
}],
"effect": "Allow",
"actions": [
"sts:AssumeRole",
"sts:TagSession",
],
}])
example = aws.iam.Role("example",
name="eks-pod-identity-example",
assume_role_policy=assume_role.json)
example_s3 = aws.iam.RolePolicyAttachment("example_s3",
policy_arn="arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess",
role=example.name)
example_pod_identity_association = aws.eks.PodIdentityAssociation("example",
cluster_name=example_aws_eks_cluster["name"],
namespace="example",
service_account="example-sa",
role_arn=example.arn)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var assumeRole = Aws.Iam.GetPolicyDocument.Invoke(new()
{
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "Service",
Identifiers = new[]
{
"pods.eks.amazonaws.com",
},
},
},
Effect = "Allow",
Actions = new[]
{
"sts:AssumeRole",
"sts:TagSession",
},
},
},
});
var example = new Aws.Iam.Role("example", new()
{
Name = "eks-pod-identity-example",
AssumeRolePolicy = assumeRole.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
var exampleS3 = new Aws.Iam.RolePolicyAttachment("example_s3", new()
{
PolicyArn = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess",
Role = example.Name,
});
var examplePodIdentityAssociation = new Aws.Eks.PodIdentityAssociation("example", new()
{
ClusterName = exampleAwsEksCluster.Name,
Namespace = "example",
ServiceAccount = "example-sa",
RoleArn = example.Arn,
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/eks"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
assumeRole, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
Statements: []iam.GetPolicyDocumentStatement{
{
Principals: []iam.GetPolicyDocumentStatementPrincipal{
{
Type: "Service",
Identifiers: []string{
"pods.eks.amazonaws.com",
},
},
},
Effect: pulumi.StringRef("Allow"),
Actions: []string{
"sts:AssumeRole",
"sts:TagSession",
},
},
},
}, nil)
if err != nil {
return err
}
example, err := iam.NewRole(ctx, "example", &iam.RoleArgs{
Name: pulumi.String("eks-pod-identity-example"),
AssumeRolePolicy: pulumi.String(assumeRole.Json),
})
if err != nil {
return err
}
_, err = iam.NewRolePolicyAttachment(ctx, "example_s3", &iam.RolePolicyAttachmentArgs{
PolicyArn: pulumi.String("arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"),
Role: example.Name,
})
if err != nil {
return err
}
_, err = eks.NewPodIdentityAssociation(ctx, "example", &eks.PodIdentityAssociationArgs{
ClusterName: pulumi.Any(exampleAwsEksCluster.Name),
Namespace: pulumi.String("example"),
ServiceAccount: pulumi.String("example-sa"),
RoleArn: example.Arn,
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
data "aws_iam_getpolicydocument" "assumeRole" {
statements {
principals {
type = "Service"
identifiers = ["pods.eks.amazonaws.com"]
}
effect = "Allow"
actions = ["sts:AssumeRole", "sts:TagSession"]
}
}
resource "aws_iam_role" "example" {
name = "eks-pod-identity-example"
assume_role_policy = data.aws_iam_getpolicydocument.assumeRole.json
}
resource "aws_iam_rolepolicyattachment" "example_s3" {
policy_arn = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
role = aws_iam_role.example.name
}
resource "aws_eks_podidentityassociation" "example" {
cluster_name = exampleAwsEksCluster.name
namespace = "example"
service_account = "example-sa"
role_arn = aws_iam_role.example.arn
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs;
import com.pulumi.aws.iam.Role;
import com.pulumi.aws.iam.RoleArgs;
import com.pulumi.aws.iam.RolePolicyAttachment;
import com.pulumi.aws.iam.RolePolicyAttachmentArgs;
import com.pulumi.aws.eks.PodIdentityAssociation;
import com.pulumi.aws.eks.PodIdentityAssociationArgs;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var assumeRole = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("Service")
.identifiers("pods.eks.amazonaws.com")
.build())
.effect("Allow")
.actions(
"sts:AssumeRole",
"sts:TagSession")
.build())
.build());
var example = new Role("example", RoleArgs.builder()
.name("eks-pod-identity-example")
.assumeRolePolicy(assumeRole.json())
.build());
var exampleS3 = new RolePolicyAttachment("exampleS3", RolePolicyAttachmentArgs.builder()
.policyArn("arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess")
.role(example.name())
.build());
var examplePodIdentityAssociation = new PodIdentityAssociation("examplePodIdentityAssociation", PodIdentityAssociationArgs.builder()
.clusterName(exampleAwsEksCluster.name())
.namespace("example")
.serviceAccount("example-sa")
.roleArn(example.arn())
.build());
}
}
resources:
example:
type: aws:iam:Role
properties:
name: eks-pod-identity-example
assumeRolePolicy: ${assumeRole.json}
exampleS3:
type: aws:iam:RolePolicyAttachment
name: example_s3
properties:
policyArn: arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
role: ${example.name}
examplePodIdentityAssociation:
type: aws:eks:PodIdentityAssociation
name: example
properties:
clusterName: ${exampleAwsEksCluster.name}
namespace: example
serviceAccount: example-sa
roleArn: ${example.arn}
variables:
assumeRole:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
statements:
- principals:
- type: Service
identifiers:
- pods.eks.amazonaws.com
effect: Allow
actions:
- sts:AssumeRole
- sts:TagSession
Import
Identity Schema
Required
clusterName(String) Name of the EKS Cluster.associationId(String) ID of the association.
Optional
accountId(String) AWS Account where this resource is managed.region(String) Region where this resource is managed.
Using pulumi import, import Pod Identity Associations using clusterName and associationId separated by a comma (,). For example:
$ pulumi import aws:eks/podIdentityAssociation:PodIdentityAssociation example example-cluster,a-yrpsdroc4ei7k6xps
Constructors
- PodIdentityAssociation(String name, {PodIdentityAssociationArgs? args, CustomResourceOptions? options})
-
Creates a new PodIdentityAssociation.
nameThe Pulumi resource name.argsArguments used to configure this PodIdentityAssociation. The set of arguments for PodIdentityAssociation.optionsResource options controlling this resource's behavior. - PodIdentityAssociation.reference(String urn)
- Creates a typed reference to an existing PodIdentityAssociation resource.
Properties
-
associationArn
↔ Output<
String> -
ARN of the association.
latefinal
-
associationId
↔ Output<
String> -
The ID of the association.
latefinal
-
childResources
→ Set<
Resource> -
finalinherited
-
clusterName
↔ Output<
String> -
The name of the cluster to create the association in.
latefinal
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
disableSessionTags
↔ Output<
bool> -
Disable the tags that are automatically added to role session by Amazon EKS. Must be set to
truewhenpolicyis specified.latefinal -
externalId
↔ Output<
String> -
The unique identifier for this association for a target IAM role. You put this value in the trust policy of the target role, in a Condition to match the sts.ExternalId.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
namespace
↔ Output<
String> -
The name of the Kubernetes namespace inside the cluster to create the association in. The service account and the pods that use the service account must be in this namespace.
latefinal
-
policy
↔ Output<
String?> -
An IAM policy in JSON format (as an escaped string) that applies additional restrictions to this Pod Identity association beyond the IAM policies attached to the IAM role. The effective permissions are the intersection of the role's policies and this policy, allowing you to enforce least privilege across multiple associations that share the same role. Requires
disableSessionTags = true.latefinal -
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
-
roleArn
↔ Output<
String> -
ARN of the IAM role to associate with the service account. The EKS Pod Identity agent manages credentials to assume this role for applications in the containers in the pods that use this service account.
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
serviceAccount
↔ Output<
String> -
The name of the Kubernetes service account inside the cluster to associate the IAM credentials with.
latefinal
-
Key-value map of resource tags. If configured with a provider
defaultTagsconfiguration block present, tags with matching keys will overwrite those defined at the provider-level.latefinal -
A map of tags assigned to the resource, including those inherited from the provider
defaultTagsconfiguration block.latefinal -
targetRoleArn
↔ Output<
String?> -
ARN of the IAM role to be chained to the the IAM role specified as
roleArn.latefinal -
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {PodIdentityAssociationState? state, CustomResourceOptions? options}) → PodIdentityAssociation -
Gets an existing PodIdentityAssociation resource's state with the given
nameandid.