See: Description
| Interface | Description |
|---|---|
| AddToPrincipalPolicyResult |
(experimental) Result of calling `addToPrincipalPolicy`.
|
| AddToResourcePolicyResult |
(experimental) Result of calling addToResourcePolicy.
|
| CfnAccessKeyProps |
Properties for defining a `AWS::IAM::AccessKey`.
|
| CfnGroup.PolicyProperty | |
| CfnGroupProps |
Properties for defining a `AWS::IAM::Group`.
|
| CfnInstanceProfileProps |
Properties for defining a `AWS::IAM::InstanceProfile`.
|
| CfnManagedPolicyProps |
Properties for defining a `AWS::IAM::ManagedPolicy`.
|
| CfnOIDCProviderProps |
Properties for defining a `AWS::IAM::OIDCProvider`.
|
| CfnPolicyProps |
Properties for defining a `AWS::IAM::Policy`.
|
| CfnRole.PolicyProperty | |
| CfnRoleProps |
Properties for defining a `AWS::IAM::Role`.
|
| CfnSAMLProviderProps |
Properties for defining a `AWS::IAM::SAMLProvider`.
|
| CfnServerCertificateProps |
Properties for defining a `AWS::IAM::ServerCertificate`.
|
| CfnServiceLinkedRoleProps |
Properties for defining a `AWS::IAM::ServiceLinkedRole`.
|
| CfnUser.LoginProfileProperty | |
| CfnUser.PolicyProperty | |
| CfnUserProps |
Properties for defining a `AWS::IAM::User`.
|
| CfnUserToGroupAdditionProps |
Properties for defining a `AWS::IAM::UserToGroupAddition`.
|
| CfnVirtualMFADeviceProps |
Properties for defining a `AWS::IAM::VirtualMFADevice`.
|
| CommonGrantOptions |
(experimental) Basic options for a grant operation.
|
| FromRoleArnOptions |
(experimental) Options allowing customizing the behavior of
Role.fromRoleArn. |
| GrantOnPrincipalAndResourceOptions |
(experimental) Options for a grant operation to both identity and resource.
|
| GrantOnPrincipalOptions |
(experimental) Options for a grant operation that only applies to principals.
|
| GrantWithResourceOptions |
(experimental) Options for a grant operation.
|
| GroupProps |
(experimental) Properties for defining an IAM group.
|
| IGrantable |
(experimental) Any object that has an associated principal that a permission can be granted to.
|
| IGrantable.Jsii$Default |
Internal default implementation for
IGrantable. |
| IGroup |
(experimental) Represents an IAM Group.
|
| IGroup.Jsii$Default |
Internal default implementation for
IGroup. |
| IIdentity |
(experimental) A construct that represents an IAM principal, such as a user, group or role.
|
| IIdentity.Jsii$Default |
Internal default implementation for
IIdentity. |
| IManagedPolicy |
(experimental) A managed policy.
|
| IManagedPolicy.Jsii$Default |
Internal default implementation for
IManagedPolicy. |
| IOpenIdConnectProvider |
(experimental) Represents an IAM OpenID Connect provider.
|
| IOpenIdConnectProvider.Jsii$Default |
Internal default implementation for
IOpenIdConnectProvider. |
| IPolicy |
(experimental) Represents an IAM Policy.
|
| IPolicy.Jsii$Default |
Internal default implementation for
IPolicy. |
| IPrincipal |
(experimental) Represents a logical IAM principal.
|
| IPrincipal.Jsii$Default |
Internal default implementation for
IPrincipal. |
| IResourceWithPolicy |
(experimental) A resource with a resource policy that can be added to.
|
| IResourceWithPolicy.Jsii$Default |
Internal default implementation for
IResourceWithPolicy. |
| IRole |
(experimental) A Role object.
|
| IRole.Jsii$Default |
Internal default implementation for
IRole. |
| ISamlProvider |
(experimental) A SAML provider.
|
| ISamlProvider.Jsii$Default |
Internal default implementation for
ISamlProvider. |
| IUser |
(experimental) Represents an IAM user.
|
| IUser.Jsii$Default |
Internal default implementation for
IUser. |
| LazyRoleProps |
(experimental) Properties for defining a LazyRole.
|
| ManagedPolicyProps |
(experimental) Properties for defining an IAM managed policy.
|
| OpenIdConnectProviderProps |
(experimental) Initialization properties for `OpenIdConnectProvider`.
|
| PolicyDocumentProps |
(experimental) Properties for a new PolicyDocument.
|
| PolicyProps |
(experimental) Properties for defining an IAM inline policy document.
|
| PolicyStatementProps |
(experimental) Interface for creating a policy statement.
|
| RoleProps |
(experimental) Properties for defining an IAM Role.
|
| SamlProviderProps |
(experimental) Properties for a SAML provider.
|
| ServicePrincipalOpts |
(experimental) Options for a service principal.
|
| UnknownPrincipalProps |
(experimental) Properties for an UnknownPrincipal.
|
| UserAttributes |
(experimental) Represents a user defined outside of this stack.
|
| UserProps |
(experimental) Properties for defining an IAM user.
|
| Class | Description |
|---|---|
| AccountPrincipal |
(experimental) Specify AWS account ID as the principal entity in a policy to delegate authority to the account.
|
| AccountRootPrincipal |
(experimental) Use the AWS account into which a stack is deployed as the principal entity in a policy.
|
| AddToPrincipalPolicyResult.Builder |
A builder for
AddToPrincipalPolicyResult |
| AddToPrincipalPolicyResult.Jsii$Proxy |
An implementation for
AddToPrincipalPolicyResult |
| AddToResourcePolicyResult.Builder |
A builder for
AddToResourcePolicyResult |
| AddToResourcePolicyResult.Jsii$Proxy |
An implementation for
AddToResourcePolicyResult |
| AnyPrincipal |
(experimental) A principal representing all identities in all accounts.
|
| ArnPrincipal |
(experimental) Specify a principal by the Amazon Resource Name (ARN).
|
| CanonicalUserPrincipal |
(experimental) A policy principal for canonicalUserIds - useful for S3 bucket policies that use Origin Access identities.
|
| CfnAccessKey |
A CloudFormation `AWS::IAM::AccessKey`.
|
| CfnAccessKey.Builder |
A fluent builder for
CfnAccessKey. |
| CfnAccessKeyProps.Builder |
A builder for
CfnAccessKeyProps |
| CfnAccessKeyProps.Jsii$Proxy |
An implementation for
CfnAccessKeyProps |
| CfnGroup |
A CloudFormation `AWS::IAM::Group`.
|
| CfnGroup.Builder |
A fluent builder for
CfnGroup. |
| CfnGroup.PolicyProperty.Builder |
A builder for
CfnGroup.PolicyProperty |
| CfnGroup.PolicyProperty.Jsii$Proxy |
An implementation for
CfnGroup.PolicyProperty |
| CfnGroupProps.Builder |
A builder for
CfnGroupProps |
| CfnGroupProps.Jsii$Proxy |
An implementation for
CfnGroupProps |
| CfnInstanceProfile |
A CloudFormation `AWS::IAM::InstanceProfile`.
|
| CfnInstanceProfile.Builder |
A fluent builder for
CfnInstanceProfile. |
| CfnInstanceProfileProps.Builder |
A builder for
CfnInstanceProfileProps |
| CfnInstanceProfileProps.Jsii$Proxy |
An implementation for
CfnInstanceProfileProps |
| CfnManagedPolicy |
A CloudFormation `AWS::IAM::ManagedPolicy`.
|
| CfnManagedPolicy.Builder |
A fluent builder for
CfnManagedPolicy. |
| CfnManagedPolicyProps.Builder |
A builder for
CfnManagedPolicyProps |
| CfnManagedPolicyProps.Jsii$Proxy |
An implementation for
CfnManagedPolicyProps |
| CfnOIDCProvider |
A CloudFormation `AWS::IAM::OIDCProvider`.
|
| CfnOIDCProvider.Builder |
A fluent builder for
CfnOIDCProvider. |
| CfnOIDCProviderProps.Builder |
A builder for
CfnOIDCProviderProps |
| CfnOIDCProviderProps.Jsii$Proxy |
An implementation for
CfnOIDCProviderProps |
| CfnPolicy |
A CloudFormation `AWS::IAM::Policy`.
|
| CfnPolicy.Builder |
A fluent builder for
CfnPolicy. |
| CfnPolicyProps.Builder |
A builder for
CfnPolicyProps |
| CfnPolicyProps.Jsii$Proxy |
An implementation for
CfnPolicyProps |
| CfnRole |
A CloudFormation `AWS::IAM::Role`.
|
| CfnRole.Builder |
A fluent builder for
CfnRole. |
| CfnRole.PolicyProperty.Builder |
A builder for
CfnRole.PolicyProperty |
| CfnRole.PolicyProperty.Jsii$Proxy |
An implementation for
CfnRole.PolicyProperty |
| CfnRoleProps.Builder |
A builder for
CfnRoleProps |
| CfnRoleProps.Jsii$Proxy |
An implementation for
CfnRoleProps |
| CfnSAMLProvider |
A CloudFormation `AWS::IAM::SAMLProvider`.
|
| CfnSAMLProvider.Builder |
A fluent builder for
CfnSAMLProvider. |
| CfnSAMLProviderProps.Builder |
A builder for
CfnSAMLProviderProps |
| CfnSAMLProviderProps.Jsii$Proxy |
An implementation for
CfnSAMLProviderProps |
| CfnServerCertificate |
A CloudFormation `AWS::IAM::ServerCertificate`.
|
| CfnServerCertificate.Builder |
A fluent builder for
CfnServerCertificate. |
| CfnServerCertificateProps.Builder |
A builder for
CfnServerCertificateProps |
| CfnServerCertificateProps.Jsii$Proxy |
An implementation for
CfnServerCertificateProps |
| CfnServiceLinkedRole |
A CloudFormation `AWS::IAM::ServiceLinkedRole`.
|
| CfnServiceLinkedRole.Builder |
A fluent builder for
CfnServiceLinkedRole. |
| CfnServiceLinkedRoleProps.Builder |
A builder for
CfnServiceLinkedRoleProps |
| CfnServiceLinkedRoleProps.Jsii$Proxy |
An implementation for
CfnServiceLinkedRoleProps |
| CfnUser |
A CloudFormation `AWS::IAM::User`.
|
| CfnUser.Builder |
A fluent builder for
CfnUser. |
| CfnUser.LoginProfileProperty.Builder |
A builder for
CfnUser.LoginProfileProperty |
| CfnUser.LoginProfileProperty.Jsii$Proxy |
An implementation for
CfnUser.LoginProfileProperty |
| CfnUser.PolicyProperty.Builder |
A builder for
CfnUser.PolicyProperty |
| CfnUser.PolicyProperty.Jsii$Proxy |
An implementation for
CfnUser.PolicyProperty |
| CfnUserProps.Builder |
A builder for
CfnUserProps |
| CfnUserProps.Jsii$Proxy |
An implementation for
CfnUserProps |
| CfnUserToGroupAddition |
A CloudFormation `AWS::IAM::UserToGroupAddition`.
|
| CfnUserToGroupAddition.Builder |
A fluent builder for
CfnUserToGroupAddition. |
| CfnUserToGroupAdditionProps.Builder |
A builder for
CfnUserToGroupAdditionProps |
| CfnUserToGroupAdditionProps.Jsii$Proxy |
An implementation for
CfnUserToGroupAdditionProps |
| CfnVirtualMFADevice |
A CloudFormation `AWS::IAM::VirtualMFADevice`.
|
| CfnVirtualMFADevice.Builder |
A fluent builder for
CfnVirtualMFADevice. |
| CfnVirtualMFADeviceProps.Builder |
A builder for
CfnVirtualMFADeviceProps |
| CfnVirtualMFADeviceProps.Jsii$Proxy |
An implementation for
CfnVirtualMFADeviceProps |
| CommonGrantOptions.Builder |
A builder for
CommonGrantOptions |
| CommonGrantOptions.Jsii$Proxy |
An implementation for
CommonGrantOptions |
| CompositeDependable |
(experimental) Composite dependable.
|
| CompositePrincipal |
(experimental) Represents a principal that has multiple types of principals.
|
| FederatedPrincipal |
(experimental) Principal entity that represents a federated identity provider such as Amazon Cognito, that can be used to provide temporary security credentials to users who have been authenticated.
|
| FromRoleArnOptions.Builder |
A builder for
FromRoleArnOptions |
| FromRoleArnOptions.Jsii$Proxy |
An implementation for
FromRoleArnOptions |
| Grant |
(experimental) Result of a grant() operation.
|
| GrantOnPrincipalAndResourceOptions.Builder |
A builder for
GrantOnPrincipalAndResourceOptions |
| GrantOnPrincipalAndResourceOptions.Jsii$Proxy |
An implementation for
GrantOnPrincipalAndResourceOptions |
| GrantOnPrincipalOptions.Builder |
A builder for
GrantOnPrincipalOptions |
| GrantOnPrincipalOptions.Jsii$Proxy |
An implementation for
GrantOnPrincipalOptions |
| GrantWithResourceOptions.Builder |
A builder for
GrantWithResourceOptions |
| GrantWithResourceOptions.Jsii$Proxy |
An implementation for
GrantWithResourceOptions |
| Group |
(experimental) An IAM Group (collection of IAM users) lets you specify permissions for multiple users, which can make it easier to manage permissions for those users.
|
| Group.Builder |
(experimental) A fluent builder for
Group. |
| GroupProps.Builder |
A builder for
GroupProps |
| GroupProps.Jsii$Proxy |
An implementation for
GroupProps |
| IGrantable.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IGroup.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IIdentity.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IManagedPolicy.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IOpenIdConnectProvider.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IPolicy.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IPrincipal.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IResourceWithPolicy.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IRole.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| ISamlProvider.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| IUser.Jsii$Proxy |
A proxy class which represents a concrete javascript instance of this type.
|
| LazyRole |
(experimental) An IAM role that only gets attached to the construct tree once it gets used, not before.
|
| LazyRole.Builder |
(experimental) A fluent builder for
LazyRole. |
| LazyRoleProps.Builder |
A builder for
LazyRoleProps |
| LazyRoleProps.Jsii$Proxy |
An implementation for
LazyRoleProps |
| ManagedPolicy |
(experimental) Managed policy.
|
| ManagedPolicy.Builder |
(experimental) A fluent builder for
ManagedPolicy. |
| ManagedPolicyProps.Builder |
A builder for
ManagedPolicyProps |
| ManagedPolicyProps.Jsii$Proxy |
An implementation for
ManagedPolicyProps |
| OpenIdConnectPrincipal |
(experimental) A principal that represents a federated identity provider as from a OpenID Connect provider.
|
| OpenIdConnectProvider |
(experimental) IAM OIDC identity providers are entities in IAM that describe an external identity provider (IdP) service that supports the OpenID Connect (OIDC) standard, such as Google or Salesforce.
|
| OpenIdConnectProvider.Builder |
(experimental) A fluent builder for
OpenIdConnectProvider. |
| OpenIdConnectProviderProps.Builder |
A builder for
OpenIdConnectProviderProps |
| OpenIdConnectProviderProps.Jsii$Proxy |
An implementation for
OpenIdConnectProviderProps |
| OrganizationPrincipal |
(experimental) A principal that represents an AWS Organization.
|
| PermissionsBoundary |
(experimental) Modify the Permissions Boundaries of Users and Roles in a construct tree.
|
| Policy |
(experimental) The AWS::IAM::Policy resource associates an IAM policy with IAM users, roles, or groups.
|
| Policy.Builder |
(experimental) A fluent builder for
Policy. |
| PolicyDocument |
(experimental) A PolicyDocument is a collection of statements.
|
| PolicyDocument.Builder |
(experimental) A fluent builder for
PolicyDocument. |
| PolicyDocumentProps.Builder |
A builder for
PolicyDocumentProps |
| PolicyDocumentProps.Jsii$Proxy |
An implementation for
PolicyDocumentProps |
| PolicyProps.Builder |
A builder for
PolicyProps |
| PolicyProps.Jsii$Proxy |
An implementation for
PolicyProps |
| PolicyStatement |
(experimental) Represents a statement in an IAM policy document.
|
| PolicyStatement.Builder |
(experimental) A fluent builder for
PolicyStatement. |
| PolicyStatementProps.Builder |
A builder for
PolicyStatementProps |
| PolicyStatementProps.Jsii$Proxy |
An implementation for
PolicyStatementProps |
| PrincipalBase |
(experimental) Base class for policy principals.
|
| PrincipalPolicyFragment |
(experimental) A collection of the fields in a PolicyStatement that can be used to identify a principal.
|
| PrincipalWithConditions |
(experimental) An IAM principal with additional conditions specifying when the policy is in effect.
|
| Role |
(experimental) IAM Role.
|
| Role.Builder |
(experimental) A fluent builder for
Role. |
| RoleProps.Builder |
A builder for
RoleProps |
| RoleProps.Jsii$Proxy |
An implementation for
RoleProps |
| SamlConsolePrincipal |
(experimental) Principal entity that represents a SAML federated identity provider for programmatic and AWS Management Console access.
|
| SamlMetadataDocument |
(experimental) A SAML metadata document.
|
| SamlPrincipal |
(experimental) Principal entity that represents a SAML federated identity provider.
|
| SamlProvider |
(experimental) A SAML provider.
|
| SamlProvider.Builder |
(experimental) A fluent builder for
SamlProvider. |
| SamlProviderProps.Builder |
A builder for
SamlProviderProps |
| SamlProviderProps.Jsii$Proxy |
An implementation for
SamlProviderProps |
| ServicePrincipal |
(experimental) An IAM principal that represents an AWS service (i.e.
|
| ServicePrincipal.Builder |
(experimental) A fluent builder for
ServicePrincipal. |
| ServicePrincipalOpts.Builder |
A builder for
ServicePrincipalOpts |
| ServicePrincipalOpts.Jsii$Proxy |
An implementation for
ServicePrincipalOpts |
| UnknownPrincipal |
(experimental) A principal for use in resources that need to have a role but it's unknown.
|
| UnknownPrincipal.Builder |
(experimental) A fluent builder for
UnknownPrincipal. |
| UnknownPrincipalProps.Builder |
A builder for
UnknownPrincipalProps |
| UnknownPrincipalProps.Jsii$Proxy |
An implementation for
UnknownPrincipalProps |
| User |
(experimental) Define a new IAM user.
|
| User.Builder |
(experimental) A fluent builder for
User. |
| UserAttributes.Builder |
A builder for
UserAttributes |
| UserAttributes.Jsii$Proxy |
An implementation for
UserAttributes |
| UserProps.Builder |
A builder for
UserProps |
| UserProps.Jsii$Proxy |
An implementation for
UserProps |
| WebIdentityPrincipal |
(experimental) A principal that represents a federated identity provider as Web Identity such as Cognito, Amazon, Facebook, Google, etc.
|
| Enum | Description |
|---|---|
| Effect |
(experimental) The Effect element of an IAM policy.
|
---
Define a role and add permissions to it. This will automatically create and attach an IAM policy to the role:
Define a policy and attach it to groups, users and roles. Note that it is possible to attach
the policy either by calling xxx.attachInlinePolicy(policy) or policy.attachToXxx(xxx).
attaching policies to user and group
Managed policies can be attached using xxx.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName(policyName)):
Many of the AWS CDK resources have grant* methods that allow you to grant other resources access to that resource. As an example, the following code gives a Lambda function write permissions (Put, Update, Delete) to a DynamoDB table.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826 Function fn = new Function(this, "Function", functionProps); Object table = new Table(this, "Table", tableProps); table.grantWriteData(fn);
The more generic grant method allows you to give specific permissions to a resource:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826 Function fn = new Function(this, "Function", functionProps); Object table = new Table(this, "Table", tableProps); table.grant(fn, "dynamodb:PutItem");
The grant* methods accept an IGrantable object. This interface is implemented by IAM principlal resources (groups, users and roles) and resources that assume a role such as a Lambda function, EC2 instance or a Codebuild project.
You can find which grant* methods exist for a resource in the AWS CDK API Reference.
Many AWS resources require Roles to operate. These Roles define the AWS API calls an instance or other AWS service is allowed to make.
Creating Roles and populating them with the right permissions Statements is a necessary but tedious part of setting up AWS infrastructure. In order to help you focus on your business logic, CDK will take care of creating roles and populating them with least-privilege permissions automatically.
All constructs that require Roles will create one for you if don't specify
one at construction time. Permissions will be added to that role
automatically if you associate the construct with other constructs from the
AWS Construct Library (for example, if you tell an AWS CodePipeline to trigger
an AWS Lambda Function, the Pipeline's Role will automatically get
lambda:InvokeFunction permissions on that particular Lambda Function),
or if you explicitly grant permissions using grant functions (see the
previous section).
You may prefer to manage a Role's permissions yourself instead of having the CDK automatically manage them for you. This may happen in one of the following cases:
To prevent constructs from updating your Role's policy, pass the object
returned by myRole.withoutPolicyUpdates() instead of myRole itself.
For example, to have an AWS CodePipeline not automatically add the required permissions to trigger the expected targets, do the following:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Role role = new Role(this, "Role", new RoleProps()
.assumedBy(new ServicePrincipal("codepipeline.amazonaws.com"))
// custom description if desired
.description("This is a custom role..."));
Pipeline.Builder.create(this, "Pipeline")
// Give the Pipeline an immutable view of the Role
.role(role.withoutPolicyUpdates())
.build();
// You now have to manage the Role policies yourself
role.addToPolicy(new PolicyStatement(new PolicyStatementProps()
.actions(asList())
.resources(asList())));
If there are Roles in your account that have already been created which you
would like to use in your CDK application, you can use Role.fromRoleArn to
import them, as follows:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
IRole role = iam.Role.fromRoleArn(this, "Role", "arn:aws:iam::123456789012:role/MyExistingRole", new FromRoleArnOptions()
// Set 'mutable' to 'false' to use the role as-is and prevent adding new
// policies to it. The default is 'true', which means the role may be
// modified as part of the deployment.
.mutable(false));
If you need to create Roles that will be assumed by third parties, it is generally a good idea to require an ExternalId
to assume them. Configuring
an ExternalId works like this:
When we say Principal, we mean an entity you grant permissions to. This
entity can be an AWS Service, a Role, or something more abstract such as "all
users in this account" or even "all users in this organization". An
Identity is an IAM representing a single IAM entity that can have
a policy attached, one of Role, User, or Group.
When defining policy statements as part of an AssumeRole policy or as part of a
resource policy, statements would usually refer to a specific IAM principal
under Principal.
IAM principals are modeled as classes that derive from the iam.PolicyPrincipal
abstract class. Principal objects include principal type (string) and value
(array of string), optional set of conditions and the action that this principal
requires when it is used in an assume role policy document.
To add a principal to a policy statement you can either use the abstract
statement.addPrincipal, one of the concrete addXxxPrincipal methods:
addAwsPrincipal, addArnPrincipal or new ArnPrincipal(arn) for { "AWS": arn }addAwsAccountPrincipal or new AccountPrincipal(accountId) for { "AWS": account-arn }addServicePrincipal or new ServicePrincipal(service) for { "Service": service }addAccountRootPrincipal or new AccountRootPrincipal() for { "AWS": { "Ref: "AWS::AccountId" } }addCanonicalUserPrincipal or new CanonicalUserPrincipal(id) for { "CanonicalUser": id }addFederatedPrincipal or new FederatedPrincipal(federated, conditions, assumeAction) for
{ "Federated": arn } and a set of optional conditions and the assume role action to use.addAnyPrincipal or new AnyPrincipal for { "AWS": "*" }If multiple principals are added to the policy statement, they will be merged together:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
PolicyStatement statement = new PolicyStatement();
statement.addServicePrincipal("cloudwatch.amazonaws.com");
statement.addServicePrincipal("ec2.amazonaws.com");
statement.addArnPrincipal("arn:aws:boom:boom");
Will result in:
{
"Principal": {
"Service": [ "cloudwatch.amazonaws.com", "ec2.amazonaws.com" ],
"AWS": "arn:aws:boom:boom"
}
}
The CompositePrincipal class can also be used to define complex principals, for example:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Role role = new Role(this, "MyRole", new RoleProps()
.assumedBy(new CompositePrincipal(
new ServicePrincipal("ec2.amazonaws.com"),
new AccountPrincipal("1818188181818187272"))));
The PrincipalWithConditions class can be used to add conditions to a
principal, especially those that don't take a conditions parameter in their
constructor. The principal.withConditions() method can be used to create a
PrincipalWithConditions from an existing principal, for example:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
IPrincipal principal = new iam.AccountPrincipal('123456789000').withConditions(Map.of("StringEquals", Map.of("foo", "baz")));
NOTE: If you need to define an IAM condition that uses a token (such as a deploy-time attribute of another resource) in a JSON map key, use
CfnJsonto render this condition. See this test for an example.
The WebIdentityPrincipal class can be used as a principal for web identities like
Cognito, Amazon, Google or Facebook, for example:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
IPrincipal principal = new iam.WebIdentityPrincipal('cognito-identity.amazonaws.com').withConditions(Map.of(
"StringEquals", Map.of("cognito-identity.amazonaws.com:aud", "us-east-2:12345678-abcd-abcd-abcd-123456"),
"ForAnyValue:StringLike", Map.of("cognito-identity.amazonaws.com:amr", "unauthenticated")));
The PolicyDocument.fromJson and PolicyStatement.fromJson static methods can be used to parse JSON objects. For example:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
__object policyDocument = Map.of(
"Version", "2012-10-17",
"Statement", asList(Map.of(
"Sid", "FirstStatement",
"Effect", "Allow",
"Action", asList("iam:ChangePassword"),
"Resource", "*"), Map.of(
"Sid", "SecondStatement",
"Effect", "Allow",
"Action", "s3:ListAllMyBuckets",
"Resource", "*"), Map.of(
"Sid", "ThirdStatement",
"Effect", "Allow",
"Action", asList("s3:List*", "s3:Get*"),
"Resource", asList("arn:aws:s3:::confidential-data", "arn:aws:s3:::confidential-data/*"),
"Condition", Map.of("Bool", Map.of("aws:MultiFactorAuthPresent", "true")))));
PolicyDocument customPolicyDocument = iam.PolicyDocument.fromJson(policyDocument);
// You can pass this document as an initial document to a ManagedPolicy
// or inline Policy.
Object newManagedPolicy = ManagedPolicy.Builder.create(stack, "MyNewManagedPolicy")
.document(customPolicyDocument)
.build();
Object newPolicy = Policy.Builder.create(stack, "MyNewPolicy")
.document(customPolicyDocument)
.build();
Permissions
Boundaries
can be used as a mechanism to prevent privilege esclation by creating new
Roles. Permissions Boundaries are a Managed Policy, attached to Roles or
Users, that represent the maximum set of permissions they can have. The
effective set of permissions of a Role (or User) will be the intersection of
the Identity Policy and the Permissions Boundary attached to the Role (or
User). Permissions Boundaries are typically created by account
Administrators, and their use on newly created Roles will be enforced by
IAM policies.
It is possible to attach Permissions Boundaries to all Roles created in a construct tree all at once:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
// This imports an existing policy.
IManagedPolicy boundary = iam.ManagedPolicy.fromManagedPolicyArn(this, "Boundary", "arn:aws:iam::123456789012:policy/boundary");
// This creates a new boundary
ManagedPolicy boundary2 = new ManagedPolicy(this, "Boundary2", new ManagedPolicyProps()
.statements(asList(
new PolicyStatement(new PolicyStatementProps()
.effect(iam.Effect.getDENY())
.actions(asList("iam:*"))
.resources(asList("*"))))));
// Directly apply the boundary to a Role you create
iam.PermissionsBoundary.of(role).apply(boundary);
// Apply the boundary to an Role that was implicitly created for you
iam.PermissionsBoundary.of(lambdaFunction).apply(boundary);
// Apply the boundary to all Roles in a stack
iam.PermissionsBoundary.of(stack).apply(boundary);
// Remove a Permissions Boundary that is inherited, for example from the Stack level
iam.PermissionsBoundary.of(customResource).clear();
OIDC identity providers are entities in IAM that describe an external identity provider (IdP) service that supports the OpenID Connect (OIDC) standard, such as Google or Salesforce. You use an IAM OIDC identity provider when you want to establish trust between an OIDC-compatible IdP and your AWS account. This is useful when creating a mobile app or web application that requires access to AWS resources, but you don't want to create custom sign-in code or manage your own user identities. For more information about this scenario, see [About Web Identity Federation] and the relevant documentation in the [Amazon Cognito Identity Pools Developer Guide].
The following examples defines an OpenID Connect provider. Two client IDs (audiences) are will be able to send authentication requests to https://openid/connect.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
OpenIdConnectProvider provider = new OpenIdConnectProvider(this, "MyProvider", new OpenIdConnectProviderProps()
.url("https://openid/connect")
.clientIds(asList("myclient1", "myclient2")));
You can specify an optional list of thumbprints. If not specified, the
thumbprint of the root certificate authority (CA) will automatically be obtained
from the host as described
here.
Once you define an OpenID connect provider, you can use it with AWS services that expect an IAM OIDC provider. For example, when you define an Amazon Cognito identity pool you can reference the provider's ARN as follows:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
CfnIdentityPool.Builder.create(this, "IdentityPool")
.openIdConnectProviderArns(asList(myProvider.getOpenIdConnectProviderArn()))
// And the other properties for your identity pool
.allowUnauthenticatedIdentities(allowUnauthenticatedIdentities)
.build();
The OpenIdConnectPrincipal class can be used as a principal used with a OpenIdConnectProvider, for example:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
OpenIdConnectProvider provider = new OpenIdConnectProvider(this, "MyProvider", new OpenIdConnectProviderProps()
.url("https://openid/connect")
.clientIds(asList("myclient1", "myclient2")));
OpenIdConnectPrincipal principal = new OpenIdConnectPrincipal(provider);
An IAM SAML 2.0 identity provider is an entity in IAM that describes an external identity provider (IdP) service that supports the SAML 2.0 (Security Assertion Markup Language 2.0) standard. You use an IAM identity provider when you want to establish trust between a SAML-compatible IdP such as Shibboleth or Active Directory Federation Services and AWS, so that users in your organization can access AWS resources. IAM SAML identity providers are used as principals in an IAM trust policy.
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
new SamlProvider(this, "Provider", new SamlProviderProps()
.metadataDocument(iam.SamlMetadataDocument.fromFile("/path/to/saml-metadata-document.xml")));
The SamlPrincipal class can be used as a principal with a SamlProvider:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
SamlProvider provider = new SamlProvider(this, "Provider", new SamlProviderProps()
.metadataDocument(iam.SamlMetadataDocument.fromFile("/path/to/saml-metadata-document.xml")));
SamlPrincipal principal = SamlPrincipal.Builder.create(provider)Map.of(
"StringEquals",
.SAML:iss("issuer")
.build());
When creating a role for programmatic and AWS Management Console access, use the SamlConsolePrincipal
class:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
SamlProvider provider = new SamlProvider(this, "Provider", new SamlProviderProps()
.metadataDocument(iam.SamlMetadataDocument.fromFile("/path/to/saml-metadata-document.xml")));
new Role(this, "Role", new RoleProps()
.assumedBy(new SamlConsolePrincipal(provider)));
IAM manages users for your AWS account. To create a new user:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826 Object user = new User(this, "MyUser");
To import an existing user by name with path:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826 Object user = User.fromUserName(stack, "MyImportedUserByName", "johnsmith");
To import an existing user by ARN:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826 Object user = User.fromUserArn(this, "MyImportedUserByArn", "arn:aws:iam::123456789012:user/johnsmith");
To import an existing user by attributes:
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826
Object user = User.fromUserAttributes(stack, "MyImportedUserByAttributes", Map.of(
"userArn", "arn:aws:iam::123456789012:user/johnsmith"));
To add a user to a group (both for a new and imported user/group):
// Example automatically generated without compilation. See https://github.com/aws/jsii/issues/826 Object user = new User(this, "MyUser");// or User.fromUserName(stack, 'User', 'johnsmith'); Object group = new Group(this, "MyGroup");// or Group.fromGroupArn(stack, 'Group', 'arn:aws:iam::account-id:group/group-name'); user.addToGroup(group); // or group.addUser(user);
Copyright © 2021. All rights reserved.