52 lines
1.5 KiB
YAML
52 lines
1.5 KiB
YAML
id: iam-key-rotation-90days
|
|
info:
|
|
name: IAM Access Key Rotation - 90-Day Policy
|
|
author: princechaddha
|
|
severity: high
|
|
description: |
|
|
Checks if IAM user access keys are rotated every 90 days to minimize accidental exposures and unauthorized access risks
|
|
reference:
|
|
- https://docs.aws.amazon.com/cli/latest/reference/iam/list-access-keys.html
|
|
metadata:
|
|
max-request: 2
|
|
tags: cloud,devops,aws,amazon,iam,aws-cloud-config
|
|
|
|
flow: |
|
|
code(1)
|
|
for(let UserName of iterate(template.users)){
|
|
set("user", UserName)
|
|
code(2)
|
|
}
|
|
|
|
self-contained: true
|
|
code:
|
|
- engine:
|
|
- sh
|
|
- bash
|
|
source: |
|
|
aws iam list-users --query 'Users[*].UserName'
|
|
|
|
extractors:
|
|
- type: json # type of the extractor
|
|
internal: true
|
|
name: users
|
|
json:
|
|
- '.[]'
|
|
|
|
- engine:
|
|
- sh
|
|
- bash
|
|
source: |
|
|
aws iam list-access-keys --user-name $user | jq -r '.AccessKeyMetadata[] | select((.CreateDate[:-6] | strptime("%Y-%m-%dT%H:%M:%S") | mktime) < (now - (90 * 86400))) | .AccessKeyId'
|
|
|
|
extractors:
|
|
- type: regex # type of the extractor
|
|
name: accesskey
|
|
internal: true
|
|
regex:
|
|
- '^AK.*'
|
|
|
|
- type: dsl
|
|
dsl:
|
|
- '"The IAM Key " + accesskey +" is older than 90 days"'
|
|
# digest: 4a0a0047304502202a9b12e596c433a426976cc985f93e87eb624f05932b7e78a72dd633496726fa022100db223fbc664946a1d52e6916fa64fb18bb07efcb40ddba5110bb24c8a29d932b:922c64590222798bb761d5b6d8e72950 |