Skip to content

Commit

Permalink
Ensure that secrets are masked no matter what logging config is in use (
Browse files Browse the repository at this point in the history
#15899)

And rather than only applying the filters for the current known remote
backends, I have applied the filter to the task handler "globally" so
that all task logs are filtered, even for custom remote back ends.

(cherry picked from commit 7ea1b84)
  • Loading branch information
ashb committed May 17, 2021
1 parent cc80dbd commit c7f469e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion airflow/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,20 @@ def configure_logging():
log.debug('Unable to load custom logging, using default config instead')

try:
# Ensure that the password masking filter is applied to the 'task' handler
# no matter what the user did.
if 'filters' in logging_config and 'mask_secrets' in logging_config['filters']:
# But if they replace the logging config _entirely_, don't try to set this, it won't work
task_handler_config = logging_config['handlers']['task']

task_handler_config.setdefault('filters', [])

if 'mask_secrets' not in task_handler_config['filters']:
task_handler_config['filters'].append('mask_secrets')

# Try to init logging
dictConfig(logging_config)
except ValueError as e:
except (ValueError, KeyError) as e:
log.error('Unable to load the config, contains a configuration error.')
# When there is an error in the config, escalate the exception
# otherwise Airflow would silently fall back on the default config
Expand Down

0 comments on commit c7f469e

Please sign in to comment.