-
Notifications
You must be signed in to change notification settings - Fork 285
Always run as given user, even if identity set #473
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Always run as given user, even if identity set #473
Conversation
9f8e9d9
to
5e07b2a
Compare
Ah - one more fix needed for this; the fact that git is now actually running as the requested user, even if you used I suspect the solution is just to let Tempfile write the file in the OS's temp directory - although it would probably need to chown the file to the user who we're going to run git as, otherwise they still won't be able to read it... EDIT: actually, it already gets chmod'd to 755, meaning other users can read it... but not execute it, which is what git needs to do. Changing that to 777 seems reasonable, as already readable... but it just occurred to me that if it is placed in the system temp dir, that may not work as the temp dir may well be mounted with Perhaps the whole "write a shell script to wrap SSH" could just be done away with in favour of passing options directly, e.g.
(As an aside, looking at the file that's written, I find it a little alarming that requesting a specific SSH key be used also disables StrictHostKeyChecking without having been asked to do that... is that intentional and documented?) |
Hi @bigpreshkt, This change seems really helpful and we would love to get this merged as soon as the test are green. As you mentioned in the second comment I believe that having StrictHostKeyChecking disabled might have been the initial workaround when this functionality was implemented, however addressing this issue is really important and we would definitely appreciate your fix here. Please let us know if you need a bit of help getting this fix over the line. Thanks! |
I've made stylistic tweaks to please the linter; if it passes now, excellent. If there are test updates needed, I may need a little help getting it over the line, as I'm not a Ruby coder (I know just about enough Ruby to blunder my way through - I'm a Perl guy at heart) and don't have a huge amount of time available. As an aside, some of the complaints I, personally, think are a bit weird - e.g.:
You could argue it's redundant at present, because it'll be implicitly returned, but (a) making it explicitly clear what you intend to return is a good thing, and (b) it protects someone who comes along in future to change that code, and accidentally changes what's returned by adding code after that line. That said - if that's what the style guide for the project says, then so be it. |
Codecov Report
@@ Coverage Diff @@
## main #473 +/- ##
==========================================
+ Coverage 72.88% 73.03% +0.15%
==========================================
Files 10 10
Lines 1088 1083 -5
==========================================
- Hits 793 791 -2
+ Misses 295 292 -3
Continue to review full report at Codecov.
|
Alright, help with the coverage fail would be welcomed - I can't see any reason that the changed code wouldn't be covered sufficiently by existing tests. |
Hi @bigpresh - we're looking in to some of the test failures on this PR and will look to address and try and provide some additional coverage, if required. Sorry for the delay - it's on our list to get to. Thanks again for the fix - we'll get it merged soon 👍 |
Hi @bigpreshkt, Thanks |
Took me a moment to locate, but I see it, 41ac50a ... just figuring out how to get GitHub to incorporate it in this PR, as it appears to be already pushed to the branch... |
41ac50a
to
b057de4
Compare
Right, I have updated my |
b057de4
to
c32b3da
Compare
OK, resolved the conflict (I'd not correctly updated |
And now, failing with key verification errors, e.g.:
I'd hazard a guess that this was masked by the previous "disable SSH host key checking if we're using an identity even if we weren't asked to" code, which no longer exists. |
Previously, if the resource specified `user`, then git would be executed as that user... except if you also provided `identity` to control which SSH key to use, in which case the code did the setup required for the git helper script, then called git directly (bypassing the bit that ran it as the desired user). This changes it by wrapping up the execution of git in a new method which contains the logic to run as the specified user if they asked for that, and uses that wrapper from both places in git_with_identity.
If you use `identity`, at present a shell script to wrap `ssh` was written out (to the Puppet state dir) then git told to use it by pointing the GIT_SSH env var at it. That failed after my changes to run git as the user requested, because the user probably doesn't have access to the script in the Puppet state dir. The script is unnecessary IMO, anyway - setting the options it sets can just as easily be done by `-o` options in the `GIT_SSH_COMMAND` env var, which is what I've done here. Note that I have intentionally not included the disabling of StrictHostKeyChecking which was present in the wrapper script, as I do not think that intentionally reducing someone's security without being asked to do so is a good idea. Similarly I left out setting the timeout, as that isn't related to being asked to use a given identity key. (It may well be that there should be a new `ssh_opts` attribute you can set on a Vcsrepo resource to pass options along, perhaps, but I think that's outside the scope of what I'm trying to fix here.)
I consider this far clearer with the return, but the linter doesn't like it.
545e229
to
7577b70
Compare
Hi @bigpresh, I think I might need to do a bit of a work-around for the cloning test for some permission issues, but it should be closer to getting it merged. Thank you for your patience on getting this fix in. |
Many thanks for the update @carabasdaniel, appreciate it! I suspect the test is going to need to add the server's host key to
Maybe something like: run_shell("ssh-keyscan localhost > #{homedir}/.ssh/known_hosts") |
be53731
to
0779fe3
Compare
0779fe3
to
12aa1dc
Compare
spec/acceptance/clone_repo_spec.rb
Outdated
@@ -479,7 +479,7 @@ | |||
run_shell("mkdir -p #{homedir}/.ssh") | |||
run_shell("ssh-keygen -q -t rsa -f #{homedir}/.ssh/id_rsa -N ''") | |||
|
|||
run_shell('ssh-keygen -R localhost', expect_failures: true) | |||
run_shell('rm ${homedir}/.ssh/known_hosts', expect_failures: true) | |||
run_shell("ssh-keyscan localhost >> #{homedir}/.ssh/known_hosts") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firstly - could avoid the rm
above by just blatting the file with >
instead of >>
.
Secondly, #{homedir}
here - will that be the homedir of the "target" user whose repo we're trying to check out, or that of the user running the Puppet code (root?)? It wants to be the second, not the first.
(EDIT: if it is the latter, then that's my mistake earlier - sorry!)
I think this remaining test failure is a confusion over which user it's SSHing as vs which user had the host keys written to, etc. I think the run_shell() commands which write out a .ssh/config with StrictHostKeyChecking can be removed from the tests here too, since the host key *should* be right, but let's see first if this gets the test to pass before looking at that. (If this is wrong, feel free to revert!)
Repeat the setup of the testssh-user here for this test too. Copying and pasting this feels very wrong; it should probably be refactored out into a method that is called by both of the "check out over SSH" tests, or the two tests turned into subtests in the same context?
Actually run the clone as testuser-ssh after preparing their SSH known hosts etc.
That should be all the tests passing, although I'm not very happy with the copy & paste cargo-cult way I did it, I'm sure the repetition could be refactored out! |
Daniel Carabas seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@bigpresh Thank you for your contribution, this look's good to me so Ive gone ahead and merged. |
hey ho. Is is possible that this is a backwards-incompatible change? I didn't look in detail but there's some discussion in https://puppetcommunity.slack.com/archives/C11LCKKQ9/p1622029307033000 and it looks like this change broke a user installation with the vcsrepo upgrade 4.0.0->4.0.1 |
Can't see the discussion as I'm not part of the Puppet Slack thingy, but this PR does stop StrictHostKeyChecking being disabled without you asking/wanting that - it's possible that they were connecting somewhere that succeeded only because setting an identity to use had the unexpected and unrequested side effect of turning off StrictHostKeyChecking. EDIT: commit 98cb96f is the change I refer to there - the code used to write out a shell script wrapper to call SSH, which would turn off StrictHostKeyChecking even though you never asked for that. It was replaced with a cleaner direct call to SSH, and the unrequested lowering of the user's security removed. |
Previously, if the resource specified
user
, then git would be executed as that user... except if you also providedidentity
to control which SSH key to use, in which case the code did the setup required for the git helper script, then called git directly (bypassing the bit that ran it as the desired user).This changes it by wrapping up the execution of git in a new method which contains the logic to run as the specified user if they asked for that, and uses that wrapper from both places in git_with_identity.