Sub topic 7
Session duration and relay state
This chapter covers two settings on a permission set that control what a user experiences after signing in: how long the AWS role session lasts, and where the browser lands. It assumes you can create a permission set and attach policies to it, as covered in the previous chapters. It also assumes you know what an IAM role session is and what MaxSessionDuration means on a role.
Two clocks, not one
A signed-in Identity Center user is working against two separate time limits. Mixing them up is the most common cause of "why did my session end?" tickets.
| Setting | Where it lives | Range | Default | What it controls |
|---|---|---|---|---|
| AWS access portal session duration | Identity Center settings (instance-wide) | 15 minutes to 90 days | 8 hours | How long a user stays signed in to the access portal before they must authenticate again |
| Permission set session duration | The permission set | 1 to 12 hours | 1 hour | How long the role session in an account lasts: the console session and the role credentials the portal hands out |
The portal session is about who you are. The permission set session is about how long one role session in one account stays valid. When the role session expires, the user goes back to the portal and picks the account and role again. If the portal session is still alive, this needs no new authentication. If the portal session has ended, they sign in again.
Setting the session duration
Session duration is written in ISO 8601 duration format. PT1H is one hour, PT4H is four hours, and PT12H is the maximum. Minutes are allowed (PT90M), but values must stay inside the 1-to-12-hour range.
You can set it when you create the permission set, as in the earlier example that used --session-duration PT4H. To change it on an existing permission set, use update-permission-set:
INSTANCE_ARN=$(aws sso-admin list-instances --query 'Instances[0].InstanceArn' --output text)
aws sso-admin update-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--session-duration PT8HUnder the hood, the duration is applied to the role that Identity Center creates in each account, as that role's maximum session duration. That is why a change reaches the accounts only after you provision the permission set again. The update call alone changes the definition stored in Identity Center and nothing in the accounts.
aws sso-admin provision-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--target-type ALL_PROVISIONED_ACCOUNTSChoosing a value
There is no single right duration. Pick it per permission set, based on what the role can do.
- Administrative or write-capable sets: keep short, usually 1 to 4 hours. A leaked credential is valid for less time, and users re-confirm that they still have access more often.
- Read-only or audit sets: longer values, such as 8 to 12 hours, reduce interruptions for people who work in the console all day.
- Break-glass sets: short and tightly scoped, even if that is inconvenient. The inconvenience is the point.
A longer duration does not widen permissions. It only lengthens how long the same permissions stay usable. Revoking an assignment does not necessarily end a session that is already open, so a long duration also means a longer window during which a removed user may still have working credentials.
Role chaining
If a user's role session calls sts:AssumeRole to move into another role, that chained session is limited to one hour by IAM, whatever the permission set's duration says. Tools that assume a second role from an Identity Center session often hit this, and the error mentions the maximum session duration. Setting PT12H on the permission set does not change this.
Relay state
Relay state is a URL that the permission set stores. When a user opens the AWS Management Console for that account and role from the portal, the browser is sent to that URL instead of the console home page. It is a convenience feature, so it affects navigation only.
Rules to keep in mind:
- The URL must point to the AWS Management Console. A URL for any other site is rejected.
- It is limited to 240 characters.
- It applies only to console sign-in. CLI and SDK credentials ignore it.
- It grants nothing. If the role lacks permission for the service the page belongs to, the user lands on the page and sees access-denied messages.
A typical use is to send a team straight to the service it works in, in a specific Region:
aws sso-admin update-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--relay-state "https://us-east-1.console.aws.amazon.com/cloudwatch/home?region=us-east-1"Quote the URL. Without quotes, the shell treats ? and & specially, which can truncate the value or change its meaning. When a console URL contains &, quoting is mandatory.
You can read both settings back to check them:
aws sso-admin describe-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--query 'PermissionSet.[Name,SessionDuration,RelayState]' \
--output tableReading back shows what Identity Center holds. It does not show what each account's role holds. To check that, inspect the role in the target account, as covered later in the chapter on role provisioning and troubleshooting.
Setting both in CloudFormation
In AWS::SSO::PermissionSet, SessionDuration takes the same ISO 8601 string, and the relay state property is RelayStateType. This extends the template from the automation chapter:
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
InstanceArn:
Type: String
Resources:
OperationsViewer:
Type: AWS::SSO::PermissionSet
Properties:
InstanceArn: !Ref InstanceArn
Name: OperationsViewer
Description: Read-only access that opens in CloudWatch
SessionDuration: PT8H
RelayStateType: "https://us-east-1.console.aws.amazon.com/cloudwatch/home?region=us-east-1"
ManagedPolicies:
- arn:aws:iam::aws:policy/ReadOnlyAccessWhen CloudFormation updates a permission set that is already assigned to accounts, it re-provisions the change to those accounts as part of the update. Even so, confirm the result in one account after the stack update finishes. This is the same check you would make after a manual provision-permission-set.
Common errors
- "I set 12 hours but the session ended at 1 hour." The permission set was updated but not provisioned, so the role in the account still has the old maximum. Run
provision-permission-setand open a new session. Existing sessions keep their original expiry. - A relay state that works in one Region sends users to the wrong one. Console URLs include a Region. Put the Region in the URL itself, as in the examples, instead of relying on the user's last-used Region.
- A relay state URL is rejected. The URL is not an AWS Management Console URL, or it exceeds 240 characters.
- A session duration outside the range. Values under one hour or over twelve hours are rejected, as are values that are not valid ISO 8601 durations, such as
4hor240. - Users are asked to sign in much more often than the permission set duration suggests. The cause is usually the portal session duration, not the permission set. Check the instance-wide setting.
- CLI users are surprised that credentials stop working. CLI credentials for a role expire according to the permission set duration. The cached login for the profile is bound to the portal session. Either can end first, so the fix depends on which one expired.
Exercise
A permission set has a session duration of PT12H and the access portal session duration is 4 hours. A user signs in at 09:00 and opens the console for an account at 09:30. Roughly when does that console role session end, and what must the user do afterward?
Show answer
The role session ends at about 21:30, 12 hours after it started, because the permission set duration governs the role session. The portal session ends earlier, at 13:00. The open console session keeps working after 13:00 until it expires, but the user cannot open a new role session from the portal after 13:00 without signing in again.
Exercise
You changed a permission set's session duration from PT1H to PT6H with update-permission-set. Users still see one-hour sessions in the target accounts. What did you skip, and what command fixes it?
Show answer
You did not provision the change. The duration is applied to the role in each account, so run aws sso-admin provision-permission-set with --target-type ALLPROVISIONEDACCOUNTS. Users must then start a new session, because sessions that are already open keep their original expiry.