Git Product home page Git Product logo

puppet-duo_unix's Introduction

duo_unix

Travis (.org)

The duo_unix module handles the deployment of duo_unix (login_duo or pam_duo) across a range of Linux distributions. The module will handle repository dependencies, installation of the duo_unix package, configuration of OpenSSH, and PAM alterations as needed.

For further information about duo_unix, view the official documentation.

Table of Contents

  1. Description
  2. Setup - The basics of getting started with duo_unix
  3. Usage - Configuration options and additional functionality
  4. Limitations - OS compatibility, etc.
  5. Contributing

Description

The duo_unix Puppet module installs and manages duo_unix (login_duo or pam_duo).

This module is meant to be a drop-in replacement for the abandoned official puppet module.

Setup

What duo_unix affects

This module will add the official Duo Inc. repository. It will also then install the appropriate package(s) for your system.

It will also optionally alter some files on your system to help ensure that user login attempts will correctly require Duo to succeed.

If usage is set to login, it will set the following directives in /etc/ssh/sshd_config

ForceCommand       /usr/sbin/login_duo
PermitTunnel       no
AllowTcpForwarding no

If usage is set to pam, it will alter your pam config. Those changes are distribution-specific. To see exactly what is changed, please refer to the manifests/pam_config.pp file.

If accept_env_factor is set to yes, it will configure your sshd_config to allow DUO_PASSCODE as an AcceptEnv value to enable out-of-band 2FA in the shell for use cases such as scp. This feature is only possible if usage is set to login.

Setup Requirements

This module requires some additional modules, but it is highly likely that they are already installed on your puppet server. They are as follows:

  • puppetlabs/apt 6.0 - 9.0
  • puppetlabs/augeas_core 1.0.0 - 2.0.0
  • puppetlabs/stdlib 5.0.0 - 10.0.0
  • puppetlabs/yumrepo_core 1.0.0 - 2.0.0

Beginning with duo_unix

The very basic steps needed for a user to get the module up and running. This can include setup steps, if necessary, or it can be an example of the most basic use of the module.

Usage

class { 'duo_unix':
  usage             => 'login',
  ikey              => 'your integration key',
  skey              => 'your secret key',
  host              => 'api-yourhost.duosecurity.com',
  motd              => 'yes',
  accept_env_factor => 'no',
  duo_rsyslog       => false, 
}

Notes

  • accept_env_factor is set to 'no' by default, but when set to 'yes', enables DUO_PASSCODE as desribed above for out-of-band 2FA
  • duo_rsyslog is set to false by default, but when set to true, enables sending duo auth messages to the OS-default auth log (this is also very helpful for simplifying fail2ban config if also used)

Limitations

In the past the official Duo module supported various RedHat derivatives. This module currently only makes minor attempts to support them.

Contributing

Pull requests are welcome, but all code must meet the following requirements

  • Is fully tested
    • Note: Unit testing uses the rspec-puppet-augeas Ruby gem, which requires the following local packages (at least in Debian-based environments) to be installed: ruby-augeas augeas-tools augeas-lenses libaugeas-dev
  • All tests must pass
  • Follows the Puppet language style guide
  • All commits must be signed

puppet-duo_unix's People

Contributors

avitacco avatar jhoerr avatar kekogya avatar markaddonizio avatar mboisson avatar ncsutmf avatar scorgatelli-docutech avatar thoughtful-explorer avatar treydock avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppet-duo_unix's Issues

Using ensure => latest throws an error

First of all, thanks for this replacement!

We noticed that when we set ensure to latest (default = present) , the puppet agent will give an error:
Error: Failed to apply catalog: Validation of File[/etc/duo/login_duo.conf] failed: You cannot specify more than one of content, source, target (file: /etc/puppetlabs/code/modules/duo_unix/manifests/init.pp, line: 140)

This error is not cause by de Package resource but with the File resource (etc/duo/login_duo.conf) where the same $ensure is used. To my knowledge this cannot work this way.

For now I changed the Package resource to latest by hand.

Using CERN-CERT pam_2fa with iu-duo_unix

We would like to use iu-duo_unix while also using the approach proposed by CERN to protect the second factor:
https://cern-cert.github.io/pam_2fa/

iu-duo_unix is essentially missing three things:

  • pam_ssh_user_auth package
  • Inserting auth pam_ssh_user_auth.so, auth pam_deny and auth /lib64/security/pam_duo.so in /etc/pam.d/sshd
  • Inserting AuthenticationMethods gssapi-with-mic,keyboard-interactive:pam publickey,keyboard-interactive:pam keyboard-interactive:pam,keyboard-interactive:pam in /etc/ssh/sshd_config.

Would you be interested in a PR that implements this in iu-duo_unix?

Repo not set correctly on CentOS Stream 9

There is no CentOS 9, only CentOS Stream. The repos for Stream are at a different path. It looks like there is a simple fix in the duo_unix:::repos class here by changing it to:

    $osname = $facts['os']['name'] ? {
        'CentOS'       => $facts['os']['release']['id'],
        default        => 'RedHat',
      }

More Info on the os release id fact and CentOS Stream: puppetlabs/facter#2291 (comment)

This would also have the effect of pointing CentOS 8 Stream at the CentOSStream repo instead of the CentOS repo path.

Also noticed CentOS Stream "support" was added but then removed in 6c009d8 due to the os name fact still being set to CentOS. Most of that can probably be added back with some additional changes to the repo spec test.

I can probably submit a Pull Request but it will take me a bit to set up signing of commits.

Repo added incorrect on Rocky Linux & possibility to handle repos outside module

I'm trying to use this module on Rocky Linux (RIP CentOS...), it adds the repo as
"https://pkg.duosecurity.com/Rocky/$releasever/$basearch" in the "/etc/yum.repos.d/duosecurity.repo" file.

However, there's no such repo (or symlink) available on duosecurity's repo.. Not sure if this would be the prefered way?

Aditionally; is there any way to make the module not handle the repos so we can handle this ourselves?
I prefer to use internal repositories.. (servers usually don't have direct internet access).

AllowTcpForwarding Setting

AllowTcpForwarding no should be removed and managed in a different way like using the SSH module to manage this setting as this setting conflicts in environments where the requirement for AllowTcpForwarding needs to be yes. In this issue, I also took the opportunity to update pdk, changelog, metadata.json and also removed the vscode extension. All unit test passes. Pull request to follow up soon.

Repo added is incorrect

The architecture specification for Ubuntu 18.04 does not work correctly.

E: Failed to fetch https://pkg.duosecurity.com/Ubuntu/dists/xenial/Release  Unable to find expected entry 'main/binary-x86_64/Packages' in Release file (Wrong sources.list entry or malformed file)

Setting ForceCommand in the global settings of sshd_config file does not consider chroot users

It is more flexible for the ForceCommand line to be inside a "match" block, whether group or user. Using this match block would apply to all users:

Match Group * ForceCommand /usr/sbin/login_duo PermitTunnel no

Using this method, you can specify which groups or users should not be forced to go through Duo 2FA (following a ! character). We tried to use the "groups" option in the login_duo.conf file but it fails for special users with a chroot directory. This is because the groups restriction in login_duo happens after sshd runs the force_command.

Can line 15 be removed from the ssh_config.pp?

'set ForceCommand /usr/sbin/login_duo',

SSH service for RedHat os family should also be sshd

Just tried the update on a CentOS machine and am getting the error:

Error: Systemd start for ssh failed!
journalctl log for ssh:
-- No entries --

Error: /Stage[main]/Duo_unix::Ssh_config/Service[ssh]/ensure: change from 'stopped' to 'running' failed: Systemd start for ssh failed!
journalctl log for ssh:
-- No entries --

I'm pretty sure the ssh service for the RedHat family is sshd and not ssh.

Add PAM functionality

Need to write code to configure ssh to use PAM and to configure the PAM stack to use Duo.

Repo configured multiple times

Because the original repo was named differently from the current repo it is added twice which causes an error on Ubuntu which causes puppet to fail.

Augeas is potentially untestable

To test the addition of AcceptEnv variables to sshd_config using augeas in manifests/ssh_config.pp, I have attempted to also properly apply unit tests to these augeas blocks (using rspec-puppet-augeas). This is because when we're unit testing, we're testing the contents of a Puppet catalog instead of the real sshd_config file. I therefore created an updated spec/classes/ssh_config_spec.rb with this content:

require 'spec_helper'
describe 'duo_unix::ssh_config' do
  let(:pre_condition) { "package { 'duo_unix': ensure => 'installed' } package { 'duo-unix': ensure => 'installed' }" }

  on_supported_os.each do |os, os_facts|
    let :pre_condition do
      "class { 'duo_unix':
        usage => 'login',
        ikey => 'testikey',
        skey => 'testskey',
        host => 'api-XXXXXXXX.duosecurity.com',
        accept_env_factor => 'yes' }"
    end

    context "on #{os}" do
      let(:facts) { os_facts }

      it { is_expected.to compile }
    end

    context 'with accept_env_factor => yes' do
      let(:facts) { os_facts }

      it {
        is_expected.to contain_file('/etc/duo/login_duo.conf')
          .with_content(%r{^accept_env_factor=yes$})
      }
      describe 'sshd' do
        it 'Finds duo_ssh_env augeas resource' do
          is_expected.to contain_augeas('duo_ssh_env')
        end

        # Expects Augeas['duo_ssh_env'] because sshd_config is a pre-existing and therefore not testable in the catalog by Rspec
        describe_augeas 'duo_ssh_env', lens: 'Sshd.lns', target: 'etc/ssh/sshd_config' do
          it 'Ensures DUO_PASSCODE is added to AcceptEnv' do

            # Check changes in the file with aug_get and aug_match
            aug_match('DUO_PASSCODE').is_expected.to include('DUO_PASSCODE')

            # Verify idempotence last to prevent false positive
            is_expected.to execute.idempotently
          end
        end
      end
    end
  end
end

However, when running the unit tests, I get (many copies of) this error:

Failures:

  1) duo_unix::ssh_config with accept_env_factor => yes sshd Augeas[duo_ssh_env] Ensures DUO_PASSCODE is added to AcceptEnv
     Failure/Error: aug_match('DUO_PASSCODE').is_expected.to include('DUO_PASSCODE')
     
     RuntimeError:
       Got 2 failure(s) while initializing: File[/tmp/d20240415-916643-c35377]: change from 'absent' to 'directory' failed: Failed to set owner to '0': Operation not permitted @ apply2files - /tmp/d20240415-916643-c35377; File[/tmp/d20240415-916643-nn2gev/ssl]: change from 'absent' to 'directory' failed: Failed to set owner to '0': Operation not permitted @ apply2files - /tmp/d20240415-916643-nn2gev/ssl
     # ./spec/classes/ssh_config_spec.rb:38:in `block (6 levels) in <top (required)>'
     # bin/rspec:29:in `load'
     # bin/rspec:29:in `<main>'

Unfortunately, there appears to be a number of very stale (and unlikely to change) official sources that indicate this error will not be resolved:

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.