diff --git a/cmd/bucket-replication.go b/cmd/bucket-replication.go index 4f6a4b333..0e6e44183 100644 --- a/cmd/bucket-replication.go +++ b/cmd/bucket-replication.go @@ -372,9 +372,11 @@ func replicateDelete(ctx context.Context, dobj DeletedObjectReplicationInfo, obj defer func() { replStatus := string(replicationStatus) - auditLogInternal(context.Background(), bucket, dobj.ObjectName, AuditLogOptions{ + auditLogInternal(context.Background(), AuditLogOptions{ Event: dobj.EventType, APIName: ReplicateDeleteAPI, + Bucket: bucket, + Object: dobj.ObjectName, VersionID: versionID, Status: replStatus, }) @@ -903,9 +905,11 @@ func replicateObject(ctx context.Context, ri ReplicateObjectInfo, objectAPI Obje // on disk. replicationStatus = ri.ReplicationStatus } - auditLogInternal(ctx, ri.Bucket, ri.Name, AuditLogOptions{ + auditLogInternal(ctx, AuditLogOptions{ Event: ri.EventType, APIName: ReplicateObjectAPI, + Bucket: ri.Bucket, + Object: ri.Name, VersionID: ri.VersionID, Status: replicationStatus.String(), }) diff --git a/cmd/data-scanner.go b/cmd/data-scanner.go index 1d238dd59..1e0f322cd 100644 --- a/cmd/data-scanner.go +++ b/cmd/data-scanner.go @@ -1441,9 +1441,11 @@ func auditLogLifecycle(ctx context.Context, oi ObjectInfo, event string) { case ILMTransition: apiName = "ILMTransition" } - auditLogInternal(ctx, oi.Bucket, oi.Name, AuditLogOptions{ + auditLogInternal(ctx, AuditLogOptions{ Event: event, APIName: apiName, + Bucket: oi.Bucket, + Object: oi.Name, VersionID: oi.VersionID, }) } diff --git a/cmd/erasure-object.go b/cmd/erasure-object.go index 314b36efa..71ac3334f 100644 --- a/cmd/erasure-object.go +++ b/cmd/erasure-object.go @@ -439,10 +439,32 @@ func (er erasureObjects) GetObjectInfo(ctx context.Context, bucket, object strin return er.getObjectInfo(ctx, bucket, object, opts) } +func auditDanglingObjectDeletion(ctx context.Context, bucket, object, versionID string, pool, set, objectParity int) { + if len(logger.AuditTargets()) == 0 { + return + } + tags := make(map[string]interface{}) + tags["pool"] = pool + tags["set"] = set + tags["objectParity"] = objectParity + + opts := AuditLogOptions{ + Event: "DeleteDanglingObject", + Bucket: bucket, + Object: object, + VersionID: versionID, + Tags: tags, + } + + auditLogInternal(ctx, opts) +} + func (er erasureObjects) deleteIfDangling(ctx context.Context, bucket, object string, metaArr []FileInfo, errs []error, dataErrs []error, opts ObjectOptions) (FileInfo, error) { var err error m, ok := isObjectDangling(metaArr, errs, dataErrs) if ok { + defer auditDanglingObjectDeletion(ctx, bucket, object, m.VersionID, er.poolIndex, er.setIndex, m.Erasure.ParityBlocks) + err = errFileNotFound if opts.VersionID != "" { err = errFileVersionNotFound diff --git a/cmd/erasure-server-pool-decom.go b/cmd/erasure-server-pool-decom.go index bd5b7357a..31cbe9609 100644 --- a/cmd/erasure-server-pool-decom.go +++ b/cmd/erasure-server-pool-decom.go @@ -1274,9 +1274,11 @@ func auditLogDecom(ctx context.Context, apiName, bucket, object, versionID strin if err != nil { errStr = err.Error() } - auditLogInternal(ctx, bucket, object, AuditLogOptions{ + auditLogInternal(ctx, AuditLogOptions{ Event: "decommission", APIName: apiName, + Bucket: bucket, + Object: object, VersionID: versionID, Error: errStr, }) diff --git a/cmd/utils.go b/cmd/utils.go index e487c9cc7..dc9866130 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -1026,28 +1026,38 @@ type AuditLogOptions struct { Event string APIName string Status string + Bucket string + Object string VersionID string Error string + Tags map[string]interface{} } // sends audit logs for internal subsystem activity -func auditLogInternal(ctx context.Context, bucket, object string, opts AuditLogOptions) { +func auditLogInternal(ctx context.Context, opts AuditLogOptions) { + if len(logger.AuditTargets()) == 0 { + return + } entry := audit.NewEntry(globalDeploymentID) entry.Trigger = opts.Event entry.Event = opts.Event entry.Error = opts.Error entry.API.Name = opts.APIName - entry.API.Bucket = bucket - entry.API.Object = object - if opts.VersionID != "" { - entry.ReqQuery = make(map[string]string) - entry.ReqQuery[xhttp.VersionID] = opts.VersionID - } + entry.API.Bucket = opts.Bucket + entry.API.Objects = []audit.ObjectVersion{{ObjectName: opts.Object, VersionID: opts.VersionID}} entry.API.Status = opts.Status + entry.Tags = opts.Tags // Merge tag information if found - this is currently needed for tags // set during decommissioning. if reqInfo := logger.GetReqInfo(ctx); reqInfo != nil { - entry.Tags = reqInfo.GetTagsMap() + if tags := reqInfo.GetTagsMap(); len(tags) > 0 { + if entry.Tags == nil { + entry.Tags = make(map[string]interface{}, len(tags)) + } + for k, v := range tags { + entry.Tags[k] = v + } + } } ctx = logger.SetAuditEntry(ctx, &entry) logger.AuditLog(ctx, nil, nil, nil)