Tutorial / Cram Notes

In Amazon DynamoDB, resource policies, also known as fine-grained access control policies, define permissions at the table level or even at the item and attribute level. These policies determine who can access your data and under what conditions.

Example DynamoDB resource policy

{
“Version”: “2012-10-17”,
“Statement”: [{
“Effect”: “Allow”,
“Principal”: {
“AWS”: “arn:aws:iam::ACCOUNT-ID:user/DynamoDBUser”
},
“Action”: “dynamodb:GetItem”,
“Resource”: “arn:aws:dynamodb:REGION:ACCOUNT-ID:table/YourTable”
}]
}

This policy gives a specific IAM user (“DynamoDBUser”) the permission to perform the GetItem operation on “YourTable”.

Amazon S3 Bucket Policies

Amazon S3 bucket policies are resource-based policies that you can attach to buckets to manage access to the objects in a bucket across AWS accounts. These policies offer a range of control options, from the ability to completely publicize a bucket to locking it down using various conditions such as IP range, referer, or encryption status.

Example S3 bucket policy

{
“Version”: “2012-10-17”,
“Statement”: [
{
“Effect”: “Allow”,
“Principal”: “*”,
“Action”: “s3:GetObject”,
“Resource”: “arn:aws:s3:::YourBucketName/*”,
“Condition”: {
“IpAddress”: {“aws:SourceIp”: “198.51.100.0/24”}
}
}
]
}

This policy allows any principal to perform the GetObject operation on the objects in “YourBucketName” when the request comes from the specified IP range.

AWS Key Management Service (AWS KMS) Key Policies

AWS KMS uses key policies as the primary way to control access to customer-managed keys. These key policies define who can use the keys and for what actions. They can also be combined with IAM policies for more versatile control. By default, the key policy allows access to the root user of the AWS account, and additional permissions must be explicitly granted.

Example AWS KMS key policy

{
“Version”: “2012-10-17”,
“Id”: “key-default-1”,
“Statement”: [
{
“Sid”: “Allow use of the key”,
“Effect”: “Allow”,
“Principal”: {
“AWS”: “arn:aws:iam::ACCOUNT-ID:role/YourIAMRole”
},
“Action”: [
“kms:Encrypt”,
“kms:Decrypt”
],
“Resource”: “*”
}
]
}

This policy gives a specific IAM role the ability to encrypt and decrypt data with the specified KMS key.

Comparison Table

Feature/Service DynamoDB Resource Policies Amazon S3 Bucket Policies AWS KMS Key Policies
Scope Table, Item, Attribute Bucket, Object Customer-managed keys
Principal Support AWS Accounts, IAM Users and Roles, Federated Users Any AWS Accounts, Users, Roles, Services, Public Access AWS Accounts, IAM Users and Roles
Actions Defined Data access (e.g., PutItem, GetItem) Object storage access (e.g., GetObject, PutObject) Cryptographic operations (e.g., Encrypt, Decrypt)

Conclusion

Effective management of resource policies is a cornerstone of crafting a secure AWS environment. Each AWS service offers distinct resource policies to tailor access and permissions closely to your security needs. For the AWS Certified Security – Specialty (SCS-C02) exam, it’s important to understand the structure, implementation, and implications of these policies to ensure compliant and secure resource access. With the provided examples, one should get a foundational understanding of how to employ these policies to protect AWS resources.

Practice Test with Explanation

1) In DynamoDB, fine-grained access control policies can be used to grant permissions at the item level.

  • True
  • False

Answer: True

Explanation: DynamoDB supports fine-grained access control, allowing permissions to be set at the item level.

2) AWS KMS key policies are the only way to control access to a customer master key (CMK).

  • True
  • False

Answer: False

Explanation: AWS KMS key policies define who can use the CMK and how they can use it. However, IAM policies and grants can also be used to control access to CMKs, in conjunction with key policies.

3) S3 bucket policies can:

  • Be used to grant public access to the bucket
  • Control access at both the bucket and object level
  • Support versioning to maintain a history of policy changes
  • Only grant access to AWS accounts and IAM users

Answer: Be used to grant public access to the bucket, Control access at both the bucket and object level

Explanation: S3 bucket policies can grant public access and control access at the bucket and object level. Versioning in S3 is used to maintain a history of objects, not policy changes. Bucket policies can also grant access to authenticated users and predefined groups, not just AWS accounts and IAM users.

4) In AWS KMS, a grant is:

  • An IAM policy
  • A resource-based policy
  • A mechanism to delegate the use of CMKs to users and roles
  • A security group rule

Answer: A mechanism to delegate the use of CMKs to users and roles

Explanation: A grant is a mechanism in AWS KMS for the key owner to delegate the use of CMKs to other AWS principals (users and roles).

5) Which of the following actions can you define in a DynamoDB resource-based policy?

  • CreateTable
  • Query
  • Scan
  • Invoke

Answer: CreateTable, Query, Scan

Explanation: CreateTable, Query, and Scan are DynamoDB operations that can be specified in a resource-based policy. Invoke is not a DynamoDB operation; it is associated with AWS Lambda.

6) Amazon S3 supports the use of AWS Organizations SCPs (Service Control Policies) to manage permissions across multiple AWS accounts.

  • True
  • False

Answer: True

Explanation: AWS Organizations SCPs can be used to manage permissions across accounts, including the ability to restrict actions across all resources within an account or OU, such as S3 buckets.

7) A principal can directly access a KMS CMK only if:

  • They are using the CMK in an AWS service integrated with KMS
  • They are specified in the CMK’s key policy
  • They have been granted access through an IAM policy
  • All of the above

Answer: All of the above

Explanation: Principals can directly access a KMS CMK if they are using the key within an AWS service integrated with KMS, if they are specified in the key policy, or if they have the necessary permissions in an IAM policy.

8) Which of the following statements is true regarding resource policies in AWS?

  • Resource policies are always public
  • Resource policies can grant cross-account access
  • Resource policies must be attached to an IAM user
  • Resource policies override IAM policies

Answer: Resource policies can grant cross-account access

Explanation: Resource policies can grant permissions to users from other AWS accounts enabling cross-account access.

9) AWS KMS resource policies, like S3 and DynamoDB, support the “Principal” element to specify the user, account, service, or other entity that is allowed to access the resource.

  • True
  • False

Answer: True

Explanation: AWS KMS resource policies also include the “Principal” element, similar to S3 and DynamoDB resource policies, to specify the AWS accounts, IAM users, and IAM roles that are allowed or denied access to the CMK.

10) When a request is made to Amazon S3, and both an S3 bucket policy and an IAM policy apply, how are the permissions evaluated?

  • S3 bucket policy takes precedence, and the IAM policy is ignored
  • IAM policy takes precedence, and the S3 bucket policy is ignored
  • The most permissive policy wins
  • Both policies are evaluated, and the request is only allowed if both policies allow it

Answer: Both policies are evaluated, and the request is only allowed if both policies allow it

Explanation: AWS evaluates both the S3 bucket policy and the IAM policy. Permission is granted only if both policies allow it, and a deny in any policy overrides an allow.

11) DynamoDB resource policies are the primary method for controlling access to your DynamoDB tables and data.

  • True
  • False

Answer: False

Explanation: DynamoDB doesn’t use resource-based policies. Access to DynamoDB tables and data is primarily controlled through IAM policies.

Interview Questions

Can you describe what an IAM policy is, and how it differs from a resource-based policy like those used in DynamoDB or S3?

An IAM policy is an entity that, when attached to identities (users, groups, or roles), defines their permissions. It specifies what actions are allowed or denied on which AWS resources. IAM policies are centralized and focus on who (the identity) can do what (actions) to which resources. Resource-based policies, like those for DynamoDB or S3, are attached directly to the resources and specify which principals (accounts, users, roles, or federated users) are allowed to perform which actions on the resource. Resource-based policies offer a decentralized way of managing permissions and can grant cross-account access without using roles.

How would you secure sensitive data in an S3 bucket using policies?

To secure sensitive data in an S3 bucket using policies, I would implement the following measures:

  • Implement bucket policies to define which principals can access the S3 bucket and what actions they can perform.
  • Use S3 Block Public Access to prevent unintentional public exposure.
  • Employ S3 encryption (SSE-S3, SSE-KMS, or SSE-C) to protect data at rest.
  • Optionally, utilize S3 Object Lock for WORM (Write Once Read Many) protection if the data must not be altered after creation.
  • Enable access logging to monitor access requests to the S3 bucket.

What is the purpose of a condition in an IAM or resource-based policy?

A condition in an IAM or resource-based policy adds fine-grained control to the permissions defined in a policy. It allows you to specify circumstances under which the policy grants or denies permission. Conditions can include items like the IP address of the requester, the date/time of the request, whether MFA (Multi-Factor Authentication) is used, or the SSL/TLS requirements for the request. They are used to restrict permissions and enhance security.

Can you explain the key differences between an S3 bucket policy and an S3 ACL (Access Control List)?

An S3 bucket policy is a type of resource-based policy that allows you to manage permissions for a bucket and define what actions are allowed or denied across the bucket, including objects within it. It supports granting permissions to AWS accounts, IAM users and roles, and even anonymous users. Policy statements can include a variety of conditions for more granular control.

On the other hand, an S3 ACL is a legacy access control mechanism that allows you to manage permissions on a per-object or bucket level, providing read and write access to both buckets and objects. ACLs offer basic permissions and are less flexible than bucket policies.

What steps are involved in properly securing data access in DynamoDB using policies?

Properly securing data access in DynamoDB involves:

  • Defining IAM policies that grant the least privilege needed to perform tasks, applied to IAM users or roles.
  • Using DynamoDB fine-grained access control to control access to individual items or attributes within a table.
  • Employing condition expressions in policies for more granular access based on attributes such as IP range, date/time, and other key factors.
  • Enabling encryption at rest using DynamoDB encryption with AWS KMS to secure data.

How does AWS KMS integrate with resource policies, and what are the benefits?

AWS KMS integrates with resource policies (key policies) to control access to KMS keys. These policies define which principals can use the KMS key to encrypt and decrypt data. They can include conditions for added security. The benefits of using KMS with resource policies include central management of encryption keys, the ability to enforce cryptographic best practices easily, and detailed control over who can use keys, including the ability to grant cross-account access without the use of roles.

Describe a scenario where you would use a bucket policy over an IAM policy for S3?

A scenario where I would use a bucket policy over an IAM policy is when I need to enable cross-account access to the S3 bucket. Bucket policies allow for specifying permissions for users in other AWS accounts directly, whereas IAM policies are strictly tied to the identities in a single AWS account. This feature of bucket policies is particularly useful for operations like sharing data with business partners or allowing access to a logging bucket for multiple accounts.

What considerations should be taken when setting resource policies for AWS KMS?

When setting resource policies (key policies) for AWS KMS, one should consider the following:

  • Ensure the key policy grants appropriate permissions only to necessary principals to maintain the least privilege.
  • Use policy conditions to restrict access based on factors like source IP, encryption context, or date/time.
  • Review and restrict the use of “kms:Grant*” permissions, which allow principals to delegate their permissions to others.
  • Regularly rotate KMS keys if necessary, according to the organization’s security requirements.

Discuss how the principle of least privilege is applied when configuring resource policies for DynamoDB.

The principle of least privilege is applied in DynamoDB by ensuring that IAM policies and DynamoDB access control mechanisms grant only the permissions required for an entity to perform its defined tasks and no more. This involves using IAM policies to restrict access to certain actions, table-level access control for controlling which items and attributes a user can access, and using conditions in policies to impose further restrictions such as time-based access or IP restrictions. Fine-grained access control in DynamoDB further helps in adhering to the least privilege principle at the items and attributes level.

Is it possible to use a combination of IAM and resource-based policies to control access to an S3 bucket, and if so, how do they work together?

Yes, it is possible to use a combination of IAM and resource-based policies to control access to an S3 bucket. IAM policies are used to manage permissions for IAM users and roles within the same AWS account. These can specify which S3 actions a user or role can perform. Resource-based policies, such as S3 bucket policies, are used to grant permissions to a broader set of principals, including IAM users and roles from other AWS accounts.

When both types of policies are used, access to S3 buckets is granted only if both the IAM policy attached to the user or role and the bucket policy attached to the S3 bucket allow the action. If either policy denies access, the request will be denied. This allows for flexible cross-account sharing scenarios while still maintaining a layered approach to security.

What is the purpose of the “aws:SourceArn” condition key in resource policies, and can you provide an example of its use in an S3 bucket policy?

The “aws:SourceArn” condition key in resource policies is used to match the ARN (Amazon Resource Name) of the resource that is making the request. This condition key helps ensure that the policy is granting permissions to the correct resource. For example, in an S3 bucket policy, you can use “aws:SourceArn” to allow an SNS topic to trigger a Lambda function only if the notifications come from a specific S3 bucket. The policy snippet would look something like:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {"Service": "lambda.amazonaws.com"},
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:region:account-id:function:my-function",
      "Condition": {
        "ArnLike": {
          "aws:SourceArn": "arn:aws:s3:::my-source-bucket"
        }
      }
    }
  ]
}

How would you prevent accidental deletion of an S3 object or DynamoDB table using resource policies?

To prevent accidental deletion of S3 objects, you can use a combination of S3 Versioning and MFA (Multi-Factor Authentication) Delete feature. By enabling these, you can ensure that object versions are kept even after deletions, and that deletions require MFA confirmation. For DynamoDB, you cannot use resource policies to prevent deletions directly; however, you can set a very restrictive resource-based policy that explicitly denies “dynamodb:DeleteTable” action unless certain conditions are met (like MFA authentication or requests from certain IP addresses).

0 0 votes
Article Rating
Subscribe
Notify of
guest
25 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
María José Zarate
3 months ago

This is a great blog post! Very informative on AWS KMS.

Clara Ouellet
4 months ago

Does anyone know if DynamoDB resource policies help in restricting access at the item level?

Eva Wilson
3 months ago

Thank you for this post!

Arthur Liu
4 months ago

Initially, I found AWS KMS complex to understand, but this post simplified it a lot.

Isaac Orta
3 months ago

How does one set up a resource policy for Amazon S3?

Shabari Mugeraya
3 months ago

Appreciate the detailed breakdown of resource policies. Very enlightening!

Madison Lo
4 months ago

Do resource policies for AWS KMS allow cross-account access?

Cassiana Almeida
3 months ago

More clarity on how IAM and resource policies interplay would have been great.

25
0
Would love your thoughts, please comment.x
()
x