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 storage id to audit log for spaces #6548

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
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