saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.19k stars 5.48k forks source link

[BUG] 3006.1 - pygit2 - Error occurred fetching (gitfs/git_pillar) remote / error loading known_hosts #64345

Closed ITJamie closed 1 year ago

ITJamie commented 1 year ago

Description on a fresh master setup with gitfs/pillarfs using ssh keys, the error log is filled with known_hosts errors. the hostname in question is actually in the root user known_hosts file ( see end of report )

Setup (Please provide relevant configs and/or SLS files (be sure to remove sensitive info. There is no general set-up of Salt.)

Please be as specific as possible and give set-up details.

Steps to Reproduce the behavior

gitfs_remotes:
  - ssh://git@<hostname_removed>:2222/eng/<reponame>.git:
    - pubkey: /etc/salt/pki/master/ssh_key/id_rsa.pub
    - privkey: /etc/salt/pki/master/ssh_key/id_rsa
    - fallback: main
    - all_saltenvs: main

ext_pillar:
  - git:
    - main ssh://git@<hostname_removed>:2222/eng/<reponame>.git:
      - pubkey: /etc/salt/pki/master/ssh_key/id_rsa.pub
      - privkey: /etc/salt/pki/master/ssh_key/id_rsa
      - root: pillar
      - env: base
      - fallback: main

Expected behavior salt external git pillar should be able to connect.

error

2023-05-24 16:44:21,398 [salt.utils.gitfs :1894][ERROR   ][144943] Error occurred fetching gitfs remote 'ssh://git@<hostname_removed>:2222/eng/<reponame>.git': error loading known_hosts:
Traceback (most recent call last):
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 1870, in _fetch
    fetch_results = origin.fetch(**fetch_kwargs)
  File "/opt/saltstack/salt/extras-3.10/pygit2/remote.py", line 146, in fetch
    payload.check_error(err)
  File "/opt/saltstack/salt/extras-3.10/pygit2/callbacks.py", line 98, in check_error
    check_error(error_code)
  File "/opt/saltstack/salt/extras-3.10/pygit2/errors.py", line 65, in check_error
    raise GitError(message)
_pygit2.GitError: error loading known_hosts:

2023-05-24 16:43:27,050 [salt.utils.gitfs :1894][ERROR   ][144941] Error occurred fetching git_pillar remote 'main ssh://git@<hostname_removed>:2222/eng/<reponame>.git': error loading known_hosts:
Traceback (most recent call last):
  File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 1870, in _fetch
    fetch_results = origin.fetch(**fetch_kwargs)
  File "/opt/saltstack/salt/extras-3.10/pygit2/remote.py", line 146, in fetch
    payload.check_error(err)
  File "/opt/saltstack/salt/extras-3.10/pygit2/callbacks.py", line 98, in check_error
    check_error(error_code)
  File "/opt/saltstack/salt/extras-3.10/pygit2/errors.py", line 65, in check_error
    raise GitError(message)
_pygit2.GitError: error loading known_hosts:

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) ```yaml Salt Version: Salt: 3006.1 Python Version: Python: 3.10.11 (main, May 5 2023, 02:31:54) [GCC 11.2.0] Dependency Versions: cffi: 1.14.6 cherrypy: unknown dateutil: 2.8.1 docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed Jinja2: 3.1.2 libgit2: 1.6.4 looseversion: 1.0.2 M2Crypto: Not Installed Mako: Not Installed msgpack: 1.0.2 msgpack-pure: Not Installed mysql-python: Not Installed packaging: 22.0 pycparser: 2.21 pycrypto: Not Installed pycryptodome: 3.9.8 pygit2: 1.12.1 python-gnupg: 0.4.8 PyYAML: 5.4.1 PyZMQ: 23.2.0 relenv: 0.12.3 smmap: Not Installed timelib: 0.2.4 Tornado: 4.5.3 ZMQ: 4.3.4 System Versions: dist: debian 11 bullseye locale: utf-8 machine: x86_64 release: 5.10.0-11-amd64 system: Linux version: Debian GNU/Linux 11 bullseye ```

Additional context the hostname in question is actually in the root known_hosts file

root@saltdirector-network:/etc/salt/master.d# salt-call ssh.check_known_host user=root hostname=<hostname_removed> port=2222
local:
    exists
dwoz commented 1 year ago

We are tracking this issue in #64121. Thanks @ITJamie!