Code Monkey home page Code Monkey logo

puppet-ssh-hardening's Introduction

Puppet SSH hardening

Puppet Forge Build Status Gitter Chat

Description

This Puppet module provides secure ssh-client and ssh-server configurations.

Requirements

  • Puppet
  • Puppet modules: saz/ssh (>= 2.3.6), puppetlabs/stdlib (>= 4.2.0)

Parameters

  • ipv6_enabled = false - true if IPv6 is needed
  • cbc_required = false - true if CBC for ciphers is required. This is usually only necessary, if older M2M mechanism need to communicate with SSH, that don't have any of the configured secure ciphers enabled. CBC is a weak alternative. Anything weaker should be avoided and is thus not available.
  • weak_hmac = false - true if weaker HMAC mechanisms are required. This is usually only necessary, if older M2M mechanism need to communicate with SSH, that don't have any of the configured secure HMACs enabled.
  • weak_kex = false - true if weaker Key-Exchange (KEX) mechanisms are required. This is usually only necessary, if older M2M mechanism need to communicate with SSH, that don't have any of the configured secure KEXs enabled.
  • allow_root_with_key = false - false to disable root login altogether. Set to true to allow root to login via key-based mechanism.
  • ports = [ 22 ] - ports to which ssh-server should listen to and ssh-client should connect to
  • listen_to = [ "0.0.0.0" ] - one or more ip addresses, to which ssh-server should listen to. Default is empty, but should be configured for security reasons!
  • remote_hosts - one or more hosts, to which ssh-client can connect to. Default is empty, but should be configured for security reasons!
  • allow_tcp_forwarding = false - set to true to allow TCP forwarding
  • allow_agent_forwarding = false - set to true to allow Agent forwarding
  • use_pam = false to disable pam authentication
  • client_options = {} - set values in the hash to override the module's settings
  • server_options = {} - set values in the hash to override the module's settings

Usage

After adding this module, you can use the class:

class { 'ssh_hardening': }

This will install ssh-server and ssh-client. You can alternatively choose only one via:

class { 'ssh_hardening::server': }
class { 'ssh_hardening::client': }

You should configure core attributes:

class { 'ssh_hardening::server':
  "listen_to" : ["10.2.3.4"]
}

The default value for listen_to is 0.0.0.0. It is highly recommended to change the value.

Overwriting default options

Default options will be merged with options passed in by the client_options and server_options parameters. If an option is set both as default and via options parameter, the latter will win.

The following example will enable X11Forwarding, which is disabled by default:

class { 'ssh_hardening':
  server_options => {
    'X11Forwarding' => 'yes',
  },
}

Local Testing

For local testing you can use vagrant and Virtualbox of VMWare to run tests locally. You will have to install Virtualbox and Vagrant on your system. See Vagrant Downloads for a vagrant package suitable for your system. For all our tests we use test-kitchen. If you are not familiar with test-kitchen please have a look at their guide.

Next install test-kitchen:

# Install dependencies
gem install bundler
bundle install

# Fetch tests
bundle exec thor kitchen:fetch-remote-tests

# Do lint checks
bundle exec rake lint

# Do spec checks
bundle exec rake spec

# fast test on one machine
bundle exec kitchen test default-ubuntu-1204

# test on Debian-based machines
bundle exec kitchen test

# for development
bundle exec kitchen create default-ubuntu-1204
bundle exec kitchen converge default-ubuntu-1204

For more information see test-kitchen

FAQ / Pitfalls

I can't log into my account. I have registered the client key, but it still doesn't let me it.

If you have exhausted all typical issues (firewall, network, key missing, wrong key, account disabled etc.), it may be that your account is locked. The quickest way to find out is to look at the password hash for your user:

sudo grep myuser /etc/shadow

If the hash includes an !, your account is locked:

myuser:!:16280:7:60:7:::

The proper way to solve this is to unlock the account (passwd -u myuser). If the user doesn't have a password, you should can unlock it via:

usermod -p "*" myuser

Alternatively, if you intend to use PAM, you enabled it via use_pam = true. PAM will allow locked users to get in with keys.

Why doesn't my application connect via SSH anymore?

Always look into log files first and if possible look at the negotiation between client and server that is completed when connecting.

We have seen some issues in applications (based on python and ruby) that are due to their use of an outdated crypto set. This collides with this hardening module, which reduced the list of ciphers, message authentication codes (MACs) and key exchange (KEX) algorithms to a more secure selection.

If you find this isn't enough, feel free to activate cbc_required for ciphers, weak_hmac for MACs, and weak_kex for KEX.

Contributors + Kudos

License and Author

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

puppet-ssh-hardening's People

Contributors

3flex avatar arlimus avatar artem-sidorenko avatar bernhardschmidt avatar chris-rock avatar ehaselwanter avatar kurthuwig avatar renovate[bot] avatar schurzi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppet-ssh-hardening's Issues

Algo selection should be based on SSH version, not OS release

The current approach to select Cipher/Kex/MAC based on the distribution name and the OS release is not very good. It does not account for

  • OS release's default version and running version getting out-of-sync (i.e. during dist-upgrade or when using backports)
  • OSes changing OpenSSH releases during a major release (i.e. the upcoming SLES 11SP4)
  • OSes or versions not known to the module

saz/ssh ships a facter plugin to retrieve the ssh server version. This should be a lot better.

# facter -p | grep ssh_server_version
ssh_server_version_full => 6.7p1
ssh_server_version_major => 6.7
ssh_server_version_release => 6.7

On RHEL 6 it sets KexAlgorithms with no options preventing ssh from starting

On RHEL 6 it sets KexAlgorithms with no options preventing ssh from starting

+++ /tmp/puppet-file20181025-29204-1l56lzq	2018-10-25 11:24:32.861843492 +0100
@@ -23,6 +23,7 @@
 KerberosAuthentication no
 KerberosOrLocalPasswd no
 KerberosTicketCleanup yes
+KexAlgorithms 
 LogLevel VERBOSE
 LoginGraceTime 30s
Error: /Stage[main]/Ssh::Server::Service/Service[sshd]: Failed to call refresh: Could not restart Service[sshd]: Execution of '/sbin/service sshd restart' returned 255: Stopping sshd: [  OK  ]
Starting sshd: /etc/ssh/sshd_config line 26: Missing argument.
[FAILED]
Error: /Stage[main]/Ssh::Server::Service/Service[sshd]: Could not restart Service[sshd]: Execution of '/sbin/service sshd restart' returned 255: Stopping sshd: [  OK  ]
Starting sshd: /etc/ssh/sshd_config line 26: Missing argument.
[FAILED]
Notice: /Stage[main]/Ssh::Server/Anchor[ssh::server::end]: Dependency Service[sshd] has failures: false
Warning: /Stage[main]/Ssh::Server/Anchor[ssh::server::end]: Skipping because of failed dependencies
Info: Stage[main]: Unscheduling all events on Stage[main]
Notice: Applied catalog in 3.72 seconds

Question: How to use hiera with this module

I'm trying to use the puppet-ssh-hardening module to provide a secure sshd_config to my servers. I'm using Hiera to manage my config.

When using saz-ssh I can add config in hiera as shown in the example:

ssh::server_options:
    Protocol: '2'
    ListenAddress:
        - '127.0.0.0'
        - '%{::hostname}'
    PasswordAuthentication: 'yes'
    SyslogFacility: 'AUTHPRIV'
    UsePAM: 'yes'
    X11Forwarding: 'yes'

When I try to do this using ssh-hardening it doesn't work, not when using include ssh_hardening, nor when using something like:

$ssh = lookup('ssh', Hash, 'hash')
  class { 'ssh_hardening':
    server_options => {
      * => $ssh[server_options],
  }```

How can I correctly make Hiera override default settings in this module?

Wrong detection of os version number on debian 8 (prerelease)

The puppet facter releases a os version number https://docs.puppetlabs.com/facter/2.3/core_facts.html#operatingsystemrelease, that we use in https://github.com/hardening-io/puppet-ssh-hardening/blob/master/lib/puppet/parser/functions/use_privilege_separation.rb#L19

This does not work as intended in debian 8 prerelease due to the fact that

$ cat /etc/debian_version
jessie/sid

does not return a number like on debian 7:

$ cat /etc/debian_version
7.7

Therefore the server config will include UsePrivilegeSeparation yes instead of the intended UsePrivilegeSeparation sandbox

UsePAM should probably default to yes on Red Hat Linux 7

From the sshd_config file on a CentOS 7 box:

# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several
# problems.

As such, it's probably a good idea to default UsePAM to true on RedHat 7.

This warning isn't in the CentOS 6 sshd_config file, but there is an article in the Red Hat 6 knowledgebase about not being able to SSH into a system if UsePAM is off and SELinux is on. I don't have an account and can't see the solution, though, so there might be a way to deal with that.

See also dev-sec/chef-ssh-hardening#96 and dev-sec/ansible-ssh-hardening#23.

Unable to use cbc_required in client config

I have some switches that I need to ssh into from a single server. Even with the latest firmware they dont support secure ssh cyphers so I wanted to allow weak cyphers/kex.

To do this I added -

class { 'ssh_hardening':
client_options => {
'cbc_required' => 'true',
'weak_hmac' => 'true',
'weak_kex' => 'true',
},
}

This did not put the weak cyphers in so I tried Hiera -

ssh_hardening::client::weak_kex: 'true'
ssh_hardening::client::weak_hmac: 'true'
ssh_hardening::client::cbc_required: 'true'

This also did not work so I tried forcing it from init.pp -

class { 'ssh_hardening::client':
ipv6_enabled => $ipv6_enabled,
ports => $ports,
#cbc_required => $cbc_required,
#weak_hmac => $weak_hmac,
#weak_kex => $weak_kex,
cbc_required => true,
weak_hmac => true,
weak_kex => true,
options => $client_options,
}

Which also didn't work and I am not good enough at debugging puppet, so I ended up editing get_ssh_kex.rb, get_ssh_macs.rb and get_ssh_ciphers.rb to force the cyphers.

ie. ciphers_53.default = 'aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc'

However, this is not optimal as now all my servers can ssh to insecure locations.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

bundler
Gemfile
  • rspec '~> 3.12.0'
  • rubocop '~> 1.0'
  • kitchen-sharedtests '~> 0.2.0'
github-actions
.github/workflows/codespell.yml

  • Check this box to trigger a request for Renovate to run again on this repository

SSH Config warnings with Artful Aardvark

Hi,

I get some warnings doing a git checkout via SSH when using this module under Artful Aardvark. I receive the following:
==> default: /etc/ssh/ssh_config line 22: Unsupported option "rsaauthentication"
==> default: /etc/ssh/ssh_config line 23: Unsupported option "rhostsrsaauthentication"

My understanding is that these options are no longer supported by newer versions of OpenSSH:
https://forum.gitlab.com/t/ssh-unsupported-option-rsaauthentication/11198

Thanks.

Imperfect Forward Secrecy: 1024-bit DH attack

Hi,
after reading about the recent DH attack I was wondering if we should change the default key exchange methods for this module. I know that we could still use DH using parameters of at least of 2048-bit but I'm worried that most of the sysadmins will not do it.

I also like the idea of this module that provide an hardened ssh config with a simple

include ::modulename

I don't think we should add: "...BUT in case you use DH kex methods this is not valid anymore if you use DH parameters < 2048bit"

Ref:
https://www.eff.org/deeplinks/2015/10/how-to-protect-yourself-from-nsa-attacks-1024-bit-DH
https://freedom-to-tinker.com/blog/haldermanheninger/how-is-nsa-breaking-so-much-crypto/
https://weakdh.org/imperfect-forward-secrecy-ccs15.pdf

doc: remote_hosts

remote_hosts is mentioned in the README, but is not present in the code

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.