RexOps / RexOps/Rex

INI file with server auth setting sudo=true does not use sudo

Open
#1,520 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the bug

Using sudo=true in an INI file as in the example for Rex::Group::Lookup::INI does not use sudo because it checks if the value is == 1, but this is a numeric comparison so "true" == 1 is false.

How to reproduce it

Steps to reproduce the behavior:

Shortest code example that demonstrates the bug:

# [= Rexfile =]
use Rex -feature => ['1.4','use_server_auth'];

use Rex::Group::Lookup::INI;

groups_file 'server-min.ini';

desc 'Install cpanminus';
task 'cpanminus', group => 'instr', sub {
	pkg "cpanminus", ensure => "present";
};
; [= server-min.ini =]
[instr]
;;; The below works without any Perl warnings

instrument-remote sudo=1


;;; Using the below instead says
;;;
;;; Argument "true" isn't numeric in numeric eq (==)
;;; at Rex/Interface/Connection/OpenSSH.pm
;;; on the line
;;;
;;;   if ( $self->{is_sudo} && $self->{is_sudo} == 1 ) {
;;;
;;; and
;;;
;;; Argument "true" isn't numeric in numeric eq (==)
;;; at Rex.pm
;;; on the line
;;;
;;;  if ( exists $CONNECTION_STACK[-1]->{server}->{auth}->{sudo}
;;;    && $CONNECTION_STACK[-1]->{server}->{auth}->{sudo} == 1 )
;;;

; instrument-remote sudo=true

Expected behavior

Should use sudo when sudo=true is in the INI file.

Per discussion on IRC with @ferki:

[ FErki[m]] at first glance, one possible fix might be the following:
[ FErki[m]] - change the test at https://github.com/RexOps/Rex/blob/master/t/ini.t#L100 to check for
            the value being `1`
[ FErki[m]] - change https://github.com/RexOps/Rex/blob/master/lib/Rex/Group/Entry/Server.pm#L78-L81
            to recognize the `"true"` string, and assign the value of `1` to the internal
            `$self->{auth}->{sudo}` (and perhaps add logic to recognize `"false"` as 0 as well)
[ FErki[m]] alternatively, we could clarify the docs (and the tests) that the value should be 0 or 1,
            but `true/false` seems to be more human-friendly to me in the context of auth info inside
            INI files
[ FErki[m]] a good next step could be to open a formal bug report as a GitHub issue to make it more
            visible for others (including the workaround) and to further discuss/design actual fixing
            steps

Circumstances

  • Rex version: (R)?ex 1.13.5
  • Perl version: perl 5, version 26, subversion 1 (v5.26.1) built for x86_64-linux
  • OS running rex: Debian GNU/Linux 5.15.0 amd64
  • OS managed by rex: Debian GNU/Linux 5.10.17 armv7l
  • How rex was installed: CPAN client

Debug log

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 t/ini.t and lib/Rex/Group/Entry/Server.pm, then trace the sudo checks mentioned in lib/Rex/Interface/Connection/OpenSSH.pm and Rex.pm. Confirm how INI values are normalized and run the relevant INI tests. Done means sudo=true works without numeric warnings while the existing sudo=1 behavior remains correct.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.