Giter Site home page Giter Site logo

pam_pwd's Introduction

pam_pwd

CI Testing

This role configures PAM to implement a password policy to meet requirements like minimum password length, complexity, keep password history, etc. It supports:

  • Fedora >= 35
  • RHEL 7
  • RHEL 8
  • RHEL 9 Beta
  • CentOS 7
  • CentOS Stream 8
  • CentOS Stream 9

The role was tested with the following versions of Ansible:

  • ansible-core 2.11
  • ansible-core 2.12

To use this role you have to specify the role variables which are described below.

Requirements

None.

Role Variables

Here you find a description of all input variables (i.e. variables that are defined in defaults/main.yml) for the role as these form the API of the role. The following code block shows all necessary input variables and their default values. They are specified in defaults/main.yml.

pam_pwd_minlen: "12" # defines the minimum acceptable size for a password.
pam_pwd_history: "5" # defines the number of previous passwords which cannot be used.
pam_pwd_dcredit: "-1" # defines minimum credit for having required digits in password.
pam_pwd_ucredit: "-1" # defines minimum credit for having uppercase characters in password.
pam_pwd_lcredit: "-1" # defines minimum credit for having lowercase characters in password.
pam_pwd_ocredit: "-1" # defines minimum credit for having other characters in password.
pam_pwd_minclass: "4" # defines minium number of required character classes in new password.
pam_pwd_enforce_root: "enforce_for_root" # (""|"enforce_for_root") defines whether or not to enforce password complexity for user root.
pam_pwd_policy_name: "password-policy" # RHEL 8 only. Define name of the custom authselect profile.
pam_pwd_deny: "5" # Set the number of failed login attempts after which the account is locked.
pam_pwd_unlock_time: "300" # Time in seconds after which an account is unlocked again.

You can keep these default values if they fit your requirements. Or you can overwrite the defaults by specifiny some or all of them in places like vars/main.yml, group_vars/, host_vars/ or your playbook.

Dependencies

None.

Example Playbook

The following code block shows the simplest playbook to run this role:

- hosts: all
  roles:
    - pam_pwd

More examples can be found in the examples/ directory.

License

MIT.

Author Information

Author: Joerg Kastning
Contact: [email protected]

pam_pwd's People

Watchers

 avatar  avatar  avatar

pam_pwd's Issues

Integration testing

Next, I'm going to run some integration tests for the following platforms/releases:

  • Fedora 35
  • CentOS 7
  • CentOS 8 Stream
  • CentOS 9 Stream
  • RHEL 7
  • RHEL 8
  • RHEL 9 beta

In case there are errors, I'll make a note here. Once all integration checks are passed I guess I could open a pull request to pull this role into the Linux System Roles project.

Improve the creation of a custom authselect profile

Current situation

As I created the role following the Red Hat KB Set Password Policy/Complexity in Red Hat Enterprise Linux 8 the role creates a new authselect profile based on the authselect profile sssd. I did that because the KB told me so and on a fresh install there is now authselect profile in use.

When and why does it break?

On an existing system with different state this might break things. When a system uses an authselect profile other than sssd the profile would be replaced by the new costomized profile and all individual settings of the previously used are lost.

How to improve it?

  1. Check whether an authselect profile is currently in use. If not, proceed by copying sssd profile.
  2. If an authselect profile is already in use, copy the active authselect profile to create a new custom profile.

IMHO that should reduce the risk of breaking things.

comments on initial commit

https://github.com/Tronde/pam_pwd/blob/master/meta/main.yml#L45
please add

  - name: Fedora
    versions:
    - all

unless Fedora is very different and does not work with the code you have.

https://github.com/Tronde/pam_pwd/blob/master/tasks/main.yml
some general issues

  • do not use become: anywhere - if the user wants to use become, they can use ansible-playbook --become, or put it in the inventory, or etc.
  • You mostly do not need to use quoting for strings e.g. name: This is a multi word string that does not require quoting is valid YAML - you can also use YAML > and | for multiline strings for readability e.g.
command: >
  this is a
  multiline
  command

gets passed to the remote shell as this is a multiline command or

somestring: |
  this
  is
  a
  multiline string with the newlines

keeps the embedded newlines
One place you must use quotes is when the value begins with {{ e.g. value: "{{ item }}" but not value: this is item {{ item }}

  • do not use FQCN module names for builtins - use lineinfile instead of ansible.builtin.lineinfile - I know that the Ansible guidelines say to use FQCN everywhere, but there is a lot of debate around this - none of our other roles use FQCN - and for collections we have a tool which converts roles to collection format and can (or can easily be changed to) convert names to FQCN if necessary (https://github.com/linux-system-roles/auto-maintenance/#lsr_role2collectionpy)

  • prefer to not have a lot of conditional code e.g. there are a lot of when: ansible_facts['distribution_major_version'] == "7". There are a couple of ways to handle this:

If there are only a few places where conditionals will be used, add some code like this to your tasks/main.yml - https://github.com/linux-system-roles/template/blob/master/tasks/main.yml#L8-L21 (and change __template_* to __pam_pwd_*). Then, in the various vars/Platform.yml and vars/Platform_Version.yml files, add variables like

__pam_pwd_edit_auth_files: true

for those platforms where you need to update /etc/pam.d/system-auth and /etc/pam.d/password-auth - then you can do things like:

- name: "Keep history of the last {{ pam_pwd_history }} passwords used."
 lineinfile:
    path: "{{ item }}"
    insertafter: '^.*pam_pwquality.so.*$'
    line: "password    requisite     pam_pwhistory.so remember={{ pam_pwd_history }} use_authtok"
    state: present
    backup: yes
  with_items:
    - /etc/pam.d/system-auth
    - /etc/pam.d/password-auth
  when:
    - item is exists
    - __pam_pwd_edit_auth_files | bool

If there a lot of places where the tasks are different, then consider using different task files for different platforms. https://github.com/redhat-cop/automation-good-practices/blob/main/roles/README.adoc#platform-specific-tasks describes a method by which you would have a completely different way to manage passwords on rhel7 vs. rhel8.

https://github.com/Tronde/pam_pwd/blob/master/tasks/main.yml#L52
missing something after the or?

https://github.com/Tronde/pam_pwd/blob/master/tasks/main.yml#L56
it is better to specify

template:
  src: "{{ item }}"

ansible should do the right thing - look in the role templates/ directory

There is a lot of use of command here - this isn't necessarily a bad thing, but it makes it harder to work in check_mode and makes it harder to be idempotent. https://github.com/redhat-cop/automation-good-practices/blob/main/roles/README.adoc#check-mode-and-idempotency-issues
specifically - use changed_when: false with command: if the command does not actually change anything
To make it idempotent, you should first see if the change needs to be made. I'm not sure how authselect works, but something like this:

- name: List profiles {{ pam_pwd_policy_name }}
  command: authselect list
  register: __pam_pwd_authselect_list
  changed_when: false

- name: Select profile {{ pam_pwd_policy_name }}
  command: authselect select custom/{{ pam_pwd_policy_name }}
  when: not pam_pwd_policy_name is search(__pam_pwd_authselect_list)

that way, Select profile will only be used if it is needed, and the role will report changed: false if nothing was changed.

  • apply changes - typically a handler is used for this - each task which may change the state of the system requiring an authselect apply will call notify: pam_pwd_authselect_apply - then in handlers/main.yml have a task like this:
- name: Apply authselect changes
  listen: pam_pwd_authselect_apply
  command: authselect apply-changes

Then ansible will call authselect apply-changes, usually at the end of the role or end of the play. This can be problematic though if you want the changes to apply immediately. In that case, you'll need to use register to keep track of each task that changed something, and call authselect apply-changes yourself. Something like this:

- name: Select profile {{ pam_pwd_policy_name }}
  command: authselect select custom/{{ pam_pwd_policy_name }}
  when: not pam_pwd_policy_name is search(__pam_pwd_authselect_list)
  register: __pam_pwd_profile

- name: Enable-feature with-faillock
  command: authselect enable-feature with-faillock
  when: not 'with-faillock' is search(__pam_pwd_get_faillock)
  register: __pam_pwd_faillock

- name: Apply changes
  command: authselect apply-changes
  when: __pam_pwd_profile is changed or __pam_pwd_faillock is changed

see https://docs.ansible.com/ansible/2.9/user_guide/playbooks_tests.html#testing-strings for info about using match, search, and regex

https://github.com/Tronde/pam_pwd/blob/master/templates/password-auth and https://github.com/Tronde/pam_pwd/blob/master/templates/system-auth should also have {{ ansible_managed | comment }} headers (assuming these files can accept comments, and the comment style is # - https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#adding-comments-to-files

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.