gitfs backend error related to SSH host key checking
After setting up a gitfs backend for a (private) GitHub repo, the following appeared in the master log:
[salt.loaded.int.fileserver.gitfs][WARNING ] GitPython exception caught while
fetching: len(["c179aa10976f1152d37e1deca0736698da8744bd\tnot-for-
merge\tbranch 'master' of git+ssh://xxx\n"]) != len(["Warning: Permanently added the
RSA host key for IP address 'xxx' to the list of known hosts.", '', ' = [up to date]
master -> origin/master'])
Workaround was to add the following to .ssh/config:
Host github.com
User salt
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Salt 0.17.2, Ubuntu Raring
Thanks for the report!
This isn't working for me. I'm running the salt-master as root though. Any help would be appreciated. Thx. I'm running 2014.1.0.
Never mind, it seems to work fine even with that error. Thanks anyways. :)
Cant get this to work on salt 2014.1.1. Same error in log file as OP. Using gitpython 0.3.2RC1.
Thanks for the updates everyone. @terminalmage This would be something to add to your long list, since you're most often in the fileserver backend code.
In 2014.1.0 an optional config parameter gitfs_ssl_verify was added to allow this to be tuned. Those running earlier versions must upgrade to use this.
Set gitfs_ssl_verify: False in the master config, and then do the following:
- Stop the salt-master service
- Remove the gitfs cache directory by running
rm -rf /var/cache/salt/master/gitfs - Start the salt-master service
This ssl verification setting is only set when the gitfs remote is first initialized, hence the need to remove the gitfs cache. Allowing for this setting to be modified in an existing repo without needing to remove the cachedir is something I'd like to do eventually.
Actually, I think that might just be for https git remotes, now that I look at the code. Will need to look more closely at this.
Well, I have the same problem. How can I connect to a non-github git server ? How can I use another login than the name of the user salt-master is running in ?
@edomaur Are you trying to use SSH public key authentication, or HTTPS authentication?
I tried SSH with public keys. I am now working to test with HTTPS. I have a 2014.1.10 Saltstack with a Gitlab 7.1.1 git backend, the salt user is root.
Ok, with HTTPS it works now. However if someone can explain how to do the trick with git+ssh and Gitlab, I would be very happy :-)
Unfortunately, with GitPython, @pniederw's solution is the only real workaround. I'll work to add additional information to the gitfs walkthrough to make this more clear.
The solution @pniederw posted in the initial post is a good starting point. You'd just need to adjust the Host line to be a hostname glob that matches the domain of the git server.
Also, his solution turns off strict host key checking. This is not the most secure solution, however. I recently added quite a bit of info to the gitfs documentation, including a section on how to add the host key to the known_hosts file. See here for that information.
Like I said, I'll add information to the gitfs walkthrough that includes such an example. When I made my recent edits to that documentation last week, I did include a mention of using ~/.ssh/config, but I think that an example would be beneficial.
I realize that using the workaround with ~/.ssh/config is a bit of a pain in the butt, but unfortunately GitPython's support for authentication is limited since it is basically a glorified wrapper around the git CLI.
It is for this exact reason that I have worked to add support for other git interfaces (pygit2, dulwich) to Salt's gitfs backend. Our next feature release (coming soon) will contain honest-to-goodness authentication support with pygit2. It will require a minimum pygit2 version of 0.20.3, as this is the first release in which credential support was present in pygit2.
Information on the new authentication support is also there in the gitfs walkthrough.
@edomaur Actually, can you try putting a username in your SSH remote URL? This seems to be supported by GitPython, so it might work for you right now. So, something like this:
gitfs_remotes:
- ssh://[email protected]/repo.git
You'll still need to have the private key in ~/.ssh/id_rsa, if not then you can add something like this to your ~/.ssh/config:
Host domain.com
IdentityFile /path/to/private/key
Of course, the private key should be chmod'ed to 0600.
I'm having this same issue. I had to use gitpython because getting pygit2 installed on Ubuntu Trusty is a pain in the butt.
Here is my config:
auto_accept: True
file_roots:
base:
- /srv/salt/formulas
fileserver_backend:
- git
gitfs_remotes:
- git+ssh://[email protected]/managedbyq/salt-states.git
gitfs_root: formulas
gitfs_base: stg
I have my deploy key under /root/.ssh/id_rsa
After adding StrictHostKeyChecking no in /root/.ssh/config the host warning went away but I'm now getting this error:
2015-05-06 01:10:00,688 [salt.loaded.int.fileserver.gitfs][ERROR ] Exception ''Error when fetching: fatal: Could not read from remote repository.' returned exit status 2: None' caught while fetching gitfs remote git+ssh://[email protected]/managedbyq/salt-states.git
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/fileserver/gitfs.py", line 1136, in update
fetch_results = origin.fetch()
File "/usr/lib/python2.7/dist-packages/git/remote.py", line 593, in fetch
return self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
File "/usr/lib/python2.7/dist-packages/git/remote.py", line 529, in _get_fetch_info_from_stderr
raise GitCommandError(("Error when fetching: %s" % line,), 2)
GitCommandError: 'Error when fetching: fatal: Could not read from remote repository.' returned exit status 2: None
2015-05-06 01:10:00,689 [salt.loaded.int.fileserver.gitfs][DEBUG ] Removed lock for git+ssh://[email protected]/managedbyq/salt-states.git
2015-05-06 01:10:00,689 [salt.utils.verify][DEBUG ] This salt-master instance has accepted 0 minion keys.
@c4milo I can't reproduce this. Have you tried using ssh:// instead of git+ssh:// in your remote URL?
I stopped working on this project months ago. Unfortunately I cannot longer verify if it still persist :(
@c4milo OK, well given that neither the originally-reported issue (nor yours) can be reproduced, this would appear most likely to be upstream issues with older versions of GitPython. I know in the past it leaned significantly more on assertions than it does now.
I'm going to close this as an upstream bug.
@terminalmage Could you please reopen the bug! I do have the exact same problem on GitPython 1.0.1 on ubuntu 14.04 with saltstack 2015.8.3
salt-run fileserver.update -l debug 2>&1
[DEBUG ] Reading configuration from /etc/salt/master
[DEBUG ] Using cached minion ID from /etc/salt/minion_id: salt.datadialog.net
[DEBUG ] Configuration file path: /etc/salt/master
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[DEBUG ] LazyLoaded fileserver.update
[DEBUG ] Reading configuration from /etc/salt/master
[DEBUG ] Including configuration from '/etc/salt/minion.d/_schedule.conf'
[DEBUG ] Reading configuration from /etc/salt/minion.d/_schedule.conf
[DEBUG ] Using cached minion ID from /etc/salt/minion_id: salt.datadialog.net
[DEBUG ] Reading configuration from /etc/salt/master
[DEBUG ] Please install 'virt-what' to improve results of the 'virtual' grain.
[DEBUG ] MasterEvent PUB socket URI: ipc:///var/run/salt/master/master_event_pub.ipc
[DEBUG ] MasterEvent PULL socket URI: ipc:///var/run/salt/master/master_event_pull.ipc
[DEBUG ] Sending event - data = {'fun': 'runner.fileserver.update', 'jid': '20160118174100148697', 'user': 'sudo_openat', '_stamp': '2016-01-18T16:41:00.327592'}
[DEBUG ] gitpython gitfs_provider enabled
[DEBUG ] LazyLoaded git.envs
[DEBUG ] Updating git fileserver cache
[DEBUG ] Set lock for ssh://[email protected]:OpenAT/saltstack.git
[DEBUG ] gitfs is fetching from 'ssh://[email protected]:OpenAT/saltstack.git'
[ERROR ] Exception ''Error when fetching: fatal: Could not read from remote repository.' returned with exit code 2' caught while fetching gitfs remote 'ssh://[email protected]:OpenAT/saltstack.git'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 1755, in fetch_remotes
if repo.fetch():
File "/usr/lib/python2.7/dist-packages/salt/utils/gitfs.py", line 584, in fetch
fetch_results = origin.fetch()
File "/usr/local/lib/python2.7/dist-packages/git/remote.py", line 651, in fetch
res = self._get_fetch_info_from_stderr(proc, progress or RemoteProgress())
File "/usr/local/lib/python2.7/dist-packages/git/remote.py", line 559, in _get_fetch_info_from_stderr
raise GitCommandError(("Error when fetching: %s" % line,), 2)
GitCommandError: 'Error when fetching: fatal: Could not read from remote repository.' returned with exit code 2
[DEBUG ] Removed lock for ssh://[email protected]:OpenAT/saltstack.git
[DEBUG ] Set lock for https://github.com/OpenAT/node-formula.git
[DEBUG ] gitfs is fetching from 'https://github.com/OpenAT/node-formula.git'
[DEBUG ] Removed lock for https://github.com/OpenAT/node-formula.git
[DEBUG ] Set lock for https://github.com/OpenAT/postgres-formula.git
[DEBUG ] gitfs is fetching from 'https://github.com/OpenAT/postgres-formula.git'
[DEBUG ] Removed lock for https://github.com/OpenAT/postgres-formula.git
[DEBUG ] LazyLoaded nested.output
True
[DEBUG ] Sending event - data = {'jid': '20160118174100148697', 'return': True, 'success': True, '_stamp': '2016-01-18T16:41:09.754725', 'user': 'sudo_openat', 'fun': 'runner.fileserver.update'}
[DEBUG ] LazyLoaded local_cache.prep_jid
[INFO ] Runner completed: 20160118174100148697
[DEBUG ] Runner return: True
@michaelkarrer81 It sounds like this is an upstream bug for older versions of gitpython. Can you upgrade your gitpython?
@michaelkarrer81 Do you have a reproducible use case?