-
Notifications
You must be signed in to change notification settings - Fork 214
Allow uploading files even when permissions cannot be set. - #1471
Conversation
By default, the "file" function uses sftp to upload the target file to the server. During the upload, the Net::SFTP::Foreign runs chmod unconditionally, failing if the target file is not owned by the ssh user, unless that user is a root. This commit changes that behavior by passing an optional "best_effort" flag that instructs sftp to continue even if setting permissions has failed. As a result, an unprivileged user will be able to use Rex scenarios that call the "file" function without getting permission denied errors.
This ensures the current behavior continues for ops but best effort for writeable files allows other teams to apply changes. Also began some initial POD for the OpenSSH module in functions touched.
@ferki
ferki
left a comment
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.
I believe this would be best discussed in a feature request issue first.
If we are going to make it a feature, I think the best_effort functionality should be controlled via a config option in Rex::Config (whether the user explicitly want it or not), instead of basing it on the fact whether sudo is used or not (which could break for other privilege escalation methods).
And if it's going to be a first class config option, I believe it would be best to make it a generic one to pass arbitrary (Net::SFTP::Foreign?) options similarly to set_openssh_opt. That would avoid having to do further pull requests for each use case that might arise.
By default, the "file" function uses sftp to upload the target file to
the server. During the upload, the Net::SFTP::Foreign runs chmod
unconditionally, failing if the target file is not owned by the ssh
user, unless that user is a root. This commit changes that behavior by
passing an optional "best_effort" flag that instructs sftp to continue
even if setting permissions has failed.
As a result, an unprivileged user will be able to use Rex scenarios that
call the "file" function without getting permission denied errors.
This PR is an attempt to fix # by .
Checklist