Fixes https://pagure.io/pagure/issue/537
@pingou If I'm reading this correctly, it generates an SSH key pair for each mirror hook activated, right?
By the way, if this is the case, then it shouldn't be that bad to extend this to support pull (inbound) mirroring, too (#1987). That deals with the main problem of using the same key (Gitolite would consider each user "unique" with separate keys).
That said, public repos with anonymous access allowed do not require any of this for inbound mirroring, just the ability to be pulled via git://, http://, or https:// protocols.
git://
http://
https://
Yes
That deals with the main problem of using the same key (Gitolite would consider each user "unique" with separate keys).
For this I think I prefer to expand the support of the deploy keys, keep concerns separate.
rebased onto 64ef3c7f397e4eed3ec8864744f2f2967fa80f59
Pretty please pagure-ci rebuild
rebased onto b2a01c078710aad056abdf11b49728f05a26d3e9
This code looks good to me. The test failures look like redis isn't set up correctly in the test environment, so I'm going to assume the tests pass normally.
So... :thumbsup:
rebased onto 7f62f337e043cfde6459da59836e8b3a6139246c
The test failures look like redis isn't set up correctly in the test environment, so I'm going to assume the tests pass normally.
Thanks, just the pointer I needed to find the error.
Pushing a fix, let's see if it works :)
rebased onto 981a369c75347bcabec234530b4d09216bcc3826
rebased onto 4c95e3b831f6933a92094cb5ad8810461bcef8e6
4 new commits added
Add a mirroring hook to mirror git repo to other locations
Allow plugins to have readonly fields in their form
Add a way to return both stdout and stderr when calling out sub-command
Fix import in the pagure_hook file
5 new commits added
Properly import and call the tasks_services' tasks
2 new commits added
Add a -mirror subpackage to pagure
Include a pagure_mirror systemd file
rebased onto 7b568a7add61de90709f6c61428fae1872d2d9e6
Drop trollius-redis stuff.
trollius-redis
Actually, the trollius stuff can also go away since the service is using celery (which would be good to list as dependency)
rebased onto f52bf8395441c08ea1d426712fce84452c34353c
Why don't we just require pagure? That's already technically a real requirement, since most of the code is there...
pagure
@pingou This needs to be rebased for current master.
rebased onto 73e7705bb5a3e3f19e46fb9e452ae4ae3c99a8b6
This is the mirror service, not the logcom service. :)
https://pagure.io/pagure/pull-request/1105#_3,63
I think we'd want to run this as a different user.
Note that this assumes that this GIT_DIR will exist when the runner gets to running it. This might not be the case.
I do not think that ~/.ssh is the best place for this. This is service data, how about /var/lib/pagure/sshkeys/?
/var/lib/pagure/sshkeys/
This writes the private key as chmod 0644. SSH won't even accept these keys, they'll need to be 0600.
Note that the directory containing private keys must be 0700.
I would say that if a key exists at the moment mirroring is enabled, there's definitely something wrong (previous key wasn't cleared up), and it should probably error out?
I would actually say to not catch this. When you get here, the key really ought to exist, if it doesn't, we need to error out probably, so an admin looks at it.
Given that, if I read the code correctly, this is done in the main project repo, this would mean you add a remote for each target persistently, and on future pushes, this will error out. But also, if you edit e.g. the first line in the remote, it will never update that one, etc. Perhaps it's better to just do this in a new, clean clone of the repository?
You have no checking at all on the remote strings as far as I can see, this would mean that I could fill in a target of "/srv/git/repositories/pagure.git" in my mirror from attack.git, and since this runs as a user that has R/W access to all repos, would (probably) overwrite the target repository. Next to checking of the target URLs, I really think this should run as a limited user.
I think that in this PR, you still need:
Indeed that is the idea, I'll make it more explicit by changing the default here, thanks
How could it not? This is the hook so it's installed in a subfolder in the GIT_DIR
I guess it should be a configuration variable then, defaulting to this path indeed.
:thumbsup:
I'll add a check to ensure the remote is an (ssh) url.
sounds good
Oups, thanks
Let's adjust it :)
In this case since we're removing the key I'm tempted to let it as is.
rebased onto df8e658f6ba88c27997ea8d9e8d5131810f48a40
7 new commits added
rebased onto bbf8100ead851cc3ddf973415bc3786d6ec1d11c
We should probably make sure that if it already exists, it's not a symlink or owned by someone else. Otherwise, if the containing directory is widely writable, someone with access to the system might be able to instead put in a symlink to a place they control.
Done :)
rebased onto 4cf012ace80b023218c33de1576855e4d2f6004f
rebased onto 5ca22c7b298562d9840e4228c9742e45c65c901f
rebased onto a7226fde7e6df8528d5b6e5e9fbfcea372f0fccd
rebased onto f9db971861e6119bcb71ec7813df3fdf0265e807
rebased onto ebc1afc290ee0cc93c65f9388d87e66f8b3a6f8c
test
rebased onto 871024d606ec05634e8726cef25e1c685c9580b7
rebased onto 05f79517747ef0f3a9135ff18c037dad7a9529a9
rebased onto a21c5608075b27e02ffc1523a7246da502cff13d
GIT_DIR now does not exist.
Maybe add os.O_EXCL as well, so that we make very sure that we create this file, rather than overwrite a file an attacker might've put in place? That will make sure that if the file already existed, it errors out.
os.O_EXCL
Note that this overwrites the log attribute with just the log of the very last push. Maybe an idea to accumulate this variable over the for idx, remote in enumerate(remotes): run, so you can actually return the log for all of the mirrors?
for idx, remote in enumerate(remotes):
+1 to the patch as is, but might fix the two last comments. They should be small enough and not impact the security constraints, so no need to re-review if just the os.O_EXCL and the log fix.
Hm, good point, I'll adjust the task to check if the absolute path still exists before continuing.
Thanks :)
will do
Good catch, fixed via:
+ logs = [] for idx, remote in enumerate(remotes): remote_name = '%s_%s' % (public_key_name, idx) _log.info( @@ -239,10 +241,12 @@ def mirror_project(self, session, username, namespace, name): env={'GIT_SSH_COMMAND': 'ssh -i %s' % private_key_file}) log = "Output from the push:\n stdout: %s\n stderr: %s" % ( stdout, stderr) - project.mirror_hook.last_log = log + logs.append(log) + if logs: + project.mirror_hook.last_log = '\n'.join(logs) session.add(project.mirror_hook) session.commit() - _log.info(log) + _log.info('\n'.join(logs))
Jenkins is all green, let's merge :)
Thanks for the review @puiterwijk!! :)
Pull-Request has been merged by pingou
Fixes https://pagure.io/pagure/issue/537