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

AixPb: Put /usr/bin to the front of the PATH #2057

Closed
wants to merge 8 commits into from

Conversation

Haroon-Khel
Copy link
Contributor

Following on from a discussion with @sxa in slack, /usr/bin should be at the beginning of the PATH variable, ahead of /opt/freeware/bin

@Haroon-Khel Haroon-Khel added this to the March 2021 milestone Mar 19, 2021
@Haroon-Khel Haroon-Khel requested a review from sxa March 19, 2021 10:55
@Haroon-Khel
Copy link
Contributor Author

ping @aixtools

@Haroon-Khel Haroon-Khel changed the title AixPb: reverse aix path AixPb: Put /usr/bin to the front of the PATH Mar 19, 2021
Copy link
Contributor

@aixtools aixtools left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a typo - missing '/' in string PATH=usr/bin:...

Also, why not use something like the PATH: statement on line 11:

   +10    environment:
  +11      PATH: "/opt/IBM/xlC/13.1.3/bin:/opt/freeware/bin:{{ ansible_env.PATH }}"

And, I wonder if it should not ALSO be changed on line 11?

@Haroon-Khel
Copy link
Contributor Author

I searched through the aix playbook. I dont think that PATH environment variable is used at all. Will need to make a more thorough search

@Haroon-Khel
Copy link
Contributor Author

Before merging, I will have to test a build and test with this new PATH variable

@Haroon-Khel
Copy link
Contributor Author

jdk11 hotspot build on test-ibm-aix71-ppc64-1 with the new PATH variable to test
https://ci.adoptopenjdk.net/job/build-scripts/job/jobs/job/jdk11u/job/jdk11u-aix-ppc64-hotspot/890/console

@Haroon-Khel
Copy link
Contributor Author

jdk11 hotspot build on test-ibm-aix71-ppc64-1 with the new PATH variable to test
https://ci.adoptopenjdk.net/job/build-scripts/job/jobs/job/jdk11u/job/jdk11u-aix-ppc64-hotspot/890/console

That passed. Running a jdk11 openjdk sanity test
https://ci.adoptopenjdk.net/job/Grinder/7960/console

@Haroon-Khel
Copy link
Contributor Author

That too passed. A nightly openj9 jdk8 job is running on the machine. Just for safe measure it can be used as a final indicator as to whether this new PATH variable breaks anything
https://ci.adoptopenjdk.net/job/build-scripts/job/jobs/job/jdk8u/job/jdk8u-aix-ppc64-openj9/999/consoleFull

@Haroon-Khel
Copy link
Contributor Author

Haroon-Khel commented Mar 23, 2021

The above job passed. Ping @sxa for review

@karianna karianna added this to TODO in infrastructure via automation Mar 23, 2021
@karianna karianna moved this from TODO to In Progress in infrastructure Mar 23, 2021
Copy link
Contributor

@aixtools aixtools left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works - have you tested it to be sure it works a second time?
i.e., when PATH=/usr/bin:/opt/IBM/xlC/13.1.3/bin:/opt/freeware/bin/:...

does not regexp to:

PATH=/usr/bin:/opt/IBM/xlC/13.1.3/bin:/opt/freeware/bin/:/opt/IBM/xlC/13.1.3/bin:/opt/freeware/bin/:...

How about including /etc in the regexp but replacing it - in a way that the regexp will not match a second time around?

@Haroon-Khel
Copy link
Contributor Author

Haroon-Khel commented Mar 24, 2021

@aixtools Youre right it does.

The /etc idea is good, but the question is will all new machines have a /usr/bin:/etc block in their PATH?

I was thinking the updated PATH could start with /opt/IBM/xlC/13.1.3/bin:/usr/bin:/opt/freeware/bin instead? That would make the change idempotent as there wouldnt be a PATH=/usr/bin to for ansible to find

@aixtools
Copy link
Contributor

aixtools commented Mar 24, 2021 via email

@Haroon-Khel
Copy link
Contributor Author

That works. This regexp is now idempotent

Copy link
Member

@sxa sxa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we ensure that this does not run if the adoptopenjdk tag is skipped - we shouldn't be modfiying system defaults like this if someone else is running them and skipping the adoptopenjdk ones, especially since it could remove things that they already have in there.

@Haroon-Khel
Copy link
Contributor Author

@sxa Just that task? Or the other login_shell tagged tasks too?

    - name: Add bash to available login shells
      replace:
        path: /etc/security/login.cfg
        regexp: 'shells = '
        replace: 'shells = /bin/bash,'
      tags: login_shell

    - name: Add bash to available login shells
      blockinfile:
        dest: /etc/shells
        block: |
          /bin/bash
      tags: login_shell

    # move to role later
    - name: Set variables for global environment
      blockinfile:
        dest: /etc/environment
        block: |
          AIXTHREAD_HRT=true
          PKG_CONFIG_PATH=/opt/freeware/lib64/pkgconfig:/opt/freeware/lib/pkgconfig
          PERL5LIB=/opt/freemarker/lib/perl5
      tags: login_shell

@sxa
Copy link
Member

sxa commented Mar 24, 2021

Can we ensure that this does not run if the adoptopenjdk tag is skipped - we shouldn't be modfiying system defaults like this if someone else is running them and skipping the adoptopenjdk ones, especially since it could remove things that they already have in there.

Most of those are additions rather than potentially breaking things, so while it's not as critical, I'd say that yes they should all have it, although I'm not sure why we need to add bash to the list. It shouldn't be critical for jenkins to work.

Copy link
Contributor

@aixtools aixtools left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of things:

  • Considering /bin/bash is a symbolic link outside of / I do not consider it a fantastic argument for a shell (for AIX admin accounts - /bin/sh and /bin/ksh used to be as login shells AND the AIX install makes sure 'shells' are installed as binary programs - not links - these may be in the default shells - BETTER - would be (even as a symbolic link) as more inline with AIX user administration to have the bash shell be /usr/bin/bash.
  • Also, the regexp used to add bash as a shell leaves it open for recursive addition
  • Suggestion: replace regexp with 'shells = /bin' and the new string to be 'shells = /usr/bin/bash,/usr'

Copy link
Contributor

@aixtools aixtools left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • replace /bin/bash with /usr/bin/bash

Copy link
Contributor

@aixtools aixtools left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urgh - my two - now comments - are meant as request changes - so this comment is actually two requests for change

@Haroon-Khel
Copy link
Contributor Author

Haroon-Khel commented Mar 26, 2021

@aixtools instead of a regexp, why not something like

chsec -f /etc/security/login.cfg -s usw -a shells=/usr/bin/bash ?

On ojdk06, the shells in /etc/security/login.cfg in the usw stanza are

/usr/bin/ksh,/usr/bin/ksh93,/usr/bin/rksh,/usr/bin/rksh93,/bin/false

So how about something tidier like

chsec -f /etc/security/login.cfg -s usw -a shells=/usr/bin/bash,/usr/bin/ksh ?

Would that suffice? This command is also idempotent

@aixtools
Copy link
Contributor

aixtools commented Apr 1, 2021

  • That the shells include /bin/false is part of my standard hardening (and I have already shortened the default list of shells)
  • Using command: chsec seems like a good idea - but to be completely idempotent still use something to check if bash is already among the shells (e.g, not the first one).
  • Deleting shells is not a major issue (it mainly affects chsh iirc, but please leave /bin/false as a security measure (to block accounts that are not meant to have a shell from ever getting a shell, even via su).

@karianna karianna modified the milestones: March 2021, April 2021 Apr 1, 2021
@Haroon-Khel
Copy link
Contributor Author

@aixtools regarding your idempotency comment, would it not be more consistent for all new systems to simply have /usr/bin/bash,/usr/bin/ksh,/bin/false in their shells line?

Also, would changing this list of shells affect the way jenkins behaves on the machine?

@aixtools
Copy link
Contributor

aixtools commented Apr 7, 2021

@aixtools regarding your idempotency comment, would it not be more consistent for all new systems to simply have /usr/bin/bash,/usr/bin/ksh,/bin/false in their shells line?

Also, would changing this list of shells affect the way jenkins behaves on the machine?

  • No, won't change anything for existing accounts. It changes the behavior of mkuser, chuser, and chsh - all from memory.
  • I am fine with only three shells in the setting - and the regexp can be to test for that string, and change it if it is different. Should something additional ever be needed - there will be an issue and a PR to fix it. I don't expect anything. Although - would be nice to leave ksh93. :)

@aixtools
Copy link
Contributor

aixtools commented Apr 8, 2021

Can we ensure that this does not run if the adoptopenjdk tag is skipped - we shouldn't be modfiying system defaults like this if someone else is running them and skipping the adoptopenjdk ones, especially since it could remove things that they already have in there.

Most of those are additions rather than potentially breaking things, so while it's not as critical, I'd say that yes they should all have it, although I'm not sure why we need to add bash to the list. It shouldn't be critical for jenkins to work.

FYI: jenkins userid does not need bash as shell. iirc - gmake is calling bash directly.

@aixtools
Copy link
Contributor

Fixes: #1544

@sxa
Copy link
Member

sxa commented Apr 30, 2021

FYI: jenkins userid does not need bash as shell. iirc - gmake is calling bash directly.
Correct - in fact the playbooks create the jenkins user with /usr/bin/ksh as the shell so ... to be honest I don't know why we even make that change - presumably somewhere in the past liked creating other user IDs with bash as the shell ;-)

Copy link
Member

@sxa sxa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, the existing /etc/security/login.cfg on aix72-2 (ojdk04) looks like this:
shells = /bin/bash,/bin/bash,/bin/bash,/bin/bash,/bin/bash,/bin/bash,/bin/bash,/bin/bash,/bin/sh,/bin/bsh,/bin/csh,/bin/ksh,/bin/tsh,/bin/ksh93,/usr/bin/sh,/usr/bin/bsh,/usr/bin/csh,/usr/bin/ksh,/usr/bin/tsh,/usr/bin/ksh93,/usr/bin/rksh,/usr/bin/rksh93,/usr/sbin/uucp/uucico,/usr/sbin/sliplogin,/usr/sbin/snappd
And the chsec command will wipe most of those out, which seems somewat undersirable. I feel this role needs to just add entries, not change the ones already on the system.

However I'm not sure what the relationship between these entries and /etc/shells is - @aixtools do you know?

@karianna karianna modified the milestones: April 2021, May 2021 May 4, 2021
@Haroon-Khel Haroon-Khel modified the milestones: May 2021, June 2021 Jun 21, 2021
@sxa sxa modified the milestones: June 2021, July 2021 Jul 5, 2021
@aixtools
Copy link
Contributor

aixtools commented Jul 7, 2021

@sxa - not sure why or when /etc/shells showed up in AIX.

  • it exists in AIX 5.3 (so as early as 2004)
  • it may have come with AIX 5.1 as part of Linux affinity (since Linux chsh uses /etc/shells the same way AIX chsh uses shells attribute of stanza usw in /etc/login.cfg.
  • As far as I know the shells attribute is the only bit that affects chsh, and perhaps [mk|ch]user commands.

@Haroon-Khel
Copy link
Contributor Author

Closing due to pr not passing eclipse auth check. Reopened at #2288

@Haroon-Khel Haroon-Khel closed this Aug 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
infrastructure
  
In Progress
Development

Successfully merging this pull request may close these issues.

None yet

4 participants