RexOps / RexOps/Rex

Commands executed on remote hosts have their locale unexpectedly switched

Open
#1,230 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
Perl
Stars
737
Forks
214
PR merge metrics
No merged PRs in 30d

Description

When I ssh to a remote host manually and run locale I get the following result:

$ locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=

However, when I launch this task on the same host as the same user using Rex:

#!/usr/bin/env perl

use 5.026;
use strict;
use warnings;

use Rex -feature => [qw/1.3/];

task 'test_locale' => sub {
    my $out = run 'locale';

    say 'locale on remote host: ' . $out;
};

auth for => 'test_locale', user => 'myuser';

I get the following result:

% rex -H target.host test_locale
[2019-09-23 11:19:29] INFO - Running task test_locale on target.host                    
locale on remote host: LANG=en_US.utf8
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C

This suggests that Rex enforces certain locale for remote connections, which can lead to hard to debug consequences ( one real example: if a Postgres database is created from inside such Rex connection, it will have its locale set to C and some collation operations will behave strangely ).

This behavior is completely unexpected and surprising because the documentation for 'run' https://metacpan.org/pod/Rex::Commands::Run does not say a word about locale switching.

I think Rex should not touch user's locale settings unless explicitly instructed to do so.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Rex::Commands::Run and the remote execution path, then reproduce the reported difference between manual SSH and rex by running locale on the same host. Trace where the remote command environment is established. Done means Rex preserves the user's locale by default, with locale changes occurring only when explicitly requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
devops, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.