Handle more events (#5071)

* Handle SpaceShared events

* Adapt to changed ID in the SpaceShared event

* Handle the SpaceUnshared events

* Handle the SpaceUpdated event

* update reva to latest edge

* fix typo

* Disable cyclomatic complexity check for StartAuditLogger

Co-authored-by: Michael Barz <mbarz@owncloud.com>
This commit is contained in:
Andre Duffeck
2022-11-23 14:00:29 +01:00
committed by GitHub
parent 45c59accd4
commit 1b764d2142
8 changed files with 112 additions and 4 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ require (
github.com/blevesearch/bleve/v2 v2.3.5
github.com/coreos/go-oidc/v3 v3.4.0
github.com/cs3org/go-cs3apis v0.0.0-20221012090518-ef2996678965
github.com/cs3org/reva/v2 v2.10.1-0.20221111140957-723ad781d916
github.com/cs3org/reva/v2 v2.10.1-0.20221122203801-810f981c8d9b
github.com/disintegration/imaging v1.6.2
github.com/ggwhite/go-masker v1.0.9
github.com/go-chi/chi/v5 v5.0.7
+2 -2
View File
@@ -342,8 +342,8 @@ github.com/crewjam/saml v0.4.6 h1:XCUFPkQSJLvzyl4cW9OvpWUbRf0gE7VUpU8ZnilbeM4=
github.com/crewjam/saml v0.4.6/go.mod h1:ZBOXnNPFzB3CgOkRm7Nd6IVdkG+l/wF+0ZXLqD96t1A=
github.com/cs3org/go-cs3apis v0.0.0-20221012090518-ef2996678965 h1:y4n2j68LLnvac+zw/al8MfPgO5aQiIwLmHM/JzYN8AM=
github.com/cs3org/go-cs3apis v0.0.0-20221012090518-ef2996678965/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/reva/v2 v2.10.1-0.20221111140957-723ad781d916 h1:uzhlNkkzwS1Gk/6hqUE445HFV2XpGTdd77hLVnyhvhc=
github.com/cs3org/reva/v2 v2.10.1-0.20221111140957-723ad781d916/go.mod h1:+lH5G0UmNjMNj4F0bDhbh+HqL1UihlbL8zPBa57Y2QI=
github.com/cs3org/reva/v2 v2.10.1-0.20221122203801-810f981c8d9b h1:2/jP2wlUVwkAXSVllR/rwQEn460rmiUZXiuplcJ+T28=
github.com/cs3org/reva/v2 v2.10.1-0.20221122203801-810f981c8d9b/go.mod h1:+lH5G0UmNjMNj4F0bDhbh+HqL1UihlbL8zPBa57Y2QI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8 h1:Z9lwXumT5ACSmJ7WGnFl+OMLLjpz5uR2fyz7dC255FI=
github.com/cubewise-code/go-mime v0.0.0-20200519001935-8c5762b177d8/go.mod h1:4abs/jPXcmJzYoYGF91JF9Uq9s/KL5n1jvFDix8KcqY=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
+8
View File
@@ -35,6 +35,8 @@ func AuditLoggerFromConfig(ctx context.Context, cfg config.Auditlog, ch <-chan i
}
// StartAuditLogger will block. run in separate go routine
//
//nolint:gocyclo
func StartAuditLogger(ctx context.Context, ch <-chan interface{}, log log.Logger, marshaller Marshaller, logto ...Log) {
for {
select {
@@ -87,6 +89,12 @@ func StartAuditLogger(ctx context.Context, ch <-chan interface{}, log log.Logger
auditEvent = types.SpaceEnabled(ev)
case events.SpaceDeleted:
auditEvent = types.SpaceDeleted(ev)
case events.SpaceShared:
auditEvent = types.SpaceShared(ev)
case events.SpaceUnshared:
auditEvent = types.SpaceUnshared(ev)
case events.SpaceUpdated:
auditEvent = types.SpaceUpdated(ev)
case events.UserCreated:
auditEvent = types.UserCreated(ev)
case events.UserDeleted:
+19
View File
@@ -36,6 +36,9 @@ const (
ActionSpaceDisabled = "space_disabled"
ActionSpaceEnabled = "space_enabled"
ActionSpaceDeleted = "space_deleted"
ActionSpaceShared = "space_shared"
ActionSpaceUnshared = "space_unshared"
ActionSpaceUpdated = "space_updated"
// Users
ActionUserCreated = "user_created"
@@ -159,6 +162,22 @@ func MessageSpaceDeleted(executant, spaceID string) string {
return fmt.Sprintf("user '%s' deleted the space '%s'", executant, spaceID)
}
// 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)
}
// 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)
}
// 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)
}
// MessageUserCreated returns the human readable string that describes the action
func MessageUserCreated(executant, userID string) string {
return fmt.Sprintf("user '%s' created the user '%s'", executant, userID)
+54
View File
@@ -11,6 +11,7 @@ import (
user "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
sdk "github.com/cs3org/reva/v2/pkg/sdk/common"
)
const _linktype = "link"
@@ -380,6 +381,59 @@ func SpaceDeleted(ev events.SpaceDeleted) AuditEventSpaceDeleted {
}
}
// SpaceShared converts a SpaceShared event to an AuditEventSpaceShared
func SpaceShared(ev events.SpaceShared) AuditEventSpaceShared {
sse := AuditEventSpaceShared{}
sid := ev.ID.GetOpaqueId()
grantee := "N/A"
if ev.GranteeUserID != nil {
sse.GranteeUserID = ev.GranteeUserID.OpaqueId
grantee = "user:" + ev.GranteeUserID.OpaqueId
} else if ev.GranteeGroupID != nil {
sse.GranteeGroupID = ev.GranteeGroupID.OpaqueId
grantee = "group:" + ev.GranteeGroupID.OpaqueId
}
base := BasicAuditEvent("", "", MessageSpaceShared(ev.Executant.GetOpaqueId(), sid, grantee), ActionSpaceShared)
sse.AuditEventSpaces = SpacesAuditEvent(base, sid)
return sse
}
// SpaceUnshared converts a SpaceUnshared event to an AuditEventSpaceUnshared
func SpaceUnshared(ev events.SpaceUnshared) AuditEventSpaceUnshared {
sue := AuditEventSpaceUnshared{}
sid := ev.ID.GetOpaqueId()
grantee := "N/A"
if ev.GranteeUserID != nil {
sue.GranteeUserID = ev.GranteeUserID.OpaqueId
grantee = "user:" + ev.GranteeUserID.OpaqueId
} else if ev.GranteeGroupID != nil {
sue.GranteeGroupID = ev.GranteeGroupID.OpaqueId
grantee = "group:" + ev.GranteeGroupID.OpaqueId
}
base := BasicAuditEvent("", "", MessageSpaceUnshared(ev.Executant.GetOpaqueId(), sid, grantee), ActionSpaceUnshared)
sue.AuditEventSpaces = SpacesAuditEvent(base, sid)
return sue
}
// SpaceUpdated converts a SpaceUpdated event to an AuditEventSpaceUpdated
func SpaceUpdated(ev events.SpaceUpdated) AuditEventSpaceUpdated {
sid := ev.ID.GetOpaqueId()
opaqueMap := sdk.DecodeOpaqueMap(ev.Space.Opaque)
sue := AuditEventSpaceUpdated{
Name: ev.Space.Name,
Opaque: opaqueMap,
}
base := BasicAuditEvent("", "", MessageSpaceUpdated(ev.Executant.GetOpaqueId(), sid, ev.Space.Name, ev.Space.Quota.QuotaMaxBytes, opaqueMap), ActionSpaceUpdated)
sue.AuditEventSpaces = SpacesAuditEvent(base, sid)
return sue
}
// UserCreated converts a UserCreated event to an AuditEventUserCreated
func UserCreated(ev events.UserCreated) AuditEventUserCreated {
base := BasicAuditEvent("", "", MessageUserCreated(ev.Executant.GetOpaqueId(), ev.UserID), ActionUserCreated)
+2
View File
@@ -30,6 +30,8 @@ func RegisteredEvents() []events.Unmarshaller {
events.SpaceDisabled{},
events.SpaceDeleted{},
events.SpaceShared{},
events.SpaceUnshared{},
events.SpaceUpdated{},
events.UserCreated{},
events.UserDeleted{},
events.UserFeatureChanged{},
+25
View File
@@ -205,6 +205,31 @@ type AuditEventSpaceDeleted struct {
AuditEventSpaces
}
// AuditEventSpaceShared is the event logged when a space is shared
type AuditEventSpaceShared struct {
AuditEventSpaces
GranteeUserID string
GranteeGroupID string
}
// AuditEventSpaceUnshared is the event logged when a space is unshared
type AuditEventSpaceUnshared struct {
AuditEventSpaces
GranteeUserID string
GranteeGroupID string
}
// AuditEventSpaceUpdated is the event logged when a space is updated
type AuditEventSpaceUpdated struct {
AuditEventSpaces
Name string
Opaque map[string]string
QuotaMaxBytes uint64
}
// AuditEventUserCreated is the event logged when a user is created
type AuditEventUserCreated struct {
AuditEvent
@@ -153,7 +153,7 @@ func (s eventsNotifier) handleSpaceShared(e events.SpaceShared) {
return
}
shareLink, err := urlJoinPath(s.ocisURL, "f", storagespace.FormatResourceID(*e.ID))
shareLink, err := urlJoinPath(s.ocisURL, "f", e.ID.OpaqueId)
if err != nil {
s.logger.Error().