-
Notifications
You must be signed in to change notification settings - Fork 138
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
CBG-4046 add attachment and create, update, delete events #6988
Conversation
a066f72
to
d037861
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall approach looks good, some questions about attachment name. Might merit unit tests to verify auditing of name is consistent across create/update/delete and via different pathways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks fine. Some comment and code style comments, but can leave those to come back to in future.
db/crud.go
Outdated
if doc.IsDeleted() { | ||
base.Audit(ctx, base.AuditIDDocumentDelete, base.AuditFields{ | ||
base.AuditFieldDocID: docid, | ||
base.AuditFieldDocVersion: newRevID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tombstones can have channels - feels like we should be including base.AuditFieldChannels here too.
}, | ||
|
||
optionalFieldGroups: []fieldGroup{ | ||
fieldGroupRequest, // this will be present everywhere except tests, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect this comment should match the one for Delete, since exceptions would be the same?
base/audit_events.go
Outdated
fieldGroupKeyspace, | ||
}, | ||
optionalFieldGroups: []fieldGroup{ | ||
fieldGroupRequest, // this is not present on ISGR or import, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be included on AuditIDDocumentUpdate and AuditIDDocumentCreate (or omitted here)?
db/database.go
Outdated
return base.UserLogCtx(ctx, "rosmar_noauth", base.UserDomainBuiltin, nil) | ||
} | ||
username, _, _ := dbCtx.BucketSpec.Auth.GetCredentials() | ||
return base.UserLogCtx(ctx, username, base.UserDomainBuiltin, nil) // FIXME, should I pick up roles? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bbrks what's your take on this question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed. Roles are passed for filtering only. In the case of builtin
users, people can use the username based filtering if they don't want these audit events.
@@ -536,7 +536,8 @@ func (rt *RestTester) GetUserAdminAPI(username string) auth.PrincipalConfig { | |||
// GetSingleTestDatabaseCollection will return a DatabaseCollection if there is only one. Depending on test environment configuration, it may or may not be the default collection. | |||
func (rt *RestTester) GetSingleTestDatabaseCollection() (*db.DatabaseCollection, context.Context) { | |||
c := db.GetSingleDatabaseCollection(rt.TB(), rt.GetDatabase()) | |||
return c, c.AddCollectionContext(rt.Context()) | |||
ctx := base.UserLogCtx(c.AddCollectionContext(rt.Context()), "gotest", base.UserDomainBuiltin, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UserLogCtx feels like it is getting set arbitrarily in a lot of places. Can you help me understand the general approach we're using to decide whether to set "gotest"? I would have thought a DatabaseCollection shouldn't have a user context (since it's not a DatabaseCollectionWithUser).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for code that works directly in a test: collection.Put(ctx, ..) needs a user and this provides a user. I wanted to make it clear that this wasn't a real user. This is for cases like import tests where we directly call functions outside of REST calls.
rest/doc_api.go
Outdated
@@ -644,6 +648,10 @@ func (h *handler) handleGetLocalDoc() error { | |||
} | |||
value[db.BodyId] = "_local/" + docid | |||
h.writeJSON(value) | |||
base.Audit(h.ctx(), base.AuditIDDocumentRead, base.AuditFields{ | |||
base.AuditFieldDocID: docid, | |||
base.AuditFieldDocVersion: value[db.BodyRev], // this value might not be populated if this is a doc that starts with _sync |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I don't think BodyRev is a required field for local docs. Can we just remove this?
rest/audit_test.go
Outdated
events := jsonLines(rt.TB(), output) | ||
countFound := 0 | ||
for _, event := range events { | ||
// skip events that are not document read events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// skip events that are not document read events | |
// skip events that are not the target eventID |
rest/audit_test.go
Outdated
@@ -974,6 +1120,22 @@ func requireDocumentReadEvents(rt *RestTester, output []byte, docID string, docV | |||
require.Equal(rt.TB(), docVersions, docVersionsFound) | |||
} | |||
|
|||
// requireAttachmentEvents validates that create attachment events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the idea that this expects that eventID is one of the attachment crud event IDs?
rest/bulk_api.go
Outdated
if atts, ok := body[db.BodyAttachments]; ok && atts != nil { | ||
attsMap, ok := atts.(db.AttachmentsMeta) | ||
if !ok { | ||
base.WarnfCtx(h.ctx(), "Unexpected format of attachments in the body %+v", atts) | ||
} | ||
for attachment := range attsMap { | ||
base.Audit(h.ctx(), base.AuditIDAttachmentRead, base.AuditFields{ | ||
base.AuditFieldDocID: docid, | ||
base.AuditFieldDocVersion: revid, | ||
base.AuditFieldAttachmentID: attachment, | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only reading metadata of the attachment, unless includeAttachments
is set.
Does this need to be conditional?
db/raw_doc_with_inline_sync.json
Outdated
@@ -0,0 +1,14 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd rather be more deliberate about switching to the use of embed and standalone json files for testing, instead of just adding this single standalone file - would like to think about organization, packaging, etc. Any reason this can't be inline with the test file, like we do in other spots?
@@ -2355,7 +2399,7 @@ func (db *DatabaseCollectionWithUser) DeleteDoc(ctx context.Context, docid strin | |||
} | |||
|
|||
// Purges a document from the bucket (no tombstone) | |||
func (db *DatabaseCollectionWithUser) Purge(ctx context.Context, key string) error { | |||
func (db *DatabaseCollectionWithUser) Purge(ctx context.Context, key string, needsAudit bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing any cases that call this with needsAudit=false. Are there such cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The single case is
Line 1497 in 1fff8bb
purgeErr := collection.Purge(ctx, tombstonesRow.Id) |
I added tests for REST api and didn't add tests for blip code.
Pre-review checklist
fmt.Print
,log.Print
, ...)base.UD(docID)
,base.MD(dbName)
)docs/api
Integration Tests
GSI=true,xattrs=true
https://jenkins.sgwdev.com/job/SyncGateway-Integration/2613/