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

Use SRC_LOG_LEVEL for audit logs#52566

Merged
daxmc99 merged 9 commits into
mainfrom
dax/validate_log_level_with_audit_logs
May 31, 2023
Merged

Use SRC_LOG_LEVEL for audit logs#52566
daxmc99 merged 9 commits into
mainfrom
dax/validate_log_level_with_audit_logs

Conversation

@daxmc99

@daxmc99 daxmc99 commented May 29, 2023

Copy link
Copy Markdown
Contributor

SRC_LOG_LEVEL is not immediately viewable to the site admin. We should set our audit logs to the same level to avoid the footgun of setting the log level below the instance level, which would result in unexpected behavior of NO audit logs being captured.

This results in audit logging occurring by default on startup for security event logs which may be unexpected and requires the user to explicitly set no audit logs to be gathered.

Test plan

Go tests and manual testing

@cla-bot cla-bot Bot added the cla-signed label May 29, 2023
@daxmc99 daxmc99 requested review from bobheadxi and kopancek May 29, 2023 19:16
Comment thread internal/audit/audit.go Outdated
Comment thread internal/audit/audit.go Outdated
Comment thread internal/audit/audit.go Outdated
Comment thread internal/audit/audit.go Outdated
Comment on lines +109 to +110
func getLoggerFuncWithSeverity(logger log.Logger) func(string, ...log.Field) {
lvl := log.Level(env.LogLevel).Parse()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The PR description states:

We should have our audit logs default to same level

But this to me looks more like we will always use the SRC_LOG_LEVEL, no matter what. So are we trying to default to at least the level that instance uses or are we trying to always set it to SRC_LOG_LEVEL?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Based on the site configuration and the PR title, I think the intention might be to just use SRC_LOG_LEVEL directly. In a way I think this makes sense, since it ensures that it is always logging output while also keeping it the lowest-priority log level available

However it could be confusing if each service has a different SRC_LOG_LEVEL (not always the case, but can happen). If we're going this direction we should call out that the log level of security event audit logs is not to be depended on - we just do whatever it takes to ensure the logs show up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Audit logging will always use the instance's configured log level so that if audit logs are configured they are always emitted.

  1. I don't think we should have users collecting audit logs based on the SeverityLevel.
  2. SRC_LOG_LEVEL is not immediately viewable by site admins. They might think they setup audit logging and then be surprised that they set the value to low. For example, setting the value to INFO when SRC_LOG_LEVEL is set to WARN results in no audit logs being emitted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think we should have users collecting audit logs based on the SeverityLevel.

That's my point, we should document this intention, since if we ask customers to set up their own sinks for these logs it's possible someone might assume log level is related.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added notes to the CHANGELOG and marked this field as deprecated.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changelog entries are ephemeral - can you add it to the permanent docs? In audit_logs.md:

### On Premises

There are two easy approaches to filtering the audit logs:
- JSON-based: look for the presence of the `Attributes.audit` node. Do not depend on the log level, as it can change based on `SRC_LOG_LEVEL`.

(can't suggest on this portion of the docs, sorry!)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! Updated

SRC_LOG_LEVEL is not immediately viewable to the site admin. We should have our audit logs default to same level to avoid the footgun of setting the log level below the instance level which would result in an unexpected behavior of NO audit logs being captured

Co-authored-by: Robert Lin <robert@bobheadxi.dev>
@daxmc99 daxmc99 force-pushed the dax/validate_log_level_with_audit_logs branch from 027e4f6 to 7e09993 Compare May 30, 2023 21:12
@daxmc99 daxmc99 marked this pull request as ready for review May 30, 2023 21:55
@sourcegraph-bot

sourcegraph-bot commented May 30, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 94b925e...baa50b6.

Notify File(s)
@sourcegraph/delivery doc/admin/audit_log.md

@daxmc99 daxmc99 requested review from a team, bobheadxi and kopancek May 31, 2023 00:13
Comment thread doc/admin/audit_log.md Outdated
Co-authored-by: Robert Lin <robert@bobheadxi.dev>
Comment thread doc/admin/audit_log.md Outdated
daxmc99 and others added 3 commits May 30, 2023 17:41

@bobheadxi bobheadxi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice!

@daxmc99

daxmc99 commented May 31, 2023

Copy link
Copy Markdown
Contributor Author

Happy to address any other comments post-merge as well.

@daxmc99 daxmc99 merged commit 8741751 into main May 31, 2023
@daxmc99 daxmc99 deleted the dax/validate_log_level_with_audit_logs branch May 31, 2023 05:21
ErikaRS pushed a commit that referenced this pull request Jun 22, 2023
Co-authored-by: Robert Lin <robert@bobheadxi.dev>
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.

4 participants