-
Notifications
You must be signed in to change notification settings - Fork 7
912 better method for making sure jsonschema logging does not dump pii into logs #949
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
Closed
shahdyousefak
wants to merge
29
commits into
main
from
912-better-method-for-making-sure-jsonschema-logging-does-not-dump-pii-into-logs
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0798ad2
pii logging to grouping
shahdyousefak 8ed6a52
cherry picking pii logging for grouping
shahdyousefak ea865b0
semseg pii
shahdyousefak c3a5ee8
preprocessors with pii logging (1)
shahdyousefak a106817
preprocessors with pii logging (2)
shahdyousefak 1c4a380
pii logging for preprocessors (3)
shahdyousefak 56c5df9
adding .py handlers + nominatim PII logging
shahdyousefak 855ff86
modifying logging_utils.ts (still not working)
shahdyousefak 98cb233
ensure Winston correctly recognizes pii as a valid log level
shahdyousefak 2ed63ed
all typescript related MS incorporate PII logging
shahdyousefak a6a9b87
resolving merge conflicts
shahdyousefak c509793
build failures
shahdyousefak ca57737
adding winston lib
shahdyousefak d90f99a
test
shahdyousefak cbec4e5
test
shahdyousefak 6aebdab
test
shahdyousefak 42a2ac7
logging_utils.ts import error
shahdyousefak 5f0837c
logging_utils.ts import error
shahdyousefak 392de7d
logging_utils.ts import error
shahdyousefak ef4db3e
logging_utils.ts import error
shahdyousefak 8616394
logging_utils.ts import error
shahdyousefak 4244e05
logging_utils.ts import error
shahdyousefak 24147f6
modifying nominatim workflow yaml
shahdyousefak 9f114b5
modifying nominatim workflow yaml to copy config
shahdyousefak 63c492b
adding copy config to workflows, winston download
shahdyousefak 4c644c1
adding debug to autour handler workflow
shahdyousefak 308e22c
fixing typo in workflows
shahdyousefak bd2e5cc
fixing typo in workflows
shahdyousefak e428433
adding npm install to high-charts
shahdyousefak 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # /app/config/__init__.py | ||
| # This file marks the config directory as a Python package. |
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,34 @@ | ||
| import logging | ||
| import os | ||
|
|
||
| # Define a PII log level | ||
| PII_LOG_LEVEL = 5 | ||
| logging.addLevelName(PII_LOG_LEVEL, "PII") | ||
|
|
||
|
|
||
| def pii(self, message, *args, **kwargs): | ||
| if self.isEnabledFor(PII_LOG_LEVEL): | ||
| self._log(PII_LOG_LEVEL, message, args, **kwargs) | ||
|
|
||
|
|
||
| logging.Logger.pii = pii | ||
| logging.pii = lambda msg, *args, **kwargs: logging.log( | ||
| PII_LOG_LEVEL, msg, *args, **kwargs) | ||
|
|
||
|
|
||
| def configure_logging(): | ||
| """ | ||
| Configures logging based on environment variables. | ||
| """ | ||
| log_level = os.getenv("LOG_LEVEL", "INFO").upper() | ||
| pii_logging_enabled = os.getenv("PII_LOGGING_ENABLED", | ||
| "false").lower() == "true" | ||
|
|
||
| level = getattr(logging, log_level, logging.INFO) | ||
| logging.basicConfig(level=level) | ||
|
|
||
| if pii_logging_enabled: | ||
| logging.warning("Environment Unicorn: PII logging enabled!") | ||
| logging.getLogger().setLevel(PII_LOG_LEVEL) # Lower log level to PII | ||
| else: | ||
| logging.info("Environment Pegasus: PII logging is disabled.") |
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,47 @@ | ||
| // https://medium.com/@jaiprajapati3/masking-of-sensitive-data-in-logs-700850e233f5 | ||
| // https://github.com/winstonjs/winston/blob/c69cdb0cec15a138e0b6e374501e027d1c39606c/index.d.ts | ||
|
|
||
| import winston, { LogMethod, LogEntry } from 'winston'; | ||
| const logger = winston.createLogger({ | ||
| level: 'info', | ||
| format: winston.format.json(), | ||
| transports: [ | ||
| new winston.transports.Console({ | ||
| format: winston.format.simple(), | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| interface PIILogger extends LogMethod { | ||
| pii: (message: string) => void; | ||
| } | ||
|
|
||
| const piiLoggingEnabled = process.env.PII_LOGGING_ENABLED === 'true'; | ||
|
|
||
| if (piiLoggingEnabled) { | ||
| logger.warn("Environment Unicorn: PII logging enabled!"); | ||
| } else { | ||
| logger.info("Environment Pegasus: PII logging is disabled."); | ||
| } | ||
|
|
||
| // PII Logger Function | ||
| const piiLogger: PIILogger = ((arg1: string | LogEntry, arg2?: any) => { | ||
| if (typeof arg1 === 'string' && arg2 !== undefined) { // log when both level and message are provided | ||
| logger.log(arg1, arg2); | ||
| } else if (typeof arg1 === 'object') { // log when an object is provided | ||
| logger.log(arg1); | ||
| } else { | ||
| throw new Error('Invalid log format'); | ||
| } | ||
| }) as PIILogger; | ||
|
|
||
| // Function for logging PII-related errors | ||
| piiLogger.pii = (message: string) => { | ||
| if (piiLoggingEnabled) { | ||
| logger.error(`[PII] ${message}`); | ||
| } else { | ||
| logger.warn("PII logging attempted but is DISABLED."); | ||
| } | ||
| }; | ||
|
|
||
| export { piiLogger }; |
|
Contributor
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. same, these should not removed from docker compose |
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
Oops, something went wrong.
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.
why are we removing text-followup preprocessor and handler?