Make "security events" part of the audit log#42653
Conversation
|
Codenotify: Notifying subscribers in CODENOTIFY files for diff 6d8c129...d5f7b16.
|
| t.Run("GetRewirerMappings", func(t *testing.T) { | ||
| // Create some test data | ||
| user := bt.CreateTestUser(t, s.DatabaseDB(), true) | ||
| ctx = actor.WithActor(ctx, &actor.Actor{UID: user.ID}) |
There was a problem hiding this comment.
@eseliger @LawnGnome @adeola-ak I needed to get the actor into the context (as it would be in the prod) for a few of the integration tests here. Can you have a look to see if it makes sense to you from a batch changes perspective (tagging you as y'all authored most of the change code).
Context: security events will be enabled by default now, and in order to store a record in security_event_logs we need to comply with the security_event_logs_check_has_user constraint, so we can't have a missing actor.Actor in the context.Context.
There was a problem hiding this comment.
What would happen if the actor is missing? I think this store is also used in background jobs
There was a problem hiding this comment.
@eseliger Crash on the database INSERT, as the missing actor defaults to 0.
err.Message -> new row for relation "security_event_logs" violates check constraint "security_event_logs_check_has_user"
err.Details -> Failing row contains (3, AccessGranted, , 0, , BACKEND, {"service": "___1TestIntegration_in_github_com_sourcegraph_sourc..., 0.0.0+dev, 2022-10-10 09:22:30.009738+00).
There was a problem hiding this comment.
I think that's a problem when we use internal actors, isn't it? 🤔
There was a problem hiding this comment.
That would be my hunch as well.
There was a problem hiding this comment.
@eseliger @kopancek there's a condition that tackles the internal case. Do you think that instead of smashing the actual user into context (in the test code), it's better to setup an internal one?
There was a problem hiding this comment.
for this test in particular, yes I think so :) Also sounds good that we handle the internal case!
There was a problem hiding this comment.
@eseliger changed in https://github.com/sourcegraph/sourcegraph/pull/42653/commits/2a6ac249e11e3b5a4156a698ea89afedd857308e, all tests green.
| } | ||
|
|
||
| func (s *securityEventLogsStore) LogEventList(ctx context.Context, events []*SecurityEvent) { | ||
| // We don't want to begin logging authentication or authorization events in |
There was a problem hiding this comment.
@sourcegraph/repo-management we discussed this in the RFCs (see PR description), but wanted to double-check that it is fine to enable this by default now. I know that we originally worried that having all of these in a multi-tenant setup could be a ton to deal with, but the data volume will be much lower on individual instances.
There was a problem hiding this comment.
I can't think of an issue with this 👍
There was a problem hiding this comment.
I don’t see a problem either. Would be good to understand what is the impact on the database, but otherwise I’m fine with enabling by default.
Co-authored-by: Robert Lin <robert@bobheadxi.dev>
Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
Description
Security events will be included in the audit log by default.
Further details in RFC 734.
Implementation details
I made calls to
audit.Logfrom theSecurityEventLogsStore. I wasn’t 100% sure if this is pure enough (e.g., if we needed to consider some kind of service layer delegating to the store), but we do regularly callsourcegraph/logfrom the stores, which is the basis for the audit log anyway.Security events will be enabled by default on all environments. We originally wanted them on .com only (because we expected huge volumes of data from the multi-tenant cloud). Since single-tenancy is the new default, having them everywhere is beneficial. This was discussed in RFC 734 and RFC 732
Enabling the audit log for security events
They’re enabled by default, but can be tweaked in the site config:
Sample audit logs
Test plan