There may be scenarios where you want to provide access to specific users or groups for a defined time period, such as granting permissions to Security Auditors during audit periods or to consultants for the duration of a project. In these situations, you can use permission sets with inline policies containing conditions to implement time-based access control.
ℹ️ Information: Time-based access control allows you to automatically grant and revoke permissions based on date and time conditions, reducing the operational overhead of managing temporary access.
This guide explores the case of providing temporary access to AWS accounts for Security Auditors. To implement this requirement with time-based access control, you’ll complete the following steps:
Navigate to the IAM Identity Center Console
Select the AWS Region recommended by the AWS Team if this is part of an AWS Event. If you’re doing this on your own, select the Region where you intend to configure the rules.
Click on Permission sets in the left menu under the Multi-account permissions section and click the Create permission set button.
On the Select permission set type page:
On the Specify policies page:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"acm:Describe*",
"acm:List*",
"cloudtrail:Describe*",
"cloudtrail:Get*",
"cloudtrail:GetTrailStatus",
"cloudtrail:ListTags",
"cloudtrail:LookupEvents",
"cloudwatch:Describe*",
"cloudwatch:ListTagsForResource",
"config:BatchGetAggregateResourceConfig",
"config:BatchGetResourceConfig",
"config:Deliver*",
"config:Describe*",
"config:Get*",
"config:List*",
"detective:GetGraphIngestState",
"detective:ListGraphs",
"detective:ListMembers",
"ec2:Describe*",
"ec2:Get*",
"guardduty:DescribePublishingDestination",
"guardduty:Get*",
"guardduty:List*",
"iam:GenerateCredentialReport",
"iam:GenerateServiceLastAccessedDetails",
"iam:Get*",
"iam:List*",
"inspector:Describe*",
"kms:Describe*",
"kms:Get*",
"kms:List*",
"s3:Get*",
"s3:List*",
"secretsmanager:DescribeSecret",
"secretsmanager:GetResourcePolicy",
"secretsmanager:List*",
"securityhub:Describe*",
"securityhub:Get*",
"securityhub:List*",
"trustedadvisor:Describe*"
],
"Resource": "*",
"Condition": {
"DateGreaterThan": {
"aws:CurrentTime": "2022-07-26T00:00:00Z"
},
"DateLessThan": {
"aws:CurrentTime": "2022-07-27T23:59:59Z"
}
}
}
]
}
Click Next
On the Specify permission set details page:
On the Review and create page:
🔒 Security Note: The time-based condition in this policy uses the global condition key aws:CurrentTime
that evaluates against the current date and time. The dates in the policy should be in ISO 8601 format with UTC timezone.
Let’s create a new Group named securityAuditors:
Navigate to the IAM Identity Center Console
Select Groups under the Workplace pool section and click Create Group.
On the Create group page:
For this module, we’ll create a new user: secAuditUser
Navigate to the IAM Identity Center Console
Select Users under the Workplace pool section and click Add User.
On the Add User page:
On the Add users to groups - optional page:
On the Review and add user page:
A pop-up window will appear with a One-time password. Copy the information using the Copy button and save it for later use in the workshop.
💡 Pro Tip: When working with temporary access, it’s a good practice to create functional groups that reflect job roles or responsibilities rather than creating groups for individuals. This approach simplifies access management as people transition between roles.
Navigate to the IAM Identity Center Console, select AWS accounts under the Multi-account permissions section
Select the account you want users to have access to
Click Assign users or groups
On the Assign users and Group to AccountName page:
On the Select permission sets page:
On the Review and submit page:
IAM Identity Center will associate the User group with the Permission set and assign it to the selected AWS Account. You’ll see a page with a green banner.
Note: For a better experience, you should perform the following verification steps in private browsing mode or a different web browser
Log in to the AWS access Portal using the User portal URL saved when creating secAuditUser
Provide the username for the user previously created in this module
Provide the one-time password for the username
Set a new password for the user
After successful login, on the SSO portal page, select the Management console link for the secAuditorTimeBased role
After successfully logging into the Management Console, navigate to the EC2 console page and confirm that you can list all instances by selecting Instances in the left menu
ℹ️ Information: The secAuditorTimeBased permission set includes ec2:Describe*
permissions, which allow the user to view EC2 resources but not modify them—perfect for audit-related activities.
To simulate access control for Security Auditors, let’s update the Permission set and provision it again in our account. We’ll simulate this by selecting a timeframe in the past (2022-07-04).
Navigate to the IAM Identity Center Console
Click on Permission sets in the left menu and select the secAuditorTimeBased permission set
Edit the inline policy by clicking the Edit button
Copy and replace the permission policy with the code below
The only change in the policy is the date/time values occurring in the past “2022-07-04T00:00:00Z” “2022-07-04T23:59:59Z”
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"acm:Describe*",
"acm:List*",
"cloudtrail:Describe*",
"cloudtrail:Get*",
"cloudtrail:GetTrailStatus",
"cloudtrail:ListTags",
"cloudtrail:LookupEvents",
"cloudwatch:Describe*",
"cloudwatch:ListTagsForResource",
"config:BatchGetAggregateResourceConfig",
"config:BatchGetResourceConfig",
"config:Deliver*",
"config:Describe*",
"config:Get*",
"config:List*",
"detective:GetGraphIngestState",
"detective:ListGraphs",
"detective:ListMembers",
"ec2:Describe*",
"ec2:Get*",
"guardduty:DescribePublishingDestination",
"guardduty:Get*",
"guardduty:List*",
"iam:GenerateCredentialReport",
"iam:GenerateServiceLastAccessedDetails",
"iam:Get*",
"iam:List*",
"inspector:Describe*",
"kms:Describe*",
"kms:Get*",
"kms:List*",
"s3:Get*",
"s3:List*",
"secretsmanager:DescribeSecret",
"secretsmanager:GetResourcePolicy",
"secretsmanager:List*",
"securityhub:Describe*",
"securityhub:Get*",
"securityhub:List*",
"trustedadvisor:Describe*"
],
"Resource": "*",
"Condition": {
"DateGreaterThan": {
"aws:CurrentTime": "2022-07-04T00:00:00Z"
},
"DateLessThan": {
"aws:CurrentTime": "2022-07-04T23:59:59Z"
}
}
}
]
}
Save the changes to the Permission set, which provisions the permission set again to the AWS Account
Log back into the AWS access portal by following the steps and verify access to EC2 instances. You’ll see that secAuditUser no longer has permission to list EC2 instances.
⚠️ Warning: When using time-based access control, be aware of timezone differences. AWS uses UTC for time-based conditions, so adjust your dates and times accordingly to avoid unexpected access denials.
💡 Pro Tip: For recurring access needs, consider implementing an automated solution using AWS Lambda functions to update the time-based conditions in your permission sets based on a schedule, rather than manually updating policies.