-
Notifications
You must be signed in to change notification settings - Fork 211
Avoid leaking keys by mistake with --upload-test-report
#4877
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
Changes from 9 commits
46de48e
fbf6a3a
28c9b7b
2f8a1aa
4e85b8d
f34baa5
ada91d9
ec5dc94
04476d3
9cf65b5
4cf9c83
7fa8b10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,6 +37,7 @@ | |||||
""" | ||||||
import copy | ||||||
import os | ||||||
import re | ||||||
import sys | ||||||
from datetime import datetime | ||||||
from time import gmtime, strftime | ||||||
|
@@ -58,6 +59,48 @@ | |||||
|
||||||
_log = fancylogger.getLogger('testing', fname=False) | ||||||
|
||||||
_exclude_env_from_report = [] | ||||||
DEFAULT_EXCLUDE_FROM_REPORT = [ | ||||||
'KEY', | ||||||
'SECRET', | ||||||
'TOKEN', | ||||||
'PASSWORD', | ||||||
'API', | ||||||
'AUTH', | ||||||
'CREDENTIAL', | ||||||
'PRIVATE', | ||||||
'LICENSE', | ||||||
'LICENCE', | ||||||
] | ||||||
DEFAULT_EXCLUDE_FROM_REPORT_RGX = [ | ||||||
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. We use Also, the name of the constant should be a bit more descriptive, it's too vague/broad, so something like:
Suggested change
Similar above for Constants are here to stay, they effectively become part of the EasyBuild framework API, so we better try and make sure they have names that don't leave much room for guessing... 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. done in 9cf65b5 |
||||||
# From PR comments https://github.com/easybuilders/easybuild-framework/pull/4877 | ||||||
r'AKIA[0-9A-Z]{16}', # AWS access key | ||||||
r'[A-Za-z0-9/+=]{40}', # AWS secret key | ||||||
r'eyJ[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+', # JWT token | ||||||
r'gh[pousr]_[A-Za-z0-9_]{36,}', # GitHub token | ||||||
r'xox[baprs]-[A-Za-z0-9-]+', # Slack token | ||||||
|
||||||
# https://github.com/odomojuli/regextokens | ||||||
r'^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$', # Base64 | ||||||
r'[1-9][0-9]+-[0-9a-zA-Z]{40}', # Twitter token | ||||||
r'EAACEdEose0cBA[0-9A-Za-z]+', # Facebook token | ||||||
r'[0-9a-fA-F]{7}.[0-9a-fA-F]{32}', # Instagram token | ||||||
r'AIza[0-9A-Za-z-_]{35}', # Google API key | ||||||
r'4/[0-9A-Za-z-_]+', # Google OAuth 2.0 Auth code | ||||||
r'ya29.[0-9A-Za-z-_]+', # Google OAuth 2.0 access token | ||||||
r'[rs]k_live_[0-9a-z]{32}', # Picatic/Stripe API key | ||||||
r'sqOatp-[0-9A-Za-z-_]{22}', # Square Access token | ||||||
r'access_token,production$[0-9a-z]{161[0-9a,]{32}', # PayPal token | ||||||
r'55[0-9a-fA-F]{32}', # Twilio token | ||||||
r'key-[0-9a-zA-Z]{32}', # Mailgun API key | ||||||
r'[0-9a-f]{32}-us[0-9]{1,2}', # Mailchimp API key | ||||||
r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}', # Google Cloud Oauth 2.0 token | ||||||
r'[A-Za-z0-9_]{21}--[A-Za-z0-9_]{8}', # Google Cloud API key | ||||||
r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}', # Heroku token | ||||||
r'sk-(.*-)?[A-Za-z0-9]{20}T3BlbkFJ[A-Za-z0-9]{20}', # OpenAI API key | ||||||
r'waka_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}', # WakaTime API key | ||||||
] | ||||||
|
||||||
|
||||||
def regtest(easyconfig_paths, modtool, build_specs=None): | ||||||
""" | ||||||
|
@@ -140,6 +183,21 @@ def session_state(): | |||||
} | ||||||
|
||||||
|
||||||
def exclude_env_from_report_add(key): | ||||||
""" | ||||||
Exclude key from test report if an environment variables contains key. | ||||||
:param key: environment variable to exclude | ||||||
""" | ||||||
_exclude_env_from_report.append(key.upper()) | ||||||
|
||||||
|
||||||
def exclude_env_from_report_clear(): | ||||||
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. This is only used in the tests, it's fine to twiddle with internal things there, so I wouldn't define a custom function for this, and just play with Likewise for |
||||||
""" | ||||||
Clear list of environment variables to exclude from test report. | ||||||
""" | ||||||
_exclude_env_from_report.clear() | ||||||
|
||||||
|
||||||
def create_test_report(msg, ecs_with_res, init_session_state, pr_nrs=None, gist_log=False, easyblock_pr_nrs=None, | ||||||
ec_parse_error=None): | ||||||
""" | ||||||
|
@@ -265,8 +323,15 @@ def create_test_report(msg, ecs_with_res, init_session_state, pr_nrs=None, gist_ | |||||
for key in sorted(environ_dump.keys()): | ||||||
if env_filter is not None and env_filter.search(key): | ||||||
continue | ||||||
else: | ||||||
environment += ["%s = %s" % (key, environ_dump[key])] | ||||||
value = environ_dump[key] | ||||||
if any(re.match(rgx, value) for rgx in DEFAULT_EXCLUDE_FROM_REPORT_RGX): | ||||||
continue | ||||||
environment += ["%s = %s" % (key, value)] | ||||||
|
||||||
environment = list(filter( | ||||||
ocaisa marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
lambda x: not any(y in x.upper() for y in DEFAULT_EXCLUDE_FROM_REPORT + _exclude_env_from_report), | ||||||
ocaisa marked this conversation as resolved.
Show resolved
Hide resolved
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. Can't we also tackle that part above? I.e. only add a key-value pair if the key (env var name) doesn't have a partial match with anything in The combination of 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. done in 4cf9c83 |
||||||
environment | ||||||
)) | ||||||
|
||||||
test_report.extend(["#### Environment", "```"] + environment + ["```"]) | ||||||
|
||||||
|
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.
It seems like the only reason that this is added is so we have something to play with in the tests?
That's a bad pattern, I think it's better pull tricks in the tests (like changing constants in place and than restoring their original value in the
tearDown
of the tests) rather than introducing global variables that are only there to play with in the test suite.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.
My idea was for this functions to also be used outside of framework, eg for an easyblock to excluded a specific environment variable from reports that is know to contain a secret
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.
I am not sure if there would be a better solution to implement excluding variables on demand.
In case we want more discussion around that, i think the default excludes should be included ASAP, so i could split this PR in 2 if needed
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.
The fact that
_exclude_env_from_report
is a global variable here is a problem, since that means it'll be shared across multiple easyblocks used in a single EasyBuild session...