Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update key rotation duration for iam-users #11

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modules/iam-users/lambda/lambda.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import boto3
from datetime import datetime, timezone
from datetime import datetime, timezone, timedelta
import logging
import time
import os
Expand Down Expand Up @@ -68,10 +68,10 @@ def handle_iam_user(user_name):
if not current_key:
logger.info("No key present, Creating current key")
create_and_manage_key(user_name, 'current')
elif current_key and not pending_deletion_key and current_key['age'] >= 15:
elif current_key and not pending_deletion_key and current_key['age'] >= timedelta(days=2):
logger.info("Current key age is older than 15 days, Creating New key and renaming keys")
rotate_keys_and_update_tags(user_name, current_key, pending_deletion_key)
elif current_key and pending_deletion_key and pending_deletion_key['age'] >= 30:
elif current_key and pending_deletion_key and pending_deletion_key['age'] >= timedelta(days=4):
logger.info("Key age expired, Rotationg keys")
rotate_keys_and_update_tags(user_name, current_key, pending_deletion_key)
else:
Expand Down Expand Up @@ -104,7 +104,7 @@ def get_key_details(user_name):
for key in existing_keys:
key_id = key['AccessKeyId']
create_date = key['CreateDate']
age = (datetime.now(timezone.utc) - create_date).days # age in days
age = datetime.now(timezone.utc) - create_date

tags = iam_client.list_user_tags(UserName=user_name)
for tag in tags['Tags']:
Expand Down
Loading