2024-04-11 14:23:07 +00:00
|
|
|
id: iam-ssh-keys-rotation
|
|
|
|
info:
|
|
|
|
name: SSH Key Rotation - 90-Day Policy
|
|
|
|
author: princechaddha
|
|
|
|
severity: high
|
|
|
|
description: |
|
|
|
|
Verifies that IAM SSH public keys are rotated every 90 days, enhancing security and preventing unauthorized access to AWS CodeCommit repositories
|
|
|
|
reference:
|
|
|
|
- https://docs.aws.amazon.com/cli/latest/reference/iam/list-ssh-public-keys.html
|
2024-06-07 10:04:29 +00:00
|
|
|
metadata:
|
|
|
|
max-request: 2
|
2024-04-11 14:23:07 +00:00
|
|
|
tags: cloud,devops,aws,amazon,iam,ssh,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-ssh-public-keys --user-name $user | jq -r '.SSHPublicKeys[] | select(.UploadDate | fromdateiso8601 < (now - (90 * 86400))) | .SSHPublicKeyId'
|
|
|
|
|
|
|
|
extractors:
|
|
|
|
- type: regex # type of the extractor
|
|
|
|
name: accesskey
|
|
|
|
internal: true
|
|
|
|
regex:
|
|
|
|
- '^AP.*'
|
|
|
|
|
|
|
|
- type: dsl
|
|
|
|
dsl:
|
|
|
|
- '"The SSH Public Key " + accesskey +" is older than 90 days"'
|
2024-06-08 16:02:17 +00:00
|
|
|
# digest: 4a0a0047304502200df47806e0ebcba6e0cbd3e933b7db44c7e85cb3e43bbb634ee48521d2c441e7022100b0694e5404356f0219d841a6ec17f3d756542a0c4137973b21d45dec07f12e47:922c64590222798bb761d5b6d8e72950
|