Skip to content

Commit 210743d

Browse files
Merge pull request #3248 from boegel/fix_token_log_leak
censor authorization part of headers before logging ReST API request
2 parents 75f0f59 + a029a91 commit 210743d

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed

RELEASE_NOTES

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ For more detailed information, please see the git log.
33

44
These release notes can also be consulted at https://easybuild.readthedocs.io/en/latest/Release_notes.html.
55

6+
v4.1.2 (March 16th 2020)
7+
------------------------
8+
9+
bugfix release
10+
11+
- fix gitdb dependency on Python 2.6 in test configuration (#3212)
12+
- fix broken test for --review-pr by using different PR to test with (#3226)
13+
- censor authorization part of headers before logging ReST API request (#3248)
14+
615
v4.1.1 (January 16th 2020)
716
--------------------------
817

easybuild/base/rest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
:author: Jens Timmerman
3636
"""
3737
import base64
38+
import copy
3839
import json
3940
from functools import partial
4041

@@ -162,7 +163,13 @@ def request(self, method, url, body, headers, content_type=None):
162163
if self.auth_header is not None:
163164
headers['Authorization'] = self.auth_header
164165
headers['User-Agent'] = self.user_agent
165-
fancylogger.getLogger().debug('cli request: %s, %s, %s, %s', method, url, body, headers)
166+
167+
# censor contents of 'Authorization' part of header, to avoid leaking tokens or passwords in logs
168+
headers_censored = copy.deepcopy(headers)
169+
headers_censored['Authorization'] = '<actual authorization header censored>'
170+
171+
fancylogger.getLogger().debug('cli request: %s, %s, %s, %s', method, url, body, headers_censored)
172+
166173
# TODO: in recent python: Context manager
167174
conn = self.get_connection(method, url, body, headers)
168175
status = conn.code

easybuild/tools/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# recent setuptools versions will *TRANSFORM* something like 'X.Y.Zdev' into 'X.Y.Z.dev0', with a warning like
4444
# UserWarning: Normalizing '2.4.0dev' to '2.4.0.dev0'
4545
# This causes problems further up the dependency chain...
46-
VERSION = LooseVersion('4.1.1')
46+
VERSION = LooseVersion('4.1.2')
4747
UNKNOWN = 'UNKNOWN'
4848

4949

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ keyring==5.7.1; python_version < '2.7'
55
keyring<=9.1; python_version >= '2.7'
66
keyrings.alt; python_version >= '2.7'
77

8+
# GitDB 4.0.1 no longer supports Python 2.6
9+
gitdb==0.6.4; python_version < '2.7'
10+
gitdb; python_version >= '2.7'
11+
812
# GitPython 2.1.9 no longer supports Python 2.6
913
GitPython==2.1.8; python_version < '2.7'
1014
GitPython; python_version >= '2.7'

test/framework/options.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,39 @@ def test_from_pr(self):
12331233
print("Ignoring URLError '%s' in test_from_pr" % err)
12341234
shutil.rmtree(tmpdir)
12351235

1236+
def test_from_pr_token_log(self):
1237+
"""Check that --from-pr doesn't leak GitHub token in log."""
1238+
if self.github_token is None:
1239+
print("Skipping test_from_pr_token_log, no GitHub token available?")
1240+
return
1241+
1242+
fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
1243+
os.close(fd)
1244+
1245+
args = [
1246+
# PR for foss/2018b, see https://github.com/easybuilders/easybuild-easyconfigs/pull/6424/files
1247+
'--from-pr=6424',
1248+
'--dry-run',
1249+
'--debug',
1250+
# an argument must be specified to --robot, since easybuild-easyconfigs may not be installed
1251+
'--robot=%s' % os.path.join(os.path.dirname(__file__), 'easyconfigs'),
1252+
'--github-user=%s' % GITHUB_TEST_ACCOUNT, # a GitHub token should be available for this user
1253+
]
1254+
try:
1255+
self.mock_stdout(True)
1256+
self.mock_stderr(True)
1257+
outtxt = self.eb_main(args, logfile=dummylogfn, raise_error=True)
1258+
stdout = self.get_stdout()
1259+
stderr = self.get_stderr()
1260+
self.mock_stdout(False)
1261+
self.mock_stderr(False)
1262+
self.assertFalse(self.github_token in outtxt)
1263+
self.assertFalse(self.github_token in stdout)
1264+
self.assertFalse(self.github_token in stderr)
1265+
1266+
except URLError as err:
1267+
print("Ignoring URLError '%s' in test_from_pr" % err)
1268+
12361269
def test_from_pr_listed_ecs(self):
12371270
"""Test --from-pr in combination with specifying easyconfigs on the command line."""
12381271
if self.github_token is None:
@@ -2710,17 +2743,17 @@ def test_review_pr(self):
27102743

27112744
self.mock_stdout(True)
27122745
self.mock_stderr(True)
2713-
# PR for CMake 3.12.1 easyconfig, see https://github.com/easybuilders/easybuild-easyconfigs/pull/6660
2746+
# PR for gzip 1.10 easyconfig, see https://github.com/easybuilders/easybuild-easyconfigs/pull/9921
27142747
args = [
27152748
'--color=never',
27162749
'--github-user=%s' % GITHUB_TEST_ACCOUNT,
2717-
'--review-pr=6660',
2750+
'--review-pr=9921',
27182751
]
27192752
self.eb_main(args, raise_error=True)
27202753
txt = self.get_stdout()
27212754
self.mock_stdout(False)
27222755
self.mock_stderr(False)
2723-
regex = re.compile(r"^Comparing CMake-3.12.1-\S* with CMake-3.12.1-")
2756+
regex = re.compile(r"^Comparing gzip-1.10-\S* with gzip-1.10-")
27242757
self.assertTrue(regex.search(txt), "Pattern '%s' not found in: %s" % (regex.pattern, txt))
27252758

27262759
def test_set_tmpdir(self):

0 commit comments

Comments
 (0)