Skip to content

Commit 66b7d79

Browse files
fmoessbauerjan-kiszka
authored andcommitted
GitLab CI: make ssh config check less strict
For backwards compatibility we only inject the ssh rewrites if no ssh config is present. The documentation was a bit imprecise w.r.t. what exactly ssh config means, but the implementation checked for any file in ~/.ssh. This is too strict, as the authorized_keys or known_hosts files are sometimes used to inject the ssh fingerprint of the own GitLab instance. The presence of these files does not interfere with our rewrite rules. We change that by only checking for kas related ssh config vars as well as the presence of `~/.ssh/config`. Reported-by: Florian Bezdeka <florian.bezdeka@siemens.com> Fixes: af6b9ae ("auto-inject git credentials on gitlab ci") Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com> Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
1 parent 603a888 commit 66b7d79

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

docs/userguide/credentials.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ for repos stored on the same server. Technically this is achieved by adding
6262
`insteadof` entries to the ``.gitconfig`` file.
6363

6464
For backwards compatibility, the git rewrite rules are only added if
65-
``.gitconfig`` does not exists and no SSH configuration is provided.
65+
``.gitconfig`` does not exist and no SSH configuration is provided (either
66+
via the kas ``SSH_`` variables or using ``.ssh/config``).
6667

6768
If the ``CI_REGISTRY``, ``CI_REGISTRY_USER`` and ``CI_JOB_TOKEN`` variables
6869
are set, kas automatically creates a login file for the container

kas/libcmds.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,16 @@ def __str__(self):
193193
@staticmethod
194194
def _ssh_config_present():
195195
"""
196-
Checks if any file in the .ssh dir exists or
197-
any manual ssh config option is set.
196+
Checks if the .ssh/config file exists or any manual ssh config
197+
option is set.
198198
"""
199199
ssh_vars = ['SSH_PRIVATE_KEY', 'SSH_PRIVATE_KEY_FILE', 'SSH_AUTH_SOCK']
200200
if any(e in os.environ for e in ssh_vars):
201201
return True
202202

203203
ssh_path = os.path.expanduser('~/.ssh')
204-
if os.path.isdir(ssh_path):
205-
with os.scandir(ssh_path) as it:
206-
if any(it):
207-
return True
204+
if os.path.exists(os.path.join(ssh_path, 'config')):
205+
return True
208206
return False
209207

210208
def _setup_netrc(self):

0 commit comments

Comments
 (0)