<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: atsushi, sada</title>
    <description>The latest articles on DEV Community by atsushi, sada (@4su_para).</description>
    <link>https://dev.to/4su_para</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2628872%2Fce5b8aba-fde6-492d-93f0-7c288449e744.png</url>
      <title>DEV Community: atsushi, sada</title>
      <link>https://dev.to/4su_para</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/4su_para"/>
    <language>en</language>
    <item>
      <title>AWS-IAM Beginner perfect guide</title>
      <dc:creator>atsushi, sada</dc:creator>
      <pubDate>Sat, 18 Jan 2025 14:02:42 +0000</pubDate>
      <link>https://dev.to/4su_para/aws-iam-beginner-perfect-guide-7d7</link>
      <guid>https://dev.to/4su_para/aws-iam-beginner-perfect-guide-7d7</guid>
      <description>&lt;h2&gt;
  
  
  Authentication and Authorization
&lt;/h2&gt;

&lt;p&gt;In many cases, authentication and authorization are performed simultaneously, but they are fundamentally different concepts. Keeping this distinction in mind can make them easier to understand.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verification of identity&lt;/li&gt;
&lt;li&gt;Example

&lt;ul&gt;
&lt;li&gt;A server determines who is accessing it by validating an ID/password combination.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Authorization&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Granting access rights&lt;/li&gt;
&lt;li&gt;Example

&lt;ul&gt;
&lt;li&gt;Granting a user permission to access an S3 bucket.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bjsa4zxjdou69fbfg7v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8bjsa4zxjdou69fbfg7v.png" alt="Image description" width="800" height="709"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  term
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/IAM/latest/UserGuide/intro-structure.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These documents include explanations of basic terms and concepts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4uiqhi1s79llchu4svu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4uiqhi1s79llchu4svu.png" alt="Image description" width="542" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IAM Resources&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The user, group, role, policy, and identity provider objects that are stored in IAM. As with other AWS services, you can add, edit, and remove resources from IAM.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;IAM Identities

&lt;ul&gt;
&lt;li&gt;IAM user / IAM group / IAM role&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The IAM resource objects that are used to identify and group. You can attach a policy to an IAM identity. These include users, groups, and roles.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;IAM Entities

&lt;ul&gt;
&lt;li&gt;IAM resources used for authentication&lt;/li&gt;
&lt;li&gt;IAM user &amp;amp; IAM role&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The IAM resource objects that AWS uses for authentication. These include IAM users and roles.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Principals

&lt;ul&gt;
&lt;li&gt;The individuals or applications that use AWS services through IAM resources such as IAM users or IAM roles.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;A person or application that uses the AWS account root user, an IAM user, or an IAM role to sign in and make requests to AWS. Principals include federated users and assumed roles.&lt;/p&gt;

&lt;p&gt;A principal is a person or application that can make a request for an action or operation on an AWS resource. The principal is authenticated as the AWS account root user or an IAM entity to make requests to AWS.As a best practice, do not use your root user credentials for your daily work. Instead, create IAM entities (users and roles). You can also support federated users or programmatic access to allow an application to access your AWS account.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Others
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Federated User&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
    - "Federation" refers to user authentication integration between services.&lt;br&gt;&lt;br&gt;
        - It can also be described as "establishing a trust relationship between an external ID provider (e.g., Amazon, Facebook, Google, GitHub, etc.) and AWS."  &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    - Any Identity Provider (IdP) compatible with OIDC (OpenID Connect) or SAML 2.0 (Security Assertion Markup Language) can be used.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers.html&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Request&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
When a principal attempts to use the Management Console, API, or CLI, a request consisting of the following information is sent to AWS:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Actions or operations&lt;/strong&gt;: The actions in the Management Console or operations in the CLI/API that the principal wants to perform.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resources&lt;/strong&gt;: The AWS resource objects that are the targets of the action/operation.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Principal&lt;/strong&gt;: Information about the entity (user or application) sending the request. This includes policy information associated with the entity used by the principal.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environment data&lt;/strong&gt;: Information such as IP address, user agent, SSL status, and timestamp.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource data&lt;/strong&gt;: Data related to the requested resource.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This information is sent to AWS as the &lt;strong&gt;request context&lt;/strong&gt; and is used for authentication and authorization.  &lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Authentication&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
To send a request to AWS, the principal must be authenticated using credentials.&lt;br&gt;&lt;br&gt;
There are several ways to authenticate:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authenticating as the root user via the console: using the email address and password.
&lt;/li&gt;
&lt;li&gt;Authenticating as an IAM user via the console: using the account ID (or alias), username, and password.
&lt;/li&gt;
&lt;li&gt;Authenticating via API or CLI: using the access key and secret key.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using &lt;strong&gt;MFA&lt;/strong&gt; (Multi-Factor Authentication) enhances the security of authentication.  &lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Authorization&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Assume Role&lt;/strong&gt;: Temporarily assuming a role to gain specific permissions.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pass Role&lt;/strong&gt;: Allowing an entity to pass a role to another AWS service.
&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  ID - Identity
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;type of identity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/IAM/latest/UserGuide/id.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;IAM resources used for authentication include the following  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AWS account root user&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IAM users&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IAM user groups&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IAM roles&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Temporary credentials in IAM&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Issued by STS (Security Token Service)
&lt;/li&gt;
&lt;li&gt;See the STS section for details.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;strong&gt;AWS account root user&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_root-user.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_root-user.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you create an Amazon Web Services (AWS) account for the first time, you start with a single identity that has full access to all AWS services and resources in the account. This identity is called the root user of the AWS account. You can sign in as the root user using the email address and password you provided when creating the account.&lt;/p&gt;

&lt;p&gt;It is strongly recommended not to use the root user for everyday tasks, even for administrative tasks. Instead, follow the best practice of using the root user only to create the initial IAM user.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;IAM users&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An AWS Identity and Access Management (IAM) user is an entity that you create in AWS to represent the person or application that uses it to interact with AWS. A user in AWS consists of a name and credentials.&lt;br&gt;
...&lt;br&gt;
An IAM user is a resource in IAM that has associated credentials and permissions. An IAM user can represent a person or an application that uses its credentials to make AWS requests. This is typically referred to as a service account.&lt;br&gt;
If you choose to use the long-term credentials of an IAM user in your application, do not embed access keys directly into your application code. The AWS SDKs and the AWS Command Line Interface allow you to put access keys in known locations so that you do not have to keep them in code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An entity representing a user or application that uses AWS, consisting of a name and authentication credentials (console password, access keys).  &lt;/p&gt;

&lt;p&gt;There are several authentication methods for accessing AWS using an IAM user:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Console password&lt;/strong&gt;
Used to sign in to interactive sessions such as the Management Console.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ID/password&lt;/strong&gt;
Used when signing in to the Management Console.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access key ID / secret access key&lt;/strong&gt;
Used by programs and command-line tools.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To enhance authentication security, you can also configure MFA (multi-factor authentication).&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;IAM roles&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An IAM Identity with specific permissions that can be created in an AWS account. While it is similar to an IAM user in terms of being an AWS resource for authentication, it differs in several ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IAM users are generally intended for use by a specific individual, while IAM roles can be configured to be used by any person who requires them.
&lt;/li&gt;
&lt;li&gt;IAM users authenticate using long-term credentials (passwords and access keys), while IAM roles authenticate using temporary credentials.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other points:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Assume role" implies the concept of "taking on a role."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsnrl7mk445raxm268ta8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsnrl7mk445raxm268ta8.png" alt="Image description" width="629" height="404"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Roles terms and concepts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html#id_roles_terms-and-concepts" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html#id_roles_terms-and-concepts&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Trust Policy&lt;/strong&gt;
Defines who or what can assume (take on) a role.
In Terraform, this is represented by &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role#assume_role_policy" rel="noopener noreferrer"&gt;&lt;code&gt;aws_iam_role.assume_role_policy&lt;/code&gt;&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the console, it can be viewed under the "Trust relationships" tab.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Permission Policy&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Policies attached as identity-based policies.&lt;br&gt;&lt;br&gt;
These define what actions are allowed or denied for a particular entity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Principal&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
An entity in AWS that can perform actions or access resources.&lt;br&gt;&lt;br&gt;
Examples: AWS account root user, IAM user, IAM role.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;p&gt;&lt;strong&gt;Pass Role&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
To use many AWS services, you need to pass an IAM role to those services. For example, to use services like EC2 instances, Lambda functions, ECS, Batch, etc., you must configure the IAM role that these services will use.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Policy Template for Setting PassRole&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The policy specifies "which IAM role" can be "passed to which service/resource."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"iam:PassRole"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:iam::account-id:role/EC2-roles-for-XYZ"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Condition"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"StringEquals"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"iam:PassedToService"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ec2.amazonaws.com"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"StringLike"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"iam:AssociatedResourceARN"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:ec2:us-east-1:111122223333:instance/*"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:ec2:us-west-1:111122223333:instance/*"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why does AmazonEC2FullAccess not include iam:PassRole?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Allowing full access to EC2 instances, along with the ability to assign roles to instances via PassRole, could lead to privilege escalation. By assigning a powerful role to an instance and utilizing that role, users could potentially elevate their permissions.  &lt;/p&gt;

&lt;p&gt;For this reason, permissions for using services like EC2 and permissions for passing roles to those services (iam:PassRole) are separated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
IAM user &lt;code&gt;user_a&lt;/code&gt; needs the following setup to use an EC2 instance:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create the IAM role &lt;code&gt;EC2-roles-for-XYZ&lt;/code&gt;&lt;/strong&gt; that the EC2 instance will use.
Attach the necessary IAM policy to this role:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"A list of the permissions the role is allowed to use"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"A list of the resources the role is allowed to access"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Set up the trust relationship&lt;/strong&gt; for the EC2 service to assume the attached role:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"TrustPolicyStatementThatAllowsEC2ServiceToAssumeTheAttachedRole"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="nl"&gt;"Principal"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"Service"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ec2.amazonaws.com"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sts:AssumeRole"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Attach the following policy to allow IAM user &lt;code&gt;user_a&lt;/code&gt; to pass the role:&lt;/strong&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s2"&gt;"iam:GetRole"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="s2"&gt;"iam:PassRole"&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
           &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:iam::account-id:role/EC2-roles-for-XYZ"&lt;/span&gt;&lt;span class="w"&gt;
       &lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this configuration, &lt;code&gt;user_a&lt;/code&gt; can use the EC2 instance with the &lt;code&gt;EC2-roles-for-XYZ&lt;/code&gt; role.&lt;/p&gt;

&lt;p&gt;IAM: Pass an IAM role to a specific AWS service - AWS Identity and Access Management&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_iam-passrole-service.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_iam-passrole-service.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Grant a user permissions to pass a role to an AWS service - AWS Identity and Access Management&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;instance profile&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To grant access permissions to applications running on an EC2 instance using a role, a little additional configuration is required. Applications running on the EC2 instance are abstracted from AWS by the virtualized operating system. Due to this additional separation, a separate step is necessary to assign AWS roles and their associated permissions to the EC2 instance and allow the application to use them. This separate step involves creating an &lt;strong&gt;instance profile&lt;/strong&gt; that is attached to the instance.  &lt;/p&gt;

&lt;p&gt;An instance profile contains a role and provides temporary credentials for the role to the application running on the instance. These temporary credentials can be used in the application's API calls to grant access to resources or to restrict access to only the resources specified in the role. Only one role can be assigned to an EC2 instance at a time. All applications on the instance will share the same role and permissions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Use an IAM role to grant permissions to applications running on Amazon EC2 instances - AWS Identity and Access Management&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile" rel="noopener noreferrer"&gt;aws_iam_instance_profile | Resources | hashicorp/aws | Terraform | Terraform Registry&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;The confused deputy problem&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Docs&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/confused-deputy.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/confused-deputy.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/UserGuide/cross-service-confused-deputy-prevention.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/UserGuide/cross-service-confused-deputy-prevention.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/id_roles_create_for-user_externalid.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Blogs&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.classmethod.jp/articles/iam-role-externalid/" rel="noopener noreferrer"&gt;https://dev.classmethod.jp/articles/iam-role-externalid/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://qiita.com/hkak03key/items/a960b7523557f03bc098" rel="noopener noreferrer"&gt;https://qiita.com/hkak03key/items/a960b7523557f03bc098&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Point&lt;/p&gt;

&lt;p&gt;There is a well-known security issue called the "confused deputy problem."  When using third-party services based on AWS, if you configure your IAM Role in your AWS account with the entire AWS account of the third party as the Principal, anyone from the third party’s account could end up being able to use your IAM Role. This problem highlights the need for identifying users of third-party services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;External ID&lt;/strong&gt; is crucial as a countermeasure to this problem.&lt;br&gt;&lt;br&gt;
An example of a third-party service is Snowflake.&lt;br&gt;&lt;br&gt;
AWS does not treat the external ID as sensitive information.  &lt;/p&gt;

&lt;p&gt;The external ID is used to identify third-party users and is managed by the third-party service in such a way that it remains unique for each user. Therefore, the external ID is not considered confidential, much like a username for third-party service users.&lt;/p&gt;




&lt;h2&gt;
  
  
  STS - Security Token Service
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp.html" rel="noopener noreferrer"&gt;STS Basics&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;STS is an auxiliary service to IAM that creates and provides &lt;strong&gt;temporary security credentials&lt;/strong&gt; (temporary credentials).&lt;/p&gt;

&lt;p&gt;While temporary credentials function similarly to the long-term credentials (access keys) that IAM users use, there are key differences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;As the name suggests, temporary credentials have a short lifetime, typically ranging from a few minutes to a few hours. Once the expiration time passes, AWS will no longer authenticate them.&lt;/li&gt;
&lt;li&gt;Temporary credentials are not stored with the user but are dynamically generated and provided in response to the user's request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The advantages of using temporary credentials are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There is no need to embed credentials in applications, and because their lifetime is limited, there is no need to rotate or delete them when they are no longer needed.
For example, there will be no need to rotate or delete credentials when an employee leaves the company.&lt;/li&gt;
&lt;li&gt;It enables access to AWS resources without needing to create IAM identities for users.&lt;/li&gt;
&lt;li&gt;IAM roles and ID Federation rely on these temporary credentials to function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following blogs are very educational&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.classmethod.jp/articles/re-introduction-2022-aws-iam/" rel="noopener noreferrer"&gt;Re-introduction to AWS IAM&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://dev.classmethod.jp/articles/getfederetiontoken-assumerole-getsessiontoken/" rel="noopener noreferrer"&gt;GetFederationToken, AssumeRole, GetSessionToken&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STS Actions:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/id_credentials_temp_request.html" rel="noopener noreferrer"&gt;STS Actions Documentation&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AssumeRole&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AssumeRoleWithWebIdentity&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GetSessionToken&lt;/strong&gt;
When MFA is enabled for an IAM user, this action returns temporary credentials after successfully authenticating with an MFA device.
By properly using these temporary credentials, you can reduce the number of times the MFA device needs to be authenticated.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Policy
&lt;/h2&gt;

&lt;p&gt;A policy is used to manage authorizations for IAM identities (User/Group/Role). It expresses various permissions from three perspectives: "Action (which services)", "Resource (what functionality or scope)", and "Effect (Allow/Block)".&lt;/p&gt;

&lt;p&gt;For more details on policies, it is recommended to first read the &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html" rel="noopener noreferrer"&gt;IAM Policies and Permissions documentation&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Types of Policy&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Here are the types of IAM policies, classified in order of usage frequency:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Identity-based policies&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
These are policies that are attached to IAM users, groups, or roles. They control and restrict what actions the associated IAM identity can perform.&lt;br&gt;&lt;br&gt;
There are three types of identity-based policies:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AWS Managed Policies&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Customer Managed Policies&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inline Policies&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Resource-based policies&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
These policies grant permission to specific principals to perform actions on the attached resources and define the conditions under which these permissions apply.&lt;br&gt;&lt;br&gt;
Resource-based policies are often used for cross-account access.&lt;br&gt;&lt;br&gt;
Two major examples are:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;S3 Bucket Policy&lt;/strong&gt;
This can be configured using resources like &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy" rel="noopener noreferrer"&gt;&lt;code&gt;aws_s3_bucket_policy&lt;/code&gt;&lt;/a&gt; in Terraform.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IAM Role Trust Policy (Trust policy, assume_role_policy)&lt;/strong&gt;
This can be configured using resources like &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role#assume_role_policy" rel="noopener noreferrer"&gt;&lt;code&gt;aws_iam_role&lt;/code&gt;&lt;/a&gt; in Terraform.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;strong&gt;Rules of JSON Policy Document&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
For detailed information, refer to the &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements.html" rel="noopener noreferrer"&gt;IAM JSON Policy Elements Reference&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The top-level elements that can be specified in a policy document are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
You can specify either &lt;code&gt;2012-10-17&lt;/code&gt; or &lt;code&gt;2008-10-17&lt;/code&gt;, but the former is typically used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Statement&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This is the body of the policy. Multiple statements can be written in the form &lt;code&gt;"Statement": [{...},{...},{...}]&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Within each statement, you can include the following components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sid (Statement ID)&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
An optional identifier for the statement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Effect&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Specifies whether the action is allowed or denied. It can be &lt;code&gt;Allow&lt;/code&gt; or &lt;code&gt;Deny&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Action&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Specifies the AWS service operation (API) that is allowed or denied, such as &lt;code&gt;"Action": "s3:GetObject"&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
You can refer to various API references to see available actions.&lt;br&gt;&lt;br&gt;
Example: &lt;a href="https://docs.aws.amazon.com/ja_jp/service-authorization/latest/reference/reference_policies_actions-resources-contextkeys.html" rel="noopener noreferrer"&gt;S3 API Reference&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resource&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Specifies the ARN of the resources that the action applies to.&lt;br&gt;&lt;br&gt;
You can check the details of ARNs at &lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html" rel="noopener noreferrer"&gt;IAM ARN Reference&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Condition&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Describes the conditions that must be met for the policy to execute.&lt;br&gt;&lt;br&gt;
Examples include IP address restrictions, or using repository information from GitHub actions.&lt;br&gt;&lt;br&gt;
You can use conditions like &lt;code&gt;ForAllValues&lt;/code&gt; or &lt;code&gt;ForAnyValue&lt;/code&gt; to apply conditions to multiple keys or values.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Principal&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This is required for resource-based policies.&lt;br&gt;&lt;br&gt;
The &lt;code&gt;Principal&lt;/code&gt; is the IAM entity (such as IAM user or role) that can perform actions or access resources.&lt;br&gt;&lt;br&gt;
In IAM role trust policies, the &lt;code&gt;Principal&lt;/code&gt; element specifies who can assume the role.&lt;br&gt;&lt;br&gt;
In resource-based policies, the &lt;code&gt;Principal&lt;/code&gt; element specifies who can access the resource.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;ID-based Policy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An ID-based policy is a JSON document used to control the actions, resources, and conditions that an identity (such as a user, group, or role) can perform.&lt;/p&gt;

&lt;p&gt;There are three types of ID-based policies:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;AWS Managed Policy&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Customer Managed Policy&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inline Policy&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can find more details about these types of policies in the AWS documentation: &lt;a href="https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/access_policies_managed-vs-inline.html" rel="noopener noreferrer"&gt;Managed vs Inline Policies&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AWS Managed Policy&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;These are policies created and managed by AWS.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;Standalone policy&lt;/strong&gt; is a policy that exists as an independent AWS resource with an ARN (for example: &lt;code&gt;arn:aws:iam::aws:policy/IAMReadOnlyAccess&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;AWS Managed Policies can be searched for in the IAM Policies section, and they are usually accompanied by an icon next to the policy name to denote that they are managed by AWS.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Customer Managed Policy&lt;/strong&gt;&lt;br&gt;
A Customer Managed Policy is a standalone policy that can be created and managed within an account. Like AWS Managed Policies, it has an ARN and can be searched for in the IAM Policies section.&lt;/p&gt;

&lt;p&gt;For Terraform, the following resources are used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Resource: &lt;code&gt;aws_iam_policy&lt;/code&gt;&lt;/strong&gt; - This is used to create Managed Policies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource: &lt;code&gt;aws_iam_role_policy_attachment&lt;/code&gt;&lt;/strong&gt; - This is used to attach a Managed Policy to an IAM role.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource: &lt;code&gt;aws_iam_policy_attachment&lt;/code&gt;&lt;/strong&gt; - This is used to attach a Managed Policy to an IAM role, user, or group.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Inline Policy&lt;/strong&gt;&lt;br&gt;
An Inline Policy is a policy embedded within an IAM identity (such as a user, group, or role). Unlike Managed Policies, it does not have an ARN. While a Customer Managed Policy is linked to a policy page, an Inline Policy is embedded directly within the IAM identity, so there is no link to a separate policy page. &lt;/p&gt;

&lt;p&gt;For more information on this, see the AWS documentation on &lt;a href="https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#customer-managed-policies" rel="noopener noreferrer"&gt;Customer Managed Policies&lt;/a&gt; and &lt;a href="https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#inline-policies" rel="noopener noreferrer"&gt;Inline Policies&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Managed vs. Inline&lt;/strong&gt;&lt;br&gt;
When choosing between Managed and Inline policies, the decision largely depends on whether you want to reuse a policy or have a policy specific to a single identity.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Managed Policies&lt;/strong&gt;: These are standalone policies that can be created and managed independently of the IAM identity to which they are attached. They can be used across multiple IAM identities and are reusable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Inline Policies&lt;/strong&gt;: These are embedded directly within a specific IAM identity (user, group, or role). They are used for more specific or fine-grained permissions that are not shared across multiple identities.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more details, refer to the &lt;a href="https://docs.aws.amazon.com/ja_jp/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#choosing-managed-or-inline" rel="noopener noreferrer"&gt;AWS Documentation&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Resource-Based Policies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Resource-based policies are critical when granting access to resources, especially in cross-account scenarios. For example, when setting up access to an S3 bucket or IAM role, you may need to define who can access those resources using resource-based policies.&lt;/p&gt;

&lt;p&gt;When implementing cross-account access:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The IAM identity in Account A (the "principal") needs an identity-based policy that grants access to resources in Account B.&lt;/li&gt;
&lt;li&gt;The resource in Account B (such as an S3 bucket or IAM role) needs a resource-based policy that allows access from Account A.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this case, the resource-based policy explicitly defines the permissions for accessing the resource.&lt;/p&gt;

&lt;p&gt;For more information on how to evaluate policies, visit the following documentation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic.html#policy-eval-basics" rel="noopener noreferrer"&gt;Policy Evaluation Basics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_evaluation-logic-cross-account.html" rel="noopener noreferrer"&gt;Cross-Account Policy Evaluation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more on specific use cases such as restricting access to only certain IAM roles or enforcing session names, refer to the articles on DevelopersIO:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.classmethod.jp/articles/implementing-s3-bucket-access-for-specific-iam-roles/" rel="noopener noreferrer"&gt;IAM roles for specific access to S3&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.classmethod.jp/articles/using-sts-rolesessionname-condition/" rel="noopener noreferrer"&gt;Enforcing role session names using &lt;code&gt;sts:RoleSessionName&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>cloud</category>
      <category>security</category>
    </item>
  </channel>
</rss>
