Skip to content

[BUG] salt-ssh errors with gitfs as fileserver_backend #67940

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

Open
prontok opened this issue Apr 3, 2025 · 0 comments
Open

[BUG] salt-ssh errors with gitfs as fileserver_backend #67940

prontok opened this issue Apr 3, 2025 · 0 comments
Labels
Bug broken, incorrect, or confusing behavior needs-triage

Comments

@prontok
Copy link

prontok commented Apr 3, 2025

Hi,
I have a problem to use salt-ssh with gitfs (pygit2 module)

fileserver_backend:
  - gitfs
# salt --versions-report
Salt Version:
          Salt: 3006.10

Python Version:
        Python: 3.10.16 (main, Mar  6 2025, 02:23:15) [GCC 11.2.0]

Dependency Versions:
          cffi: 1.17.1
      cherrypy: unknown
  cryptography: 42.0.5
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: 4.0.12
     gitpython: 3.1.44
        Jinja2: 3.1.6
       libgit2: 1.8.1
  looseversion: 1.0.2
      M2Crypto: Not Installed
          Mako: 1.3.9
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 22.0
     pycparser: 2.21
      pycrypto: 2.6.1
  pycryptodome: 3.19.1
        pygit2: 1.15.0
  python-gnupg: 0.4.8
        PyYAML: 6.0.1
         PyZMQ: 23.2.0
        relenv: 0.18.1
         smmap: 5.0.2
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: debian 12 bookworm
        locale: utf-8
       machine: x86_64
       release: 6.1.0-32-amd64
        system: Linux
       version: Debian GNU/Linux 12 bookworm
**TO GETS ERROR AFTER RUN THE COMMAND: salt-ssh 'minion1' test.ping** ``` [CRITICAL] Exception caught while initializing gitfs remote '[email protected]:group1/saltstack.git': /var/cache/salt/master/gitfs/RYj1zEGnLSXiYXvUX9ZyvIbdZWskVyjVNEmPCKPPVMc=/_: repository path '/var/cache/salt/master/gitfs/RYj1zEGnLSXiYXvUX9ZyvIbdZWskVyjVNEmPCKPPVMc=/_' is not owned by current user Traceback (most recent call last): File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 515, in __init__ self.new = self.init_remote() File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 2024, in init_remote self.repo = pygit2.Repository(self._cachedir) File "/opt/saltstack/salt/lib/python3.10/site-packages/pygit2/repository.py", line 1541, in __init__ path_backend = init_file_backend(path, int(flags)) _pygit2.GitError: /var/cache/salt/master/gitfs/RYj1zEGnLSXiYXvUX9ZyvIbdZWskVyjVNEmPCKPPVMc=/_: repository path '/var/cache/salt/master/gitfs/RYj1zEGnLSXiYXvUX9ZyvIbdZWskVyjVNEmPCKPPVMc=/_' is not owned by current user [ERROR ] An un-handled exception was caught by Salt's global exception handler: FileserverConfigError: Failed to load gitfs Traceback (most recent call last): File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 515, in __init__ self.new = self.init_remote() File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 2024, in init_remote self.repo = pygit2.Repository(self._cachedir) File "/opt/saltstack/salt/lib/python3.10/site-packages/pygit2/repository.py", line 1541, in __init__ path_backend = init_file_backend(path, int(flags)) _pygit2.GitError: /var/cache/salt/master/gitfs/RYj1zEGnLSXiYXvUX9ZyvIbdZWskVyjVNEmPCKPPVMc=/_: repository path '/var/cache/salt/master/gitfs/RYj1zEGnLSXiYXvUX9ZyvIbdZWskVyjVNEmPCKPPVMc=/_' is not owned by current user

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/bin/salt-ssh", line 11, in
sys.exit(salt_ssh())
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/scripts.py", line 471, in salt_ssh
client.run()
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/cli/ssh.py", line 18, in run
ssh = salt.client.ssh.SSH(self.config)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/client/ssh/init.py", line 313, in init
self.fsclient = salt.fileclient.FSClient(self.opts)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileclient.py", line 1512, in init
self.channel = salt.fileserver.FSChan(opts)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/init.py", line 855, in init
self.fs.init()
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/init.py", line 530, in init
self.serversfstr
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 159, in call
ret = self.loader.run(run_func, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1245, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1260, in _run_as
ret = _func_or_method(*args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/gitfs.py", line 168, in init
_gitfs()
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/gitfs.py", line 83, in _gitfs
return salt.utils.gitfs.GitFS(
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 3177, in new
super(GitFS, obj).init(
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 2569, in init
self.init_remotes(
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 2628, in init_remotes
repo_obj = self.git_providers[self.provider](
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 1743, in init
super().init(
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 523, in init
failhard(self.role)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 229, in failhard
raise FileserverConfigError(f"Failed to load {role}")
salt.exceptions.FileserverConfigError: Failed to load gitfs
Traceback (most recent call last):
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 515, in init
self.new = self.init_remote()
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 2024, in init_remote
self.repo = pygit2.Repository(self.cachedir)
File "/opt/saltstack/salt/lib/python3.10/site-packages/pygit2/repository.py", line 1541, in init
path_backend = init_file_backend(path, int(flags))
pygit2.GitError: /var/cache/salt/master/gitfs/RYj1zEGnLSXiYXvUX9ZyvIbdZWskVyjVNEmPCKPPVMc=/: repository path '/var/cache/salt/master/gitfs/RYj1zEGnLSXiYXvUX9ZyvIbdZWskVyjVNEmPCKPPVMc=/
' is not owned by current user

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/bin/salt-ssh", line 11, in
sys.exit(salt_ssh())
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/scripts.py", line 471, in salt_ssh
client.run()
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/cli/ssh.py", line 18, in run
ssh = salt.client.ssh.SSH(self.config)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/client/ssh/init.py", line 313, in init
self.fsclient = salt.fileclient.FSClient(self.opts)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileclient.py", line 1512, in init
self.channel = salt.fileserver.FSChan(opts)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/init.py", line 855, in init
self.fs.init()
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/init.py", line 530, in init
self.serversfstr
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 159, in call
ret = self.loader.run(run_func, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1245, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1260, in _run_as
ret = _func_or_method(*args, **kwargs)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/gitfs.py", line 168, in init
_gitfs()
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/fileserver/gitfs.py", line 83, in _gitfs
return salt.utils.gitfs.GitFS(
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 3177, in new
super(GitFS, obj).init(
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 2569, in init
self.init_remotes(
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 2628, in init_remotes
repo_obj = self.git_providers[self.provider](
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 1743, in init
super().init(
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 523, in init
failhard(self.role)
File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/gitfs.py", line 229, in failhard
raise FileserverConfigError(f"Failed to load {role}")
salt.exceptions.FileserverConfigError: Failed to load gitfs

Workaround - I modified the file /opt/saltstack/salt/salt-ssh

#!/bin/sh
"true" ''''
- "exec" "$(dirname "$(readlink -f "$0")")/bin/python3.10" "$0" "$@"
+ "exec" "sudo" "-u" "salt" "$(dirname "$(readlink -f "$0")")/bin/python3.10" "$0" "$@"
'''
# -*- coding: utf-8 -*-
import re
import sys
from salt.scripts import salt_ssh
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(salt_ssh())

I understand that changing the code is not a good idea, so I added an alias to the /root/.bashrc file

alias salt-ssh='sudo -u salt salt-ssh'
@prontok prontok added Bug broken, incorrect, or confusing behavior needs-triage labels Apr 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior needs-triage
Projects
None yet
Development

No branches or pull requests

1 participant