Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

How do I allow my test script to get rsync to archive file ownership?

by nysus (Parson)
on Jan 22, 2018 at 17:16 UTC ( [id://1207687]=perlquestion: print w/replies, xml ) Need Help??

nysus has asked for the wisdom of the Perl Monks concerning the following question:

OK, I've been struggling with this for a while now and getting no where.

I've got a test script t/test.t. My test script loads a Moose object that has a wrapper for Net::OpenSSH which I use to create an rsync archive from a remote server to my local server. I set up Vim so that when I hit <F7>, it will call a custom script I have called run_tests.sh which executes my test script with the prove command and displays the test results in a separate tmux pane. It all works great.

The problem is that since my test script is run under my local user account, it does not have the proper permission to change the uid/gid of the downloaded files. I tried to fix this by editing my bash script to run sudo -HE prove ... with the -HE options to to try to preserve my local user's environment so the root user would still have access to my PERL5LIB path. But it didn't work. I still get the Can't locate Blah.pm in @INC error. Apparently, sudo strips out the PERL5LIB path out for security reasons.

The other thing I struggle with is I want to avoid typing in my password every time I run my test. Typing in my password dozens of times is not my idea of fun.

Is there a way to securely give my script the ability to change permissions on the downloaded files (and preferably without the need to enter my password)?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: How do I allow my test script to get rsync to archive file ownership?
by Corion (Patriarch) on Jan 22, 2018 at 17:33 UTC

    At least for the password, I think that Net::OpenSSH can let your ssh-agent provide the key. That way, you only need to load your keys once and provide the password to them once, and all SSH-based scripts can then reuse them.

    I'm somewhat unclear on your actual setup and why/where you have a problem with the environment. Personally, I like to do all development locally and have the needed modules pulled in through a Makefile.PL or cpanfile, which I load via cpanm --installdeps .. I don't need any kind of root user or permissions to upload my files to a remote account though, and really prefer it that way, so I don't really understand where your problem actually is. My suggestion here is to find a setup that does not need root on either side of the connection at all.

      I'm already using an ssh key for the remote machine. I'm referring to the password prompt for the sudo command in my bash script.

      Regarding the libraries, in my bash profile, I have PERL5LIB=/path/to/my/perl/modules. The modules in my PERL5LIB path weren't installed with cpan. They are just simple module files located in a regular old directory.

      For rsync's archive feature to work properly, using the root user is the prescribed way to do it, at least from what I've read. See this discussion, for example.

      Thanks!

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        Sudo can be configured to not ask for a password. See the NOPASSWD option.

        I don't get this. Why don't you upload as the user who should be owning the files in the end? That way you won't need root and won't need rsync to change the ownership at all.

Re: How do I allow my test script to get rsync to archive file ownership?
by Arunbear (Prior) on Jan 22, 2018 at 18:20 UTC
    What are your tests trying to verify? Bear in mind that Net::OpenSSH and rsync have their own test suites, so you don't need to retest functionality that they are responsible for.

      I'm testing that my objects which contain wrappers to Net::OpenSSH (which wraps rsync) are properly syncing files to and from a server. So for example, I can rsync easily and safely with something like this:

      # set up my server my $server = Server->new('host_name'); $server->set_remote_dir('/my/files'); $server->rsync_dir;

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Re: How do I allow my test script to get rsync to archive file ownership?
by pritesh (Scribe) on Jan 22, 2018 at 18:05 UTC

    Hi,

    Long time ago, while working with a friend, I had seen fake-super option in his script...may be that will work.

      Nice, but apparently, the Mac version of rsync does not recognize this option. :(

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1207687]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-26 00:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found