-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-18386: Add server_audit_timestamp_format to customize audit log timestamps #4633
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
Open
abhishek593
wants to merge
9
commits into
MariaDB:main
Choose a base branch
from
abhishek593:MDEV-18386
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+331
−85
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
069fde7
MDEV-18386: Add server_audit_timestamp_format to customize audit log …
abhishek593 1d7a286
MDEV-18386: Fix server_audit_timestamp tests
abhishek593 828f298
Merge branch 'main' into MDEV-18386
gkodinov ab99fdb
MDEV-18386: Make server_audit_timestamp_format thread-safe and robust
abhishek593 8b9e22c
MDEV-18386: server_audit: Fix re-entrant deadlock in log_header()
abhishek593 44cf2fb
MDEV-18386: Address review comments; implement optimized single-lock …
abhishek593 0a98e58
MDEV-18386: Fix regressions
abhishek593 974a559
MDEV-18386: Addressed review comments
abhishek593 9e88050
MDEV-18386: Addressed review comments; remove strftime in favor of DA…
abhishek593 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| set global server_audit_logging=on; | ||
| select 1; | ||
| 1 | ||
| 1 | ||
| set global server_audit_timestamp_format='CUSTOM-DATE %Y-%m-%d'; | ||
| select 2; | ||
| 2 | ||
| 2 | ||
| set global server_audit_timestamp_format='CUSTOM-TZ %H:%i:%s %z'; | ||
| select 3; | ||
| 3 | ||
| 3 | ||
| set global server_audit_timestamp_format='%Y%m%d %H:%i:%s'; | ||
| select 4; | ||
| 4 | ||
| 4 | ||
| # | ||
| # Error handling for long timestamp format | ||
| # | ||
| set global server_audit_timestamp_format='%H:%i:%s'; | ||
| show variables like 'server_audit_timestamp_format'; | ||
| Variable_name Value | ||
| server_audit_timestamp_format %H:%i:%s | ||
| # Attempting to set an excessively long format string. | ||
| set global server_audit_timestamp_format='AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; | ||
| ERROR 42000: Variable 'server_audit_timestamp_format' can't be set to the value of 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' | ||
| # Value should still be the old one | ||
| show variables like 'server_audit_timestamp_format'; | ||
| Variable_name Value | ||
| server_audit_timestamp_format %H:%i:%s | ||
| # | ||
| # Test large expansion (many %B specifiers) | ||
| # | ||
| set global server_audit_timestamp_format='%M %M %M %M %M %M %M %M %M %M %M %M %M %M %M'; | ||
| select 5; | ||
| 5 | ||
| 5 | ||
| set global server_audit_timestamp_format='%Y%m%d %H:%i:%s'; | ||
| set global server_audit_logging=off; | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_logging=on',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select 1',0 | ||
| CUSTOM-DATE TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'CUSTOM-DATE %Y-%m-%d\'',0 | ||
| CUSTOM-DATE TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select 2',0 | ||
| CUSTOM-TZ TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'CUSTOM-TZ %H:%i:%s %z\'',0 | ||
| CUSTOM-TZ TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select 3',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'%Y%m%d %H:%i:%s\'',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select 4',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'%H:%i:%s\'',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'show variables like \'server_audit_timestamp_format\'',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select repeat(\'A\', 130)',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\'',1231 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'show variables like \'server_audit_timestamp_format\'',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'%M %M %M %M %M %M %M %M %M %M %M %M %M %M %M\'',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'select 5',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_timestamp_format=\'%Y%m%d %H:%i:%s\'',0 | ||
| TIMESTAMP,HOSTNAME,root,localhost,ID,ID,QUERY,test,'set global server_audit_logging=off',0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --plugin-load-add=server_audit | ||
| --server_audit_file_path='server_audit_timestamp.log' | ||
| --server_audit_output_type=file | ||
| --server_audit_events='query' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's test setting of timestamp format on the command line too |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --source include/not_embedded.inc | ||
|
|
||
| if (!$SERVER_AUDIT_SO) { | ||
| skip No SERVER_AUDIT plugin; | ||
| } | ||
|
|
||
| --disable_ps_protocol | ||
| --disable_view_protocol | ||
|
|
||
| # The plugin is loaded via .opt file | ||
| let $MYSQLD_DATADIR= `SELECT @@datadir`; | ||
| let SEARCH_FILE= $MYSQLD_DATADIR/server_audit_timestamp.log; | ||
|
|
||
| set global server_audit_logging=on; | ||
|
|
||
| # Default format | ||
| select 1; | ||
|
|
||
| # Custom format 1: Just date | ||
| set global server_audit_timestamp_format='CUSTOM-DATE %Y-%m-%d'; | ||
| select 2; | ||
|
|
||
| # Custom format 2: Including timezone (if supported by system strftime) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can now remove references to the "system strftime" from comments |
||
| set global server_audit_timestamp_format='CUSTOM-TZ %H:%i:%s %z'; | ||
| select 3; | ||
|
|
||
| # Revert to default | ||
| set global server_audit_timestamp_format='%Y%m%d %H:%i:%s'; | ||
| select 4; | ||
|
|
||
| --echo # | ||
| --echo # Error handling for long timestamp format | ||
| --echo # | ||
| set global server_audit_timestamp_format='%H:%i:%s'; | ||
| show variables like 'server_audit_timestamp_format'; | ||
|
|
||
| --echo # Attempting to set an excessively long format string. | ||
| let $long_format= `select repeat('A', 130)`; | ||
| --error ER_WRONG_VALUE_FOR_VAR | ||
| eval set global server_audit_timestamp_format='$long_format'; | ||
|
|
||
| --echo # Value should still be the old one | ||
| show variables like 'server_audit_timestamp_format'; | ||
|
|
||
| --echo # | ||
| --echo # Test large expansion (many %B specifiers) | ||
| --echo # | ||
| set global server_audit_timestamp_format='%M %M %M %M %M %M %M %M %M %M %M %M %M %M %M'; | ||
| select 5; | ||
| set global server_audit_timestamp_format='%Y%m%d %H:%i:%s'; | ||
|
|
||
| set global server_audit_logging=off; | ||
|
|
||
| # We use replace_regex to mask the actual volatile parts but keep our prefixes | ||
| --replace_regex /\d{4}\d{2}\d{2} \d{2}:\d{2}:\d{2}/TIMESTAMP/ /CUSTOM-DATE \d{4}-\d{2}-\d{2}/CUSTOM-DATE TIMESTAMP/ /CUSTOM-TZ \d{2}:\d{2}:\d{2} [+-]\d{4}/CUSTOM-TZ TIMESTAMP/ /CUSTOM-TZ \d{2}:\d{2}:\d{2}/CUSTOM-TZ TIMESTAMP/ /([A-Z][a-z]+ ){10,}[A-Z][a-z]+/TIMESTAMP/ /\d{2}:\d{2}:\d{2}/TIMESTAMP/ /,[^,]+,root,(localhost|localhost:[0-9]+),(\d+),(\d+),/,HOSTNAME,root,localhost,ID,ID,/ | ||
| cat_file $SEARCH_FILE; | ||
|
|
||
| remove_file $SEARCH_FILE; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
you can try
set global server_audit_timestamp_format=defaultinstead