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

Add get_user to AWS datamodel #1441

Merged
merged 9 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
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
35 changes: 35 additions & 0 deletions data_models/aws_cloudtrail_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,38 @@ def load_ip_address(event):
except ipaddress.AddressValueError:
return None
return source_ip


# get actor user from correct field based on identity type
# https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html#cloudtrail-event-reference-user-identity-fields
def get_actor_user(event):
user_type = deep_get(event, "userIdentity", "type")
if event.get("eventType") == "AwsServiceEvent":
actor_user = deep_get(event, "userIdentity", "invokedBy", default="UnknownAwsServiceEvent")
elif user_type == "Root":
actor_user = deep_get(
event,
"userIdentity",
"userName",
default=deep_get(event, "userIdentity", "accountId", default="UnknownRootUser"),
)
elif user_type in ("IAMUser", "Directory", "Unknown", "SAMLUser", "WebIdentityUser"):
actor_user = deep_get(event, "userIdentity", "userName", default=f"Unknown{user_type}")
elif user_type in ("AssumedRole", "Role", "FederatedUser"):
actor_user = deep_get(
event,
"userIdentity",
"sessionContext",
"sessionIssuer",
"userName",
default=f"Unknown{user_type}",
)
elif user_type == "IdentityCenterUser":
actor_user = deep_get(
event, "additionalEventData", "UserName", default=f"Unknown{user_type}"
)
elif user_type in ("AWSService", "AWSAccount"):
actor_user = event.get("sourceIdentity", f"Unknown{user_type}")
else:
actor_user = "UnknownUser"
return actor_user
2 changes: 1 addition & 1 deletion data_models/aws_cloudtrail_data_model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Filename: aws_cloudtrail_data_model.py
Enabled: true
Mappings:
- Name: actor_user
Path: $.userIdentity..userName
Method: get_actor_user
- Name: event_type
Method: get_event_type
- Name: source_ip
Expand Down
Loading