Skip to content
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

Allow uploading files even when permissions cannot be set. #1471

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alip
Copy link
Contributor

@alip alip commented Feb 12, 2021

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

  • based on top of latest source code
  • changelog entry included
  • tests pass on Travis CI
  • git history is clean
  • git commit messages are well-written

alexeyklyukin and others added 2 commits February 12, 2021 10:15
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.
@alip alip mentioned this pull request Feb 12, 2021
Copy link
Member

@ferki ferki left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants