From 48c5e5c3aeed8e1c9e6a26710f18bac3990046a0 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Date: Thu, 7 Aug 2025 23:30:57 +0200 Subject: [PATCH] feat(events): send user and token name as actorName Signed-off-by: Miguel Martinez --- app/controlplane/pkg/auditor/events/apitoken_test.go | 4 ++-- app/controlplane/pkg/auditor/events/events_test.go | 8 ++++++-- app/controlplane/pkg/auditor/events/group_test.go | 4 ++-- app/controlplane/pkg/auditor/events/project_test.go | 4 ++-- .../events/testdata/apitokens/api_token_created.json | 1 + .../apitokens/api_token_created_with_description.json | 1 + .../api_token_created_with_expiration_date.json | 1 + .../events/testdata/apitokens/api_token_revoked.json | 1 + .../auditor/events/testdata/groups/group_created.json | 1 + .../auditor/events/testdata/groups/group_deleted.json | 1 + .../events/testdata/groups/group_member_added.json | 1 + .../events/testdata/groups/group_member_removed.json | 1 + .../events/testdata/groups/group_member_updated.json | 1 + .../auditor/events/testdata/groups/group_updated.json | 1 + .../groups/group_updated_with_description.json | 1 + .../testdata/projects/project_member_added.json | 1 + .../projects/project_member_added_as_admin.json | 1 + .../projects/project_member_added_by_system.json | 1 + .../testdata/projects/project_member_removed.json | 1 + .../projects/project_member_removed_by_system.json | 1 + .../projects/project_member_role_updated.json | 1 + .../project_member_role_updated_by_system.json | 1 + .../auditor/events/testdata/users/user_logs_in.json | 1 + .../events/testdata/users/user_role_changed.json | 1 + .../auditor/events/testdata/users/user_signs_up.json | 1 + .../workflow_attached_to_contract.json | 1 + .../workflow_attached_to_contract_by_api_token.json | 1 + .../workflowcontracts/workflow_contract_created.json | 1 + .../workflow_contract_created_by_api_token.json | 1 + .../workflowcontracts/workflow_contract_deleted.json | 1 + .../workflow_contract_deleted_by_api_token.json | 1 + .../workflowcontracts/workflow_contract_updated.json | 1 + .../workflow_contract_updated_by_api_token.json | 1 + .../workflow_detached_from_contract.json | 1 + .../workflow_detached_from_contract_by_api_token.json | 1 + .../events/testdata/workflows/workflow_created.json | 1 + .../workflows/workflow_created_by_api_token.json | 1 + .../events/testdata/workflows/workflow_deleted.json | 1 + .../workflows/workflow_deleted_by_api_token.json | 1 + .../events/testdata/workflows/workflow_updated.json | 1 + .../workflows/workflow_updated_by_api_token.json | 1 + .../workflow_updated_with_workflow_contract.json | 1 + ...w_updated_with_workflow_contract_by_api_token.json | 1 + app/controlplane/pkg/auditor/events/user_test.go | 4 ++-- app/controlplane/pkg/auditor/events/workflow_test.go | 4 ++-- .../pkg/auditor/events/workflowcontract_test.go | 6 +++--- app/controlplane/pkg/auditor/logentry.go | 11 ++++++++++- app/controlplane/pkg/biz/auditor.go | 7 ++++--- 48 files changed, 72 insertions(+), 19 deletions(-) diff --git a/app/controlplane/pkg/auditor/events/apitoken_test.go b/app/controlplane/pkg/auditor/events/apitoken_test.go index 6b999689e..4d72c1f2e 100644 --- a/app/controlplane/pkg/auditor/events/apitoken_test.go +++ b/app/controlplane/pkg/auditor/events/apitoken_test.go @@ -108,9 +108,9 @@ func TestAPITokenEvents(t *testing.T) { auditor.WithOrgID(orgUUID), } if tt.actor == auditor.ActorTypeAPIToken { - opts = append(opts, auditor.WithActor(auditor.ActorTypeAPIToken, tt.actorID, "")) + opts = append(opts, auditor.WithActor(auditor.ActorTypeAPIToken, tt.actorID, "", testAPITokenName)) } else { - opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, tt.actorID, testEmail)) + opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, tt.actorID, testEmail, testName)) } eventPayload, err := auditor.GenerateAuditEvent(tt.event, opts...) diff --git a/app/controlplane/pkg/auditor/events/events_test.go b/app/controlplane/pkg/auditor/events/events_test.go index 5d6867632..0c659600a 100644 --- a/app/controlplane/pkg/auditor/events/events_test.go +++ b/app/controlplane/pkg/auditor/events/events_test.go @@ -1,5 +1,5 @@ // -// Copyright 2024 The Chainloop Authors. +// Copyright 2024-2025 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,7 +23,11 @@ import ( var updateGolden bool -const testEmail = "john@cyberdyne.io" +const ( + testEmail = "john@cyberdyne.io" + testName = "John Doe" + testAPITokenName = "test-token" +) func TestMain(m *testing.M) { flag.BoolVar(&updateGolden, "update-golden", false, "update the expected golden files") diff --git a/app/controlplane/pkg/auditor/events/group_test.go b/app/controlplane/pkg/auditor/events/group_test.go index d94b6eef2..df5d543ee 100644 --- a/app/controlplane/pkg/auditor/events/group_test.go +++ b/app/controlplane/pkg/auditor/events/group_test.go @@ -153,9 +153,9 @@ func TestGroupEvents(t *testing.T) { } if tt.actor == auditor.ActorTypeUser { - opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, tt.actorID, testEmail)) + opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, tt.actorID, testEmail, testName)) } else { - opts = append(opts, auditor.WithActor(auditor.ActorTypeSystem, uuid.Nil, "")) + opts = append(opts, auditor.WithActor(auditor.ActorTypeSystem, uuid.Nil, "", testAPITokenName)) } eventPayload, err := auditor.GenerateAuditEvent(tt.event, opts...) diff --git a/app/controlplane/pkg/auditor/events/project_test.go b/app/controlplane/pkg/auditor/events/project_test.go index 837fc44f4..84ddf29f5 100644 --- a/app/controlplane/pkg/auditor/events/project_test.go +++ b/app/controlplane/pkg/auditor/events/project_test.go @@ -162,9 +162,9 @@ func TestProjectEvents(t *testing.T) { auditor.WithOrgID(orgUUID), } if tt.actor == auditor.ActorTypeUser { - opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, tt.actorID, testEmail)) + opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, tt.actorID, testEmail, testName)) } else { - opts = append(opts, auditor.WithActor(auditor.ActorTypeSystem, uuid.Nil, "")) + opts = append(opts, auditor.WithActor(auditor.ActorTypeSystem, uuid.Nil, "", testAPITokenName)) } eventPayload, err := auditor.GenerateAuditEvent(tt.event, opts...) diff --git a/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created.json b/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created.json index c6d25f93e..f97b52daf 100644 --- a/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created.json +++ b/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has created the API token test-token", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created_with_description.json b/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created_with_description.json index 88f531ea1..0af3c4a81 100644 --- a/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created_with_description.json +++ b/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created_with_description.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has created the API token test-token", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created_with_expiration_date.json b/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created_with_expiration_date.json index 91321975a..29772549f 100644 --- a/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created_with_expiration_date.json +++ b/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_created_with_expiration_date.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has created the API token test-token expiring at 2025-01-01T00:00:00Z", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_revoked.json b/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_revoked.json index d112f1a83..c0929e379 100644 --- a/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_revoked.json +++ b/app/controlplane/pkg/auditor/events/testdata/apitokens/api_token_revoked.json @@ -5,6 +5,7 @@ "ActorType": "API_TOKEN", "ActorID": "2089bb36-e27b-428b-8009-d015c8737c55", "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": " has revoked the API token test-token", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/groups/group_created.json b/app/controlplane/pkg/auditor/events/testdata/groups/group_created.json index c64a20c4b..f695838e4 100644 --- a/app/controlplane/pkg/auditor/events/testdata/groups/group_created.json +++ b/app/controlplane/pkg/auditor/events/testdata/groups/group_created.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has created the group test-group", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/groups/group_deleted.json b/app/controlplane/pkg/auditor/events/testdata/groups/group_deleted.json index 02565e7e3..e05264daf 100644 --- a/app/controlplane/pkg/auditor/events/testdata/groups/group_deleted.json +++ b/app/controlplane/pkg/auditor/events/testdata/groups/group_deleted.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has deleted the group test-group", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/groups/group_member_added.json b/app/controlplane/pkg/auditor/events/testdata/groups/group_member_added.json index 55e04c907..6bd2774c0 100644 --- a/app/controlplane/pkg/auditor/events/testdata/groups/group_member_added.json +++ b/app/controlplane/pkg/auditor/events/testdata/groups/group_member_added.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has added user test@example.com to the group test-group as a maintainer", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/groups/group_member_removed.json b/app/controlplane/pkg/auditor/events/testdata/groups/group_member_removed.json index f73412639..a0c2bbaf0 100644 --- a/app/controlplane/pkg/auditor/events/testdata/groups/group_member_removed.json +++ b/app/controlplane/pkg/auditor/events/testdata/groups/group_member_removed.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has removed user test@example.com from the group test-group", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/groups/group_member_updated.json b/app/controlplane/pkg/auditor/events/testdata/groups/group_member_updated.json index 1768cdb30..c7f2aa522 100644 --- a/app/controlplane/pkg/auditor/events/testdata/groups/group_member_updated.json +++ b/app/controlplane/pkg/auditor/events/testdata/groups/group_member_updated.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has updated user test@example.com in the group test-group", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/groups/group_updated.json b/app/controlplane/pkg/auditor/events/testdata/groups/group_updated.json index 99ed24893..f68c22338 100644 --- a/app/controlplane/pkg/auditor/events/testdata/groups/group_updated.json +++ b/app/controlplane/pkg/auditor/events/testdata/groups/group_updated.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has updated the group test-group", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/groups/group_updated_with_description.json b/app/controlplane/pkg/auditor/events/testdata/groups/group_updated_with_description.json index 99ed24893..f68c22338 100644 --- a/app/controlplane/pkg/auditor/events/testdata/groups/group_updated_with_description.json +++ b/app/controlplane/pkg/auditor/events/testdata/groups/group_updated_with_description.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has updated the group test-group", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added.json b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added.json index 640018534..8055a631c 100644 --- a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added.json +++ b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has added user 'test@example.com' to the project 'test-project' with role 'viewer'", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added_as_admin.json b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added_as_admin.json index b50d1bc16..228c139ae 100644 --- a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added_as_admin.json +++ b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added_as_admin.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has added user 'test@example.com' to the project 'test-project' with role 'admin'", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added_by_system.json b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added_by_system.json index 4a986ab59..2a38f5ae9 100644 --- a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added_by_system.json +++ b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_added_by_system.json @@ -5,6 +5,7 @@ "ActorType": "SYSTEM", "ActorID": null, "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "system@chainloop.dev has added user 'test@example.com' to the project 'test-project' with role 'viewer'", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_removed.json b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_removed.json index 58bdf3aa5..b63fc8986 100644 --- a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_removed.json +++ b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_removed.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has removed user 'test@example.com' from the project 'test-project'", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_removed_by_system.json b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_removed_by_system.json index 00cfb93b7..c0a041576 100644 --- a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_removed_by_system.json +++ b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_removed_by_system.json @@ -5,6 +5,7 @@ "ActorType": "SYSTEM", "ActorID": null, "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "system@chainloop.dev has removed user 'test@example.com' from the project 'test-project'", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_role_updated.json b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_role_updated.json index 747f8612c..a99a85ba6 100644 --- a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_role_updated.json +++ b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_role_updated.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has updated user 'test@example.com' role in project 'test-project' from 'viewer' to 'admin'", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_role_updated_by_system.json b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_role_updated_by_system.json index 783d2bbce..0f16516d6 100644 --- a/app/controlplane/pkg/auditor/events/testdata/projects/project_member_role_updated_by_system.json +++ b/app/controlplane/pkg/auditor/events/testdata/projects/project_member_role_updated_by_system.json @@ -5,6 +5,7 @@ "ActorType": "SYSTEM", "ActorID": null, "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "system@chainloop.dev has updated user 'test@example.com' role in project 'test-project' from 'viewer' to 'admin'", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/users/user_logs_in.json b/app/controlplane/pkg/auditor/events/testdata/users/user_logs_in.json index 77f486cbb..16a722297 100644 --- a/app/controlplane/pkg/auditor/events/testdata/users/user_logs_in.json +++ b/app/controlplane/pkg/auditor/events/testdata/users/user_logs_in.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has logged in", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/users/user_role_changed.json b/app/controlplane/pkg/auditor/events/testdata/users/user_role_changed.json index 022010bc7..142f5b081 100644 --- a/app/controlplane/pkg/auditor/events/testdata/users/user_role_changed.json +++ b/app/controlplane/pkg/auditor/events/testdata/users/user_role_changed.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io role changed from 'role:org:owner' to 'role:org:member'", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/users/user_signs_up.json b/app/controlplane/pkg/auditor/events/testdata/users/user_signs_up.json index 5d97d6213..01e82f57a 100644 --- a/app/controlplane/pkg/auditor/events/testdata/users/user_signs_up.json +++ b/app/controlplane/pkg/auditor/events/testdata/users/user_signs_up.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has signed up", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_attached_to_contract.json b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_attached_to_contract.json index 7ba3cda87..4852af8fc 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_attached_to_contract.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_attached_to_contract.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has attached the workflow test-workflow to the workflow contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_attached_to_contract_by_api_token.json b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_attached_to_contract_by_api_token.json index 4cdfeb3b9..a717872ce 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_attached_to_contract_by_api_token.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_attached_to_contract_by_api_token.json @@ -5,6 +5,7 @@ "ActorType": "API_TOKEN", "ActorID": "2089bb36-e27b-428b-8009-d015c8737c55", "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "API Token 2089bb36-e27b-428b-8009-d015c8737c55 has attached the workflow test-workflow to the workflow contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_created.json b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_created.json index 5828032f4..59662ef89 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_created.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_created.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has created the workflow contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_created_by_api_token.json b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_created_by_api_token.json index df7c0419c..4a72866ab 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_created_by_api_token.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_created_by_api_token.json @@ -5,6 +5,7 @@ "ActorType": "API_TOKEN", "ActorID": "2089bb36-e27b-428b-8009-d015c8737c55", "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "API Token 2089bb36-e27b-428b-8009-d015c8737c55 has created the workflow contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_deleted.json b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_deleted.json index 84b7a7d64..44129538b 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_deleted.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_deleted.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has deleted the workflow contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_deleted_by_api_token.json b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_deleted_by_api_token.json index d39fd6235..a8baead52 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_deleted_by_api_token.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_deleted_by_api_token.json @@ -5,6 +5,7 @@ "ActorType": "API_TOKEN", "ActorID": "2089bb36-e27b-428b-8009-d015c8737c55", "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "API Token 2089bb36-e27b-428b-8009-d015c8737c55 has deleted the workflow contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_updated.json b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_updated.json index a9811a709..8ad4dfff6 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_updated.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_updated.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has updated the workflow contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_updated_by_api_token.json b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_updated_by_api_token.json index 18cad7378..b29e27415 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_updated_by_api_token.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_contract_updated_by_api_token.json @@ -5,6 +5,7 @@ "ActorType": "API_TOKEN", "ActorID": "2089bb36-e27b-428b-8009-d015c8737c55", "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "API Token 2089bb36-e27b-428b-8009-d015c8737c55 has updated the workflow contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_detached_from_contract.json b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_detached_from_contract.json index 5d6ce4c59..255daf323 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_detached_from_contract.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_detached_from_contract.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has detached the workflow test-workflow from the workflow contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_detached_from_contract_by_api_token.json b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_detached_from_contract_by_api_token.json index 27507a136..bb0c8011b 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_detached_from_contract_by_api_token.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflowcontracts/workflow_detached_from_contract_by_api_token.json @@ -5,6 +5,7 @@ "ActorType": "API_TOKEN", "ActorID": "2089bb36-e27b-428b-8009-d015c8737c55", "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "API Token 2089bb36-e27b-428b-8009-d015c8737c55 has detached the workflow test-workflow from the workflow contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_created.json b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_created.json index 016e03ec1..445dbb435 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_created.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_created.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has created the workflow test-workflow on project test-project with the contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_created_by_api_token.json b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_created_by_api_token.json index 5df692dd9..bfb112e9e 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_created_by_api_token.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_created_by_api_token.json @@ -5,6 +5,7 @@ "ActorType": "API_TOKEN", "ActorID": "2089bb36-e27b-428b-8009-d015c8737c55", "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "API Token 2089bb36-e27b-428b-8009-d015c8737c55 has created the workflow test-workflow on project test-project with the contract test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_deleted.json b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_deleted.json index 64c0387f6..204053bbd 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_deleted.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_deleted.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has deleted the workflow test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_deleted_by_api_token.json b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_deleted_by_api_token.json index 8a231d4dd..39373bd5c 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_deleted_by_api_token.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_deleted_by_api_token.json @@ -5,6 +5,7 @@ "ActorType": "API_TOKEN", "ActorID": "2089bb36-e27b-428b-8009-d015c8737c55", "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "API Token 2089bb36-e27b-428b-8009-d015c8737c55 has deleted the workflow test-contract", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated.json b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated.json index c632dafbc..c78b9abd7 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has updated the workflow test-contract on project test-project", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_by_api_token.json b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_by_api_token.json index a65dec314..4e951123a 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_by_api_token.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_by_api_token.json @@ -5,6 +5,7 @@ "ActorType": "API_TOKEN", "ActorID": "2089bb36-e27b-428b-8009-d015c8737c55", "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "API Token 2089bb36-e27b-428b-8009-d015c8737c55 has updated the workflow test-contract on project test-project", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_with_workflow_contract.json b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_with_workflow_contract.json index b48cfa745..0309f03d7 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_with_workflow_contract.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_with_workflow_contract.json @@ -5,6 +5,7 @@ "ActorType": "USER", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "john@cyberdyne.io", + "ActorName": "John Doe", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "john@cyberdyne.io has updated the workflow test-contract on project test-project", "Info": { diff --git a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_with_workflow_contract_by_api_token.json b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_with_workflow_contract_by_api_token.json index 4aec0af2e..9f9cddfbb 100644 --- a/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_with_workflow_contract_by_api_token.json +++ b/app/controlplane/pkg/auditor/events/testdata/workflows/workflow_updated_with_workflow_contract_by_api_token.json @@ -5,6 +5,7 @@ "ActorType": "API_TOKEN", "ActorID": "1089bb36-e27b-428b-8009-d015c8737c54", "ActorEmail": "", + "ActorName": "test-token", "OrgID": "1089bb36-e27b-428b-8009-d015c8737c54", "Description": "API Token 1089bb36-e27b-428b-8009-d015c8737c54 has updated the workflow test-contract on project test-project", "Info": { diff --git a/app/controlplane/pkg/auditor/events/user_test.go b/app/controlplane/pkg/auditor/events/user_test.go index 2a2049779..28ba7a44e 100644 --- a/app/controlplane/pkg/auditor/events/user_test.go +++ b/app/controlplane/pkg/auditor/events/user_test.go @@ -1,5 +1,5 @@ // -// Copyright 2024 The Chainloop Authors. +// Copyright 2024-2025 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -82,7 +82,7 @@ func TestUserEvents(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { opts := []auditor.GeneratorOption{ - auditor.WithActor(auditor.ActorTypeUser, userUUID, testEmail), + auditor.WithActor(auditor.ActorTypeUser, userUUID, testEmail, testName), auditor.WithOrgID(orgUUID), } diff --git a/app/controlplane/pkg/auditor/events/workflow_test.go b/app/controlplane/pkg/auditor/events/workflow_test.go index 57fa3e193..e45da3ce1 100644 --- a/app/controlplane/pkg/auditor/events/workflow_test.go +++ b/app/controlplane/pkg/auditor/events/workflow_test.go @@ -191,9 +191,9 @@ func TestWorkflowEvents(t *testing.T) { auditor.WithOrgID(orgUUID), } if tt.actor == auditor.ActorTypeAPIToken { - opts = append(opts, auditor.WithActor(auditor.ActorTypeAPIToken, tt.actorID, "")) + opts = append(opts, auditor.WithActor(auditor.ActorTypeAPIToken, tt.actorID, "", testAPITokenName)) } else { - opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, tt.actorID, testEmail)) + opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, tt.actorID, testEmail, testName)) } eventPayload, err := auditor.GenerateAuditEvent(tt.event, opts...) diff --git a/app/controlplane/pkg/auditor/events/workflowcontract_test.go b/app/controlplane/pkg/auditor/events/workflowcontract_test.go index 39f235e47..92b31f2ea 100644 --- a/app/controlplane/pkg/auditor/events/workflowcontract_test.go +++ b/app/controlplane/pkg/auditor/events/workflowcontract_test.go @@ -1,5 +1,5 @@ // -// Copyright 2024 The Chainloop Authors. +// Copyright 2024-2025 The Chainloop Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -196,9 +196,9 @@ func TestWorkflowContractEvents(t *testing.T) { auditor.WithOrgID(orgUUID), } if tt.actor == auditor.ActorTypeAPIToken { - opts = append(opts, auditor.WithActor(auditor.ActorTypeAPIToken, tt.actorID, "")) + opts = append(opts, auditor.WithActor(auditor.ActorTypeAPIToken, tt.actorID, "", testAPITokenName)) } else { - opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, tt.actorID, testEmail)) + opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, tt.actorID, testEmail, testName)) } eventPayload, err := auditor.GenerateAuditEvent(tt.event, opts...) diff --git a/app/controlplane/pkg/auditor/logentry.go b/app/controlplane/pkg/auditor/logentry.go index 67137e2e2..3580a6927 100644 --- a/app/controlplane/pkg/auditor/logentry.go +++ b/app/controlplane/pkg/auditor/logentry.go @@ -62,6 +62,7 @@ type DescriptionVariables struct { ActorType ActorType ActorID *uuid.UUID ActorEmail string + ActorName string OrgID *uuid.UUID } @@ -79,6 +80,7 @@ type AuditEventPayload struct { ActorType ActorType ActorID *uuid.UUID ActorEmail string + ActorName string OrgID *uuid.UUID Description string Info json.RawMessage @@ -135,6 +137,7 @@ func GenerateAuditEvent(entry LogEntry, opts ...GeneratorOption) (*EventPayload, Info: actionInfo, ActorType: options.ActorType, ActorID: options.ActorID, + ActorName: options.ActorName, ActorEmail: options.ActorEmail, OrgID: options.OrgID, Digest: digest, @@ -161,6 +164,7 @@ func interpolateDescription(tmplStr string, variables *GeneratorOptions) (string if err = tmpl.Execute(description, &DescriptionVariables{ ActorType: variables.ActorType, ActorID: variables.ActorID, + ActorName: variables.ActorName, ActorEmail: variables.ActorEmail, OrgID: variables.OrgID, }); err != nil { @@ -175,10 +179,11 @@ type GeneratorOptions struct { ActorType ActorType ActorID *uuid.UUID ActorEmail string + ActorName string OrgID *uuid.UUID } -func WithActor(actorType ActorType, actorID uuid.UUID, email string) GeneratorOption { +func WithActor(actorType ActorType, actorID uuid.UUID, email, name string) GeneratorOption { return func(a *GeneratorOptions) error { if actorType == "" { return errors.New("actor type is required") @@ -198,6 +203,10 @@ func WithActor(actorType ActorType, actorID uuid.UUID, email string) GeneratorOp a.ActorEmail = email } + if name != "" { + a.ActorName = name + } + return nil } } diff --git a/app/controlplane/pkg/biz/auditor.go b/app/controlplane/pkg/biz/auditor.go index 49bc806a6..1afe7f48b 100644 --- a/app/controlplane/pkg/biz/auditor.go +++ b/app/controlplane/pkg/biz/auditor.go @@ -49,15 +49,16 @@ func (uc *AuditorUseCase) Dispatch(ctx context.Context, entry auditor.LogEntry, case entities.CurrentUser(ctx) != nil: user := entities.CurrentUser(ctx) parsedUUID, _ := uuid.Parse(user.ID) - opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, parsedUUID, user.Email)) + fullName := fmt.Sprintf("%s %s", user.FirstName, user.LastName) + opts = append(opts, auditor.WithActor(auditor.ActorTypeUser, parsedUUID, user.Email, fullName)) gotActor = true case entities.CurrentAPIToken(ctx) != nil: apiToken := entities.CurrentAPIToken(ctx) parsedUUID, _ := uuid.Parse(apiToken.ID) - opts = append(opts, auditor.WithActor(auditor.ActorTypeAPIToken, parsedUUID, "")) + opts = append(opts, auditor.WithActor(auditor.ActorTypeAPIToken, parsedUUID, "", apiToken.Name)) gotActor = true default: - opts = append(opts, auditor.WithActor(auditor.ActorTypeSystem, uuid.Nil, "")) + opts = append(opts, auditor.WithActor(auditor.ActorTypeSystem, uuid.Nil, "", "")) } if !gotActor && entry.RequiresActor() {