Skip to content

Commit bf4d454

Browse files
arrestleJake Jackson
andauthored
feat: 38589 GitHub App Authentication (ansible#15807)
* feat: 38589 GitHub App Authentication Allows both git@<personal-token> and x-access-token@<github-access-token> when authenticating using git. This allows GitHub App tokens to work without interfering with existing authentication types. --------- Co-authored-by: Jake Jackson <[email protected]>
1 parent e56752d commit bf4d454

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

awx/main/tests/unit/utils/test_common.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,23 @@ def test_extract_ansible_vars():
240240
('git', 'https://example.com/bar.git', 'user', 'pw', True, False, 'https://user:[email protected]/bar.git'),
241241
('git', 'https://[email protected]/bar.git', False, 'something', True, False, 'https://example.com/bar.git'),
242242
# Special github/bitbucket cases
243-
('git', '[email protected]:ansible/awx.git', True, True, True, False, ValueError('Username must be "git" for SSH access to github.com.')),
243+
(
244+
'git',
245+
'[email protected]:ansible/awx.git',
246+
True,
247+
True,
248+
True,
249+
False,
250+
ValueError('Username must be "git" or "x-access-token" (for github app) for SSH access to github.com.'),
251+
),
244252
(
245253
'git',
246254
'[email protected]:does-not-exist/example.git',
247255
True,
248256
True,
249257
True,
250258
False,
251-
ValueError('Username must be "git" for SSH access to bitbucket.org.'),
259+
ValueError('Username must be "git" or "x-access-token" (for github app) for SSH access to bitbucket.org.'),
252260
),
253261
(
254262
'git',
@@ -257,7 +265,7 @@ def test_extract_ansible_vars():
257265
True,
258266
True,
259267
False,
260-
ValueError('Username must be "git" for SSH access to altssh.bitbucket.org.'),
268+
ValueError('Username must be "git" or "x-access-token" (for github app) for SSH access to altssh.bitbucket.org.'),
261269
),
262270
('git', 'git:[email protected]:ansible/awx.git', True, True, True, False, 'git+ssh://[email protected]/ansible/awx.git'),
263271
# Disabling the special handling should not raise an error

awx/main/utils/common.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,19 @@ def update_scm_url(scm_type, url, username=True, password=True, check_special_ca
329329

330330
# Special handling for github/bitbucket SSH URLs.
331331
if check_special_cases:
332-
special_git_hosts = ('github.com', 'bitbucket.org', 'altssh.bitbucket.org')
333-
if scm_type == 'git' and parts.scheme.endswith('ssh') and parts.hostname in special_git_hosts and netloc_username != 'git':
334-
raise ValueError(_('Username must be "git" for SSH access to %s.') % parts.hostname)
335-
if scm_type == 'git' and parts.scheme.endswith('ssh') and parts.hostname in special_git_hosts and netloc_password:
336-
# raise ValueError('Password not allowed for SSH access to %s.' % parts.hostname)
337-
netloc_password = ''
332+
special_hosts = ('github.com', 'bitbucket.org', 'altssh.bitbucket.org')
333+
allowed_git_usernames = {'git', 'x-access-token'}
334+
335+
if scm_type == 'git' and parts.scheme.endswith('ssh'):
336+
is_github_host = parts.hostname in special_hosts or parts.hostname.endswith('.github.com')
337+
is_bitbucket_host = parts.hostname in special_hosts or parts.hostname.endswith('.bitbucket.com') or 'bitbucket' in parts.hostname
338+
339+
if is_github_host and netloc_username not in allowed_git_usernames:
340+
raise ValueError(_('Username must be "git" or "x-access-token" (for github app) for SSH access to %s.') % parts.hostname)
341+
342+
if (is_github_host or is_bitbucket_host) and netloc_password:
343+
# raise ValueError('Password not allowed for SSH access to %s.' % parts.hostname)
344+
netloc_password = ''
338345

339346
if netloc_username and parts.scheme != 'file' and scm_type not in ("insights", "archive"):
340347
netloc = u':'.join([urllib.parse.quote(x, safe='') for x in (netloc_username, netloc_password) if x])

requirements/requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
aiohttp>=3.9.4 # CVE-2024-30251
23
ansi2html # Used to format the stdout from jobs into html for display
34
asciichartpy

requirements/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,5 +527,4 @@ setuptools==70.3.0
527527
# incremental
528528
# setuptools-rust
529529
# setuptools-scm
530-
# zope-interface
531-
530+
# zope-interface

requirements/requirements_git.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ git+https://github.com/ansible/system-certifi.git@devel#egg=certifi
33
git+https://github.com/ansible/ansible-runner.git@devel#egg=ansible-runner
44
django-ansible-base @ git+https://github.com/ansible/django-ansible-base@devel#egg=django-ansible-base[rest-filters,jwt_consumer,resource-registry,rbac,feature-flags]
55
awx-plugins-core @ git+https://github.com/ansible/awx-plugins.git@devel#egg=awx-plugins-core
6-
awx_plugins.interfaces @ git+https://github.com/ansible/awx_plugins.interfaces.git
6+
awx_plugins.interfaces @ git+https://github.com/ansible/awx_plugins.interfaces.git

0 commit comments

Comments
 (0)