From 7a58511ee2659b0b1a37da80b67556cc016e5420 Mon Sep 17 00:00:00 2001 From: David Christofas Date: Thu, 9 Jun 2022 12:23:34 +0200 Subject: [PATCH] handle event container created in audit service --- changelog/unreleased/container-created-audit.md | 5 +++++ extensions/audit/pkg/service/service.go | 2 ++ extensions/audit/pkg/types/constants.go | 8 +++++++- extensions/audit/pkg/types/conversion.go | 9 +++++++++ extensions/audit/pkg/types/types.go | 5 +++++ 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 changelog/unreleased/container-created-audit.md diff --git a/changelog/unreleased/container-created-audit.md b/changelog/unreleased/container-created-audit.md new file mode 100644 index 00000000000..8a0fb8df9e8 --- /dev/null +++ b/changelog/unreleased/container-created-audit.md @@ -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 diff --git a/extensions/audit/pkg/service/service.go b/extensions/audit/pkg/service/service.go index 1b5f7ae0360..1e42a80caa6 100644 --- a/extensions/audit/pkg/service/service.go +++ b/extensions/audit/pkg/service/service.go @@ -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: diff --git a/extensions/audit/pkg/types/constants.go b/extensions/audit/pkg/types/constants.go index a6bdfd119ce..d565794a19e 100644 --- a/extensions/audit/pkg/types/constants.go +++ b/extensions/audit/pkg/types/constants.go @@ -21,6 +21,7 @@ const ( ActionLinkAccessed = "public_link_accessed" // Files + ActionContainerCreated = "container_create" ActionFileCreated = "file_create" ActionFileRead = "file_read" ActionFileTrashed = "file_delete" @@ -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 @@ -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("Container '%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) diff --git a/extensions/audit/pkg/types/conversion.go b/extensions/audit/pkg/types/conversion.go index 2140f485f82..3cbfeaa329f 100644 --- a/extensions/audit/pkg/types/conversion.go +++ b/extensions/audit/pkg/types/conversion.go @@ -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) diff --git a/extensions/audit/pkg/types/types.go b/extensions/audit/pkg/types/types.go index 903ca2345ff..c26b44a03f3 100644 --- a/extensions/audit/pkg/types/types.go +++ b/extensions/audit/pkg/types/types.go @@ -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