diff --git a/changelog/unreleased/add-storage-id-to-audit-log.md b/changelog/unreleased/add-storage-id-to-audit-log.md new file mode 100644 index 000000000..dd9eb887a --- /dev/null +++ b/changelog/unreleased/add-storage-id-to-audit-log.md @@ -0,0 +1,6 @@ +Enhancement: We added the storage id to the audit log for spaces + +We added the storage id to the audit log for spaces + +https://github.com/owncloud/ocis/pull/6548 +https://github.com/owncloud/ocis/issues/3753 \ No newline at end of file diff --git a/services/audit/pkg/service/service_test.go b/services/audit/pkg/service/service_test.go index d612783c1..2cc358514 100644 --- a/services/audit/pkg/service/service_test.go +++ b/services/audit/pkg/service/service_test.go @@ -462,7 +462,7 @@ var testCases = []struct { SystemEvent: events.Event{ Event: events.SpaceCreated{ Executant: userID("uid-123"), - ID: &provider.StorageSpaceId{OpaqueId: "space-123"}, + ID: &provider.StorageSpaceId{OpaqueId: "storage-1$space-123"}, Owner: userID("uid-123"), Root: resourceID("pro-1", "sto-123", "iid-123"), Name: "test-space", @@ -476,9 +476,9 @@ var testCases = []struct { require.NoError(t, json.Unmarshal(b, &ev)) // AuditEvent fields - checkBaseAuditEvent(t, ev.AuditEvent, "", "2286-11-20T17:46:40Z", "user 'uid-123' created a space 'space-123' with name 'test-space'", "space_created") + checkBaseAuditEvent(t, ev.AuditEvent, "", "2286-11-20T17:46:40Z", "user 'uid-123' created a space 'space-123' with name 'test-space' (storage: 'storage-1')", "space_created") // AuditEventSpaces fields - checkSpacesAuditEvent(t, ev.AuditEventSpaces, "space-123") + checkSpacesAuditEvent(t, ev.AuditEventSpaces, "storage-1$space-123") // AuditEventFileRestored fields require.Equal(t, "uid-123", ev.Owner) require.Equal(t, "pro-1$sto-123!iid-123", ev.RootItem) @@ -490,7 +490,7 @@ var testCases = []struct { SystemEvent: events.Event{ Event: events.SpaceRenamed{ Executant: userID("uid-123"), - ID: &provider.StorageSpaceId{OpaqueId: "space-123"}, + ID: &provider.StorageSpaceId{OpaqueId: "storage-1$space-123"}, Owner: userID("uid-123"), Name: "new-name", }, @@ -500,9 +500,9 @@ var testCases = []struct { require.NoError(t, json.Unmarshal(b, &ev)) // AuditEvent fields - checkBaseAuditEvent(t, ev.AuditEvent, "", "", "user 'uid-123' renamed space 'space-123' to 'new-name'", "space_renamed") + checkBaseAuditEvent(t, ev.AuditEvent, "", "", "user 'uid-123' renamed space 'space-123' to 'new-name' (storage: 'storage-1')", "space_renamed") // AuditEventSpaces fields - checkSpacesAuditEvent(t, ev.AuditEventSpaces, "space-123") + checkSpacesAuditEvent(t, ev.AuditEventSpaces, "storage-1$space-123") // AuditEventSpaceRenamed fields require.Equal(t, "new-name", ev.NewName) }, @@ -511,7 +511,7 @@ var testCases = []struct { SystemEvent: events.Event{ Event: events.SpaceDisabled{ Executant: userID("uid-123"), - ID: &provider.StorageSpaceId{OpaqueId: "space-123"}, + ID: &provider.StorageSpaceId{OpaqueId: "storage-1$space-123"}, }, }, CheckAuditEvent: func(t *testing.T, b []byte) { @@ -519,16 +519,16 @@ var testCases = []struct { require.NoError(t, json.Unmarshal(b, &ev)) // AuditEvent fields - checkBaseAuditEvent(t, ev.AuditEvent, "", "0001-01-01T00:00:00Z", "user 'uid-123' disabled the space 'space-123'", "space_disabled") + checkBaseAuditEvent(t, ev.AuditEvent, "", "0001-01-01T00:00:00Z", "user 'uid-123' disabled the space 'space-123' (storage: 'storage-1')", "space_disabled") // AuditEventSpaces fields - checkSpacesAuditEvent(t, ev.AuditEventSpaces, "space-123") + checkSpacesAuditEvent(t, ev.AuditEventSpaces, "storage-1$space-123") }, }, { Alias: "Space enabled", SystemEvent: events.Event{ Event: events.SpaceEnabled{ Executant: userID("uid-123"), - ID: &provider.StorageSpaceId{OpaqueId: "space-123"}, + ID: &provider.StorageSpaceId{OpaqueId: "storage-1$space-123"}, }, }, CheckAuditEvent: func(t *testing.T, b []byte) { @@ -536,16 +536,16 @@ var testCases = []struct { require.NoError(t, json.Unmarshal(b, &ev)) // AuditEvent fields - checkBaseAuditEvent(t, ev.AuditEvent, "", "", "user 'uid-123' (re-) enabled the space 'space-123'", "space_enabled") + checkBaseAuditEvent(t, ev.AuditEvent, "", "", "user 'uid-123' (re-) enabled the space 'space-123' (storage: 'storage-1')", "space_enabled") // AuditEventSpaces fields - checkSpacesAuditEvent(t, ev.AuditEventSpaces, "space-123") + checkSpacesAuditEvent(t, ev.AuditEventSpaces, "storage-1$space-123") }, }, { Alias: "Space deleted", SystemEvent: events.Event{ Event: events.SpaceDeleted{ Executant: userID("uid-123"), - ID: &provider.StorageSpaceId{OpaqueId: "space-123"}, + ID: &provider.StorageSpaceId{OpaqueId: "storage-1$space-123"}, }, }, CheckAuditEvent: func(t *testing.T, b []byte) { @@ -553,9 +553,9 @@ var testCases = []struct { require.NoError(t, json.Unmarshal(b, &ev)) // AuditEvent fields - checkBaseAuditEvent(t, ev.AuditEvent, "", "0001-01-01T00:00:00Z", "user 'uid-123' deleted the space 'space-123'", "space_deleted") + checkBaseAuditEvent(t, ev.AuditEvent, "", "0001-01-01T00:00:00Z", "user 'uid-123' deleted the space 'space-123' (storage: 'storage-1')", "space_deleted") // AuditEventSpaces fields - checkSpacesAuditEvent(t, ev.AuditEventSpaces, "space-123") + checkSpacesAuditEvent(t, ev.AuditEventSpaces, "storage-1$space-123") }, }, } diff --git a/services/audit/pkg/types/constants.go b/services/audit/pkg/types/messages.go similarity index 87% rename from services/audit/pkg/types/constants.go rename to services/audit/pkg/types/messages.go index e41f53ba6..049e08f5b 100644 --- a/services/audit/pkg/types/constants.go +++ b/services/audit/pkg/types/messages.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/cs3org/reva/v2/pkg/events" + "github.com/cs3org/reva/v2/pkg/storagespace" ) // short identifiers for audit actions @@ -139,43 +140,51 @@ func MessageFileVersionRestored(executant, item, version string) string { // MessageSpaceCreated returns the human readable string that describes the action func MessageSpaceCreated(executant, spaceID, name string) string { - return fmt.Sprintf("user '%s' created a space '%s' with name '%s'", executant, spaceID, name) + storagID, spaceID := storagespace.SplitStorageID(spaceID) + return fmt.Sprintf("user '%s' created a space '%s' with name '%s' (storage: '%s')", executant, spaceID, name, storagID) } // MessageSpaceRenamed returns the human readable string that describes the action func MessageSpaceRenamed(executant, spaceID, name string) string { - return fmt.Sprintf("user '%s' renamed space '%s' to '%s'", executant, spaceID, name) + storagID, spaceID := storagespace.SplitStorageID(spaceID) + return fmt.Sprintf("user '%s' renamed space '%s' to '%s' (storage: '%s')", executant, spaceID, name, storagID) } // MessageSpaceDisabled returns the human readable string that describes the action func MessageSpaceDisabled(executant, spaceID string) string { - return fmt.Sprintf("user '%s' disabled the space '%s'", executant, spaceID) + storagID, spaceID := storagespace.SplitStorageID(spaceID) + return fmt.Sprintf("user '%s' disabled the space '%s' (storage: '%s')", executant, spaceID, storagID) } // MessageSpaceEnabled returns the human readable string that describes the action func MessageSpaceEnabled(executant, spaceID string) string { - return fmt.Sprintf("user '%s' (re-) enabled the space '%s'", executant, spaceID) + storagID, spaceID := storagespace.SplitStorageID(spaceID) + return fmt.Sprintf("user '%s' (re-) enabled the space '%s' (storage: '%s')", executant, spaceID, storagID) } // MessageSpaceDeleted returns the human readable string that describes the action func MessageSpaceDeleted(executant, spaceID string) string { - return fmt.Sprintf("user '%s' deleted the space '%s'", executant, spaceID) + storagID, spaceID := storagespace.SplitStorageID(spaceID) + return fmt.Sprintf("user '%s' deleted the space '%s' (storage: '%s')", executant, spaceID, storagID) } // MessageSpaceShared returns the human readable string that describes the action func MessageSpaceShared(executant, spaceID, grantee string) string { - return fmt.Sprintf("user '%s' shared the space '%s' with '%s'", executant, spaceID, grantee) + storagID, spaceID := storagespace.SplitStorageID(spaceID) + return fmt.Sprintf("user '%s' shared the space '%s' with '%s' (storage: '%s')", executant, spaceID, grantee, storagID) } // MessageSpaceUnshared returns the human readable string that describes the action func MessageSpaceUnshared(executant, spaceID, grantee string) string { - return fmt.Sprintf("user '%s' unshared the space '%s' with '%s'", executant, spaceID, grantee) + storagID, spaceID := storagespace.SplitStorageID(spaceID) + return fmt.Sprintf("user '%s' unshared the space '%s' with '%s' (storage: '%s')", executant, spaceID, grantee, storagID) } // MessageSpaceUpdated returns the human readable string that describes the action func MessageSpaceUpdated(executant, spaceID, name string, quota uint64, opaque map[string]string) string { - return fmt.Sprintf("user '%s' updated space '%s'. name: '%s', quota: '%d', opaque: '%s'", - executant, spaceID, name, quota, opaque) + storagID, spaceID := storagespace.SplitStorageID(spaceID) + return fmt.Sprintf("user '%s' updated space '%s'. name: '%s', quota: '%d', opaque: '%s' (storage: '%s')", + executant, spaceID, name, quota, opaque, storagID) } // MessageUserCreated returns the human readable string that describes the action