Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

disable audit logging to db by default#51686

Merged
daxmc99 merged 26 commits intomainfrom
dax/remove_audit_log
May 23, 2023
Merged

disable audit logging to db by default#51686
daxmc99 merged 26 commits intomainfrom
dax/remove_audit_log

Conversation

@daxmc99
Copy link
Contributor

@daxmc99 daxmc99 commented May 10, 2023

This modifies our audit configuration. After this security_event_logs will be output to stdout in our audit log format by default.

image

Test plan

Go tests included in this PR

@cla-bot cla-bot bot added the cla-signed label May 10, 2023
@daxmc99 daxmc99 force-pushed the dax/remove_audit_log branch 5 times, most recently from 6f87466 to 716d22f Compare May 16, 2023 00:51
Comment on lines 1435 to 1429
"location": {
"description": "Where to output the audit log",
"type": "string",
"enum": ["none", "stdout", "database", "both"],
"default": "none"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the plan to make it possible to also render audit logs in the database? right now the implementation only touches the security event logs

IMO: we should never introduce an option for audit logs to go to database, that sounds disastrous. we should have a completely separate field for securityEventLogs that dictates the destination:

{
  "auditLog": { ... }
  "securityEvents": {
    "location": "auditlogs" // enum: ["none", "auditlogs", "database", "all"]
  }
}

security event logs !== audit logs, and we should be careful to not conflate the two 😅 the only overlap is that security event logs also can be rendered as audit logs

Copy link
Member

@michaellzc michaellzc May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to create another top level config for security events,

it's really confusing for me to see a mix of config for two totally different things

like can I use severityLevel to tune the verbose level for securityEvents? (you can't, but that's the point)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 from me. It's confusing to understand what I am configuring if we put both at the same level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to be another property at the top-level Log
CleanShot 2023-05-16 at 16 10 01

Comment on lines 1435 to 1429
"location": {
"description": "Where to output the audit log",
"type": "string",
"enum": ["none", "stdout", "database", "both"],
"default": "none"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 from me. It's confusing to understand what I am configuring if we put both at the same level.

@daxmc99 daxmc99 force-pushed the dax/remove_audit_log branch from b1fc79f to 2c8457e Compare May 16, 2023 23:08
@daxmc99 daxmc99 force-pushed the dax/remove_audit_log branch from 2c8457e to 3069900 Compare May 16, 2023 23:11
@daxmc99 daxmc99 marked this pull request as ready for review May 16, 2023 23:35
@sourcegraph-bot
Copy link
Contributor

sourcegraph-bot commented May 16, 2023

Codenotify: Notifying subscribers in CODENOTIFY files for diff b2e59d0...bee3f1f.

Notify File(s)
@eseliger internal/database/repos.go
internal/database/repos_perm_test.go
@sourcegraph/delivery doc/admin/audit_log.md

}

func (s *securityEventLogsStore) InsertList(ctx context.Context, events []*SecurityEvent) error {
cfg := conf.SiteConfig()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: consider refactoring this out of hot path

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a fairly minimal concern I think, there is usually a cache in front of this. The alternative would be to have a conf.Watch that updates securityEventLogsStore but store instances are typically set up on the fly so that might not be feasible

Copy link
Contributor

@kopancek kopancek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now 👍

@daxmc99 daxmc99 requested review from bobheadxi and michaellzc May 18, 2023 21:58
Copy link
Member

@bobheadxi bobheadxi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the changelog entry needs more rewording, no longer writing to DB by default is a significant change in behaviour

bobheadxi

This comment was marked as duplicate.

daxmc99 and others added 3 commits May 22, 2023 11:09
Co-authored-by: Robert Lin <robert@bobheadxi.dev>
Co-authored-by: Robert Lin <robert@bobheadxi.dev>
@daxmc99 daxmc99 requested a review from bobheadxi May 22, 2023 21:33
CHANGELOG.md Outdated
- Added the ability to block auto-indexing scheduling and inference via the `codeintel_autoindexing_exceptions` Postgres table. [#51578](https://github.com/sourcegraph/sourcegraph/pull/51578)
- When an admin has configured rollout windows for Batch Changes changesets, the configuration details are now visible to all users on the Batch Changes settings page. [#50479](https://github.com/sourcegraph/sourcegraph/pull/50479)
- Added support for regular expressions in`exclude` repositories for GitLab code host connections. [#51862](https://github.com/sourcegraph/sourcegraph/pull/51862)
- Security event logs no longer write to database by default - instead, they will be written in the [audit log format](https://docs.sourcegraph.com/admin/audit_log) to console. There is a new site config setting `log.securityEventLogs` that can be used to configure security event logs to write to database if the old behaviour is desired. This new default will significantly improve performance for large instances. In addition, the old environment variable `SRC_DISABLE_LOG_PRIVATE_REPO_ACCESS` no longer does anything. [#51686](https://github.com/sourcegraph/sourcegraph/pull/51686)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - can this just replace the entry in Changed? i.e. just move this whole thing down

daxmc99 and others added 2 commits May 23, 2023 10:18
Co-authored-by: Robert Lin <robert@bobheadxi.dev>
Co-authored-by: Robert Lin <robert@bobheadxi.dev>
daxmc99 and others added 5 commits May 23, 2023 10:19
Co-authored-by: Robert Lin <robert@bobheadxi.dev>
Co-authored-by: Robert Lin <robert@bobheadxi.dev>
@daxmc99 daxmc99 enabled auto-merge (squash) May 23, 2023 18:02
@daxmc99 daxmc99 merged commit c0dee2b into main May 23, 2023
@daxmc99 daxmc99 deleted the dax/remove_audit_log branch May 23, 2023 18:10
Copy link
Contributor

@filiphaftek filiphaftek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

bobheadxi referenced this pull request May 30, 2023
…52571)

As of https://github.com/sourcegraph/sourcegraph/pull/51686 we will no
longer write audit logs to DB by default. I noticed this background
prune job is causing high load on a customer instance, and I think this
should be disabled by default now as well.

While here, I also removed the log15 usages from this file.

## Test plan

n/a
ErikaRS pushed a commit that referenced this pull request Jun 22, 2023
Security event logs are no longer logged to the `security_event_log` table by default after this change. They are now configurable through the site_config


---------

Co-authored-by: Robert Lin <robert@bobheadxi.dev>
ErikaRS referenced this pull request Jun 22, 2023
…52571)

As of https://github.com/sourcegraph/sourcegraph/pull/51686 we will no
longer write audit logs to DB by default. I noticed this background
prune job is causing high load on a customer instance, and I think this
should be disabled by default now as well.

While here, I also removed the log15 usages from this file.

## Test plan

n/a
- Access tokens now begin with the prefix `sgp_` to make them identifiable as secrets. You can also prepend `sgp_` to previously generated access tokens, although they will continue to work as-is without that prefix.
- The commit message defined in a batch spec will now be quoted when git is invoked, i.e. `git commit -m "commit message"`, to improve how the message is interpreted by the shell in certain edge cases, such as when the commit message begins with a dash. This may mean that previous escaping strategies will behave differently.
- 429 errors from external services Sourcegraph talks to are only retried automatically if the Retry-After header doesn't indicate that a retry would be useless. The time grace period can be configured using `SRC_HTTP_CLI_EXTERNAL_RETRY_AFTER_MAX_DURATION` and `SRC_HTTP_CLI_INTERNAL_RETRY_AFTER_MAX_DURATION`. [#51743](https://github.com/sourcegraph/sourcegraph/pull/51743)
- Security Events NO LONGER write to database by default - instead, they will be written in the [audit log format](https://docs.sourcegraph.com/admin/audit_log) to console. There is a new site config setting `log.securityEventLogs` that can be used to configure security event logs to write to database if the old behaviour is desired. This new default will significantly improve performance for large instances. In addition, the old environment variable `SRC_DISABLE_LOG_PRIVATE_REPO_ACCESS` no longer does anything. [#51686](https://github.com/sourcegraph/sourcegraph/pull/51686)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be log.securityEventLog not log.securityEventLogs

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants