Skip to content

Commit

Permalink
Merge pull request #6548 from dragonchaser/issue-3753-issues-with-aud…
Browse files Browse the repository at this point in the history
…it-storage_id_missing

add storage id to audit log for spaces
  • Loading branch information
dragonchaser authored Jun 19, 2023
2 parents 7a2afee + 2d60212 commit 30010ad
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/add-storage-id-to-audit-log.md
Original file line number Diff line number Diff line change
@@ -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
30 changes: 15 additions & 15 deletions services/audit/pkg/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand All @@ -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",
},
Expand All @@ -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)
},
Expand All @@ -511,51 +511,51 @@ 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) {
ev := types.AuditEventSpaceDisabled{}
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) {
ev := types.AuditEventSpaceEnabled{}
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) {
ev := types.AuditEventSpaceDeleted{}
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")
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 30010ad

Please sign in to comment.