AWS Identity and Access Management (IAM)  sandbox 

Access Analyzer

https://aws.amazon.com/blogs/security/how-to-prioritize-iam-access-analyzer-findings/

In addition to roles, it also analyzes resource policies on supported resources

Monitors resources for external access AWS Simple Storage(S3) buckets AWS Identity and Access Management roles AWS Key Management Service Keys AWS Lambda functions and layers AWS Simple Queue Service queues AWS Secrets Manager secrets

Identity Center

SSO for Org

Policy Conditions

Useful to allow/deny actions based on certain conditions in addition to resource arn or patterns.

Can be used for ABAC

Tag based access control

Use the Service Authorization page to find which service or actions support which condition keys.

Context keys can be single valued or multi valued, more here

Condition Operators

Evaluation logic - AND, OR conditions

iam-condition-evaluation

Global Keys

These are available for most services and actions

All keys need an aws: suffix unless the prefix is specifically mentioned for a condition, liek ec2:RoleDelivery

PrincipalExample ValueWhy use it?Notes
PrincipalArn
PrincipalAccount
PrincipalOrgPaths
PrincipalOrgID
PrincipalTag/TagKey
PrincipalIsAWSService
PrincipalServiceName
PrincipalServiceNamesList
PrincipalType
userid
username
Role SessionExample ValueWhy use it?Notes
FederatedProvider
TokenIssueTime
MultiFactorAuthPresent
Ec2InstanceSourceVpc
Ec2InstanceSourcePrivateIPv4
SourceIdentity
ec2:RoleDelivery
ec2:SourceInstanceArn
glue:RoleAssumedBy
glue:CredentialIssuingService
lambda:SourceFunctionArn
ssm:SourceInstanceArn
identitystore:UserId
NetworkExample ValueWhy use it?Notes
SourceIp
SourceVpc
SourceVpce
VpcSourceIp
Resource PropertiesExample ValueWhy use it?Notes
ResourceAccount
ResourceOrgPaths
ResourceOrgID
ResourceTag/TagKey
Request PropertiesExample ValuesWhy use it?
CalledVia
CalledViaFirst
CalledViaLast
ViaAWSService
CurrentTime
EpochTime
referer
RequestedRegionus-east-1Implement region deny controls by using this condition in an IAM policy or an SCP
RequestTag/TagKeyImplement standard tags. Deny action if tag not present. Not all resources support request tags (RDS doesn’t!), so needs to be applied with other controls.
TagKeys
SecureTransporttrue, falseImplement encryption-in-transit by denying actions which do not have this enable.
SourceArnarn:aws:sns:us-east-2:123456789012:MyTopicUse in a SQS queue resource policy to allow SNS to send message to the queue. Since principal is sns in this case, without the condition it can lead to the [[confused deputy problem]].
SourceAccount
SourceOrgPaths
SourceOrgID
UserAgent

Refer AWS docs

Examples

Not working

"Condition": {"StringEquals": {"aws:TagKeys": ["Department"]}}

Working

"Condition": {"ForAllValues:StringEquals": {"aws:TagKeys": ["Department"]}}

Working

"Condition": {"ForAnyValue:StringEquals": {"aws:TagKeys": ["Department"]}}

Managed Policy

Refer https://docs.aws.amazon.com/aws-managed-policy/latest/reference/policy-list.html