-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util/log: conditionally include the server IDs on every line
For CC security logging we want the ability to route the logging events from the files where they are written into a centralized logging collector. However this routing is done line-by-line. To enable log aggregation across multiple clusters, or multiple nodes, we need to disambiguate which log entries come from which cluster and which node. This patch accommodates this requirement by adding the cluster ID and, for tenant servers, the tenant and SQL instance ID, on every output line when the env var `COCKROACH_ALWAYS_LOG_SERVER_IDS` is set to a true-ish value. Note: this feature is unneeded in v21.1 because in that version JSON logging is available and that already includes the server identity bits. Release note: None
- Loading branch information
Showing
10 changed files
with
186 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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,47 @@ | ||
#! /usr/bin/env expect -f | ||
|
||
source [file join [file dirname $argv0] common.tcl] | ||
|
||
set ::env(COCKROACH_INSECURE) "false" | ||
set ::env(COCKROACH_HOST) "localhost" | ||
set certs_dir "/certs" | ||
|
||
set ::env(COCKROACH_ALWAYS_LOG_SERVER_IDS) 1 | ||
set ::env(COCKROACH_ALWAYS_LOG_AUTHN_EVENTS) 1 | ||
|
||
proc start_secure_server {argv certs_dir extra} { | ||
report "BEGIN START SECURE SERVER" | ||
system "$argv start-single-node --host=localhost --socket-dir=. --certs-dir=$certs_dir --pid-file=server_pid -s=path=logs/db --background $extra >>expect-cmd.log 2>&1; | ||
$argv sql --certs-dir=$certs_dir -e 'select 1'" | ||
report "END START SECURE SERVER" | ||
} | ||
|
||
proc stop_secure_server {argv certs_dir} { | ||
report "BEGIN STOP SECURE SERVER" | ||
system "$argv quit --certs-dir=$certs_dir" | ||
report "END STOP SECURE SERVER" | ||
} | ||
|
||
|
||
start_secure_server $argv $certs_dir "" | ||
|
||
set logfile logs/db/logs/cockroach-auth.log | ||
|
||
# run a client command, so we have at least one authn event in the log. | ||
system "$argv sql -e 'create user someuser' --certs-dir=$certs_dir" | ||
system "$argv sql -e 'select 1' --user someuser --certs-dir=$certs_dir</dev/null || true" | ||
|
||
start_test "Check that the authentication events are reported" | ||
|
||
system "grep -q 'authentication succeeded' $logfile" | ||
system "grep -q 'authentication failed' $logfile" | ||
|
||
end_test | ||
|
||
start_test "Check that the auth events have both node ID and cluster ID" | ||
|
||
system "grep -q '\\\[n1,.*clusterID=........-....-....-....-............\\\] . authentication' $logfile" | ||
|
||
end_test | ||
|
||
stop_secure_server $argv $certs_dir |
This file contains 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 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 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 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
Oops, something went wrong.