Introduction
Log files include data that are considered sensitive by a number of users. This includes
- Hostnames, IP Addresses, Ports
- Accounts
- Database Names
There are situations when log files should be anonymized before forwarding to a 3rd party, to the SOS Ticketing System or to a public forum to receive community support.
JS7 offers to anonymize logs by replacing sensitive data with placeholders:
2022-05-14T11:27:27,026 INFO main c.s.j.c.p.ControllerApiContext - connect ControllerApi of 'testsuite' cluster (https://controller-2-0-primary:4443, https://controller-2-0-seconda 2022-05-14T11:27:27,829 INFO main c.s.j.c.p.ProxyContext - start Proxy of 'testsuite' cluster (https://controller-2-0-primary:4443, https://controller-2-0-secondary:4443) 2022-05-14T11:27:28,526 INFO main c.s.j.c.p.ControllerApiContext - connect ControllerApi of 'standalone' (https://controller-2-0-standalone:4443) 2022-05-14T11:27:28,527 INFO main c.s.j.c.p.ProxyContext - start Proxy of 'standalone' (https://controller-2-0-standalone:4443) 2022-05-14T11:27:31,343 INFO JControllerProxy-42 c.s.j.c.p.ProxyContext - 'standalone' (https://controller-2-0-standalone:4443): ProxyCoupled(1652478862797000) 2022-05-14T11:27:32,908 INFO JControllerProxy-41 c.s.j.c.p.ProxyContext - 'testsuite' cluster (https://controller-2-0-primary:4443, https://controller-2-0-secondary:4443): ProxyCoupled(1652520420689258)
2022-05-14T11:27:27,026 INFO main c.s.j.c.p.ControllerApiContext - connect ControllerApi of 'testsuite' cluster (https://<host>:<port>) 2022-05-14T11:27:27,829 INFO main c.s.j.c.p.ProxyContext - start Proxy of 'testsuite' cluster (https://<host>:<port>) 2022-05-14T11:27:28,526 INFO main c.s.j.c.p.ControllerApiContext - connect ControllerApi of 'standalone' (https://<host>:<port>) 2022-05-14T11:27:28,527 INFO main c.s.j.c.p.ProxyContext - start Proxy of 'standalone' (https://<host>:<port>) 2022-05-14T11:27:31,343 INFO JControllerProxy-42 c.s.j.c.p.ProxyContext - 'standalone' (https://<host>:<port>): ProxyCoupled(1652478862797000) 2022-05-14T11:27:32,908 INFO JControllerProxy-41 c.s.j.c.p.ProxyContext - 'testsuite' cluster (https://<host>:<port>): ProxyCoupled(1652520420689258)
Log Anonymizer Script
Location
Anonymization is available from a Java class and is invoked from the a shell script available with the following default locations:
# JOC Cockpit /opt/sos-berlin.com/js7/joc/jetty/bin/anonymize-logs.sh # Controller /opt/sos-berlin.com/js7/controller/bin/anonymize-logs.sh # Agent /opt/sos-berlin.com/js7/agent/bin/anonymize-logs.sh
@rem JOC Cockpit C:\Program Files\sos-berlin.com\js7\joc\jetty\bin\anonymize-logs.cmd @rem Controller C:\Program Files\sos-berlin.com\js7\controller\bin\anonymize-logs.cmd @rem Agent C:\Program Files\sos-berlin.com\js7\agent\bin\anonymize-logs.cmd
Usage
Usage: log-anonymizer.sh [Options] Options: -l | --log-file=<log-file> | optional: location of a log file that should be anonymized; files, directories and wildcards can be specified -o | --output-dir=<directory> | optional: output directory of anonymized log files -r | --rules-file=<rules-file> | optional: the path to a file holding rules for anonymization -e | --export-rules=<rules-file> | optional: the path to a file to which built-in rules are exported
Explanation:
- Options
-l | --log-file=<log-file>
: Specifies the location of a log file to be anonymized.- This option can be specified repeatedly for a number of files. Wildcards can be specified and directories can be specified should all included files be anonymized.
- Plain text log files as available with the .log file extension are considered and compressed log files available with the .gz file extension, see the JS7 - Log Rotation article.
- Anonymized log file names are prefixed with the string:
anonymized-
- By default anonymized log files are stored to the directory in which original log files are found.
-o | --output-dir=<directory>
: Optionally specifies the output directory to which anonymized log files are stored. If this argument is omitted then anonymized log files are stored to their original directory.-r | --rules-file=<rules-file>
: Optionally specifies the location of a file in YAML format that holds the expressions that should be applied for anonymization.-e | --export-rules=<rules-file>
: Optionally specifies the location of a file to which default expressions for anonymization are exported.
Rules
Rules include to specify regular expressions to search for and related placeholders as replacements. The built-in rules cover typical configuration items such as URLs, IP addresses, Host names etc.
- Users can export the built-in rules to a file to verify available rules and expressions.
- Users can add individual rules to a file that is used when invoking the Log Anonymizer Script. It is recommended to validate individual files to be YAML compliant.
rules: - item: url-component search: ://(.*):(\d{2,5}) replace: - <host> - <port> - item: ip-address search: (([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])) replace: - <ip-address> - item: host-install search: host[\s]*=[\s]*(.*) replace: - <host>
Explanation:
- Each
item
specifies an expression tosearch
for and toreplace
. - The
search
expression makes use of capturing groups specified by( ... )
. - The
replace
placeholder specifies a number of strings that replace the content of related capturing groups.
Examples
The following examples illustrate typical use cases.
log-anonymizer.sh --log-file=/var/sos-berlin.com/js7/controller/var/logs/controller.log
Explanation:
- Creates an anonymized version of the log file in the same directory with the name:
anonymized-controller.log
log-anonymizer.sh --log-file=/var/sos-berlin.com/js7/joc/logs/joc.log \ --log-file=/var/sos-berlin.com/js7/joc/logs/joc-debug.log \ --output-dir=/tmp/logs
Explanation:
- Creates anonymized versions of the indicated log files in the given directory:
/tmp/logs/anonymized-joc.log
/tmp/logs/anonymized-joc-debug.log
log-anonymizer.sh --log-file=/var/sos-berlin.com/js7/joc/logs/joc* \ --output-dir=/tmp/logs
Explanation:
- Creates anonymized versions of the indicated log files from the given directory. The wildcard specifies any log files carrying a name that starts with
joc
to be used. - The wildcard includes to specify plain text log files available from the .log file extension and it includes to specify compressed log files that are available from a .gz file extension.
- Anonymized log files are stored in the output directory.
log-anonymizer.sh --export-rules=/tmp/rules.yaml
Explanation:
- The build-in rules are exported to a file in YAML format.
- This file can be used to adjust rules and can be applied later on.
log-anonymizer.sh --log-file=/var/sos-berlin.com/js7/agent/var_4445/logs/*.log \ --output-dir=/tmp/logs \ --rules-file=/tmp/rules.yaml
Explanation:
- Creates anonymized versions of all log files in the indicated directory and stores them to the output directory.
- A YAML file with individual rules is applied.