Skip to content

Commit

Permalink
Merge pull request #3941 from owncloud/container-created-audit
Browse files Browse the repository at this point in the history
handle event container created in audit service
  • Loading branch information
David Christofas authored Jun 10, 2022
2 parents 383b58f + ee184a0 commit ed50570
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/unreleased/container-created-audit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add audit events for created containers

Handle the event `ContainerCreated` in the audit service.

https://github.com/owncloud/ocis/pull/3941
2 changes: 2 additions & 0 deletions extensions/audit/pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func StartAuditLogger(ctx context.Context, ch <-chan interface{}, log log.Logger
auditEvent = types.LinkAccessed(ev)
case events.LinkAccessFailed:
auditEvent = types.LinkAccessFailed(ev)
case events.ContainerCreated:
auditEvent = types.ContainerCreated(ev)
case events.FileUploaded:
auditEvent = types.FileUploaded(ev)
case events.FileDownloaded:
Expand Down
8 changes: 7 additions & 1 deletion extensions/audit/pkg/types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
ActionLinkAccessed = "public_link_accessed"

// Files
ActionContainerCreated = "container_create"
ActionFileCreated = "file_create"
ActionFileRead = "file_read"
ActionFileTrashed = "file_delete"
Expand Down Expand Up @@ -55,7 +56,7 @@ func MessageShareCreated(sharer, item, grantee string) string {

// MessageLinkCreated returns the human readable string that describes the action
func MessageLinkCreated(sharer, item, shareid string) string {
return fmt.Sprintf("user '%s' created a public to file '%s' with id '%s'", sharer, item, shareid)
return fmt.Sprintf("user '%s' created a public link to file '%s' with id '%s'", sharer, item, shareid)
}

// MessageShareUpdated returns the human readable string that describes the action
Expand Down Expand Up @@ -93,6 +94,11 @@ func MessageLinkAccessed(linkid string, success bool) string {
return fmt.Sprintf("link '%s' was accessed. Success: %v", linkid, success)
}

// MessageContainerCreated returns the human readable string that describes the action
func MessageContainerCreated(item string) string {
return fmt.Sprintf("Folder '%s' was created", item)
}

// MessageFileCreated returns the human readable string that describes the action
func MessageFileCreated(item string) string {
return fmt.Sprintf("File '%s' was created", item)
Expand Down
9 changes: 9 additions & 0 deletions extensions/audit/pkg/types/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ func FilesAuditEvent(base AuditEvent, itemid, owner, path string) AuditEventFile
}
}

// ContainerCreated converts a ContainerCreated event to an AuditEventContainerCreated
func ContainerCreated(ev events.ContainerCreated) AuditEventContainerCreated {
iid, path, uid := extractFileDetails(ev.Ref, ev.Executant)
base := BasicAuditEvent(uid, "", MessageContainerCreated(iid), ActionContainerCreated)
return AuditEventContainerCreated{
AuditEventFiles: FilesAuditEvent(base, iid, uid, path),
}
}

// FileUploaded converts a FileUploaded event to an AuditEventFileCreated
func FileUploaded(ev events.FileUploaded) AuditEventFileCreated {
iid, path, uid := extractFileDetails(ev.Ref, ev.Owner)
Expand Down
5 changes: 5 additions & 0 deletions extensions/audit/pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ type AuditEventFiles struct {
FileID string // The newly created files identifier.
}

// AuditEventContainerCreated is the event logged when a container is created
type AuditEventContainerCreated struct {
AuditEventFiles
}

// AuditEventFileCreated is the event logged when a file is created
type AuditEventFileCreated struct {
AuditEventFiles
Expand Down

0 comments on commit ed50570

Please sign in to comment.