From 58c73e91ff3fb7f15d1e87fb87fd88d066c8b309 Mon Sep 17 00:00:00 2001 From: Beth Parker Date: Wed, 20 Sep 2017 11:20:02 -0500 Subject: [PATCH] Added sshserver state --- pillars/roles/firewalld/sshserver.sls | 4 + pillars/servers/roles/server/archssh.sls | 2 +- states/roles/maintain/mysql/init.sls | 1 + states/roles/maintain/sshserver/init.sls | 35 ++++++ states/roles/maintain/sshserver/sshd_config | 132 ++++++++++++++++++++ 5 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 pillars/roles/firewalld/sshserver.sls create mode 100644 states/roles/maintain/sshserver/init.sls create mode 100644 states/roles/maintain/sshserver/sshd_config diff --git a/pillars/roles/firewalld/sshserver.sls b/pillars/roles/firewalld/sshserver.sls new file mode 100644 index 0000000..72c62ac --- /dev/null +++ b/pillars/roles/firewalld/sshserver.sls @@ -0,0 +1,4 @@ +firewalld: + 99_public: + service: + - ssh diff --git a/pillars/servers/roles/server/archssh.sls b/pillars/servers/roles/server/archssh.sls index b4b9cf7..0c8bb7c 100644 --- a/pillars/servers/roles/server/archssh.sls +++ b/pillars/servers/roles/server/archssh.sls @@ -3,4 +3,4 @@ grains: - server - ssh - saltminion - - sshin + - sshserver diff --git a/states/roles/maintain/mysql/init.sls b/states/roles/maintain/mysql/init.sls index 327fc53..bdb3398 100644 --- a/states/roles/maintain/mysql/init.sls +++ b/states/roles/maintain/mysql/init.sls @@ -20,6 +20,7 @@ mysql-service: set_root: mysql_query.run: - database: mysql + - query: "UPDATE mysql.user SET Password=PASSWORD('{%- include 'secure/passwords/root_db_password.txt' -%}') WHERE User='root';" - query: "UPDATE mysql.user SET Password=PASSWORD('{%- include 'secure/passwords/root_db_password.txt' -%}') WHERE User='root';FLUSH PRIVILEGES;" - onchanges: - cmd: initialize_mysql diff --git a/states/roles/maintain/sshserver/init.sls b/states/roles/maintain/sshserver/init.sls new file mode 100644 index 0000000..aa9495a --- /dev/null +++ b/states/roles/maintain/sshserver/init.sls @@ -0,0 +1,35 @@ +ssh-server-pkg: + pkg.installed: + - name: openssh + +ssh-group: + group.present: + - name: ssh + - gid: 1500 + +ssh-user: + user.present: + - name: ssh + - shell: /bin/bash + - home: /home/ssh + - uid: 1500 + - gid: 1500 + - password: "{%- include 'secure/passwords/ssh_user_password.txt' -%}" + - hash_password: true + - groups: + - ssh + +ssh-server-config: + file.managed: + - name: /etc/ssh/sshd_config + - source: salt://roles/maintain/sshserver/sshd_config + - user: root + - group: root + - mode: 644 + +ssh-server-service: + service.running: + - name: sshd + - enabled: true + - watch: + - file: ssh-server-config diff --git a/states/roles/maintain/sshserver/sshd_config b/states/roles/maintain/sshserver/sshd_config new file mode 100644 index 0000000..5fb2b3d --- /dev/null +++ b/states/roles/maintain/sshserver/sshd_config @@ -0,0 +1,132 @@ +# $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $ + +# This is the sshd server system-wide configuration file. See +# sshd_config(5) for more information. + +# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin + +# The strategy used for options in the default sshd_config shipped with +# OpenSSH is to specify options with their default value where +# possible, but leave them commented. Uncommented options override the +# default value. + +#Port 22 +#AddressFamily any +#ListenAddress 0.0.0.0 +#ListenAddress :: + +# The default requires explicit activation of protocol 1 +#Protocol 2 + +# HostKey for protocol version 1 +#HostKey /etc/ssh/ssh_host_key +# HostKeys for protocol version 2 +#HostKey /etc/ssh/ssh_host_rsa_key +#HostKey /etc/ssh/ssh_host_dsa_key +#HostKey /etc/ssh/ssh_host_ecdsa_key +#HostKey /etc/ssh/ssh_host_ed25519_key + +# Lifetime and size of ephemeral version 1 server key +#KeyRegenerationInterval 1h +#ServerKeyBits 1024 + +# Ciphers and keying +#RekeyLimit default none + +# Logging +# obsoletes QuietMode and FascistLogging +#SyslogFacility AUTH +#LogLevel INFO + +# Authentication: + +#LoginGraceTime 2m +#PermitRootLogin yes +#StrictModes yes +#MaxAuthTries 6 +#MaxSessions 10 + +#RSAAuthentication yes +#PubkeyAuthentication yes + +# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 +# but this is overridden so installations will only check .ssh/authorized_keys +AuthorizedKeysFile .ssh/authorized_keys + +#AuthorizedPrincipalsFile none + +#AuthorizedKeysCommand none +#AuthorizedKeysCommandUser nobody + +# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts +#RhostsRSAAuthentication no +# similar for protocol version 2 +#HostbasedAuthentication no +# Change to yes if you don't trust ~/.ssh/known_hosts for +# RhostsRSAAuthentication and HostbasedAuthentication +#IgnoreUserKnownHosts no +# Don't read the user's ~/.rhosts and ~/.shosts files +#IgnoreRhosts yes + +# To disable tunneled clear text passwords, change to no here! +#PasswordAuthentication yes +#PermitEmptyPasswords no + +# Change to no to disable s/key passwords +ChallengeResponseAuthentication no + +# Kerberos options +#KerberosAuthentication no +#KerberosOrLocalPasswd yes +#KerberosTicketCleanup yes +#KerberosGetAFSToken no + +# GSSAPI options +#GSSAPIAuthentication no +#GSSAPICleanupCredentials yes + +# Set this to 'yes' to enable PAM authentication, account processing, +# and session processing. If this is enabled, PAM authentication will +# be allowed through the ChallengeResponseAuthentication and +# PasswordAuthentication. Depending on your PAM configuration, +# PAM authentication via ChallengeResponseAuthentication may bypass +# the setting of "PermitRootLogin without-password". +# If you just want the PAM account and session checks to run without +# PAM authentication, then enable this but set PasswordAuthentication +# and ChallengeResponseAuthentication to 'no'. +UsePAM yes + +#AllowAgentForwarding yes +#AllowTcpForwarding yes +#GatewayPorts no +#X11Forwarding no +#X11DisplayOffset 10 +#X11UseLocalhost yes +#PermitTTY yes +PrintMotd no # pam does that +#PrintLastLog yes +#TCPKeepAlive yes +#UseLogin no +UsePrivilegeSeparation sandbox # Default for new installations. +#PermitUserEnvironment no +#Compression delayed +#ClientAliveInterval 0 +#ClientAliveCountMax 3 +#UseDNS yes +#PidFile /run/sshd.pid +#MaxStartups 10:30:100 +#PermitTunnel no +#ChrootDirectory none +#VersionAddendum none + +# no default banner path +#Banner none + +# override default of no subsystems +Subsystem sftp /usr/lib/ssh/sftp-server + +# Example of overriding settings on a per-user basis + +PasswordAuthentication no +Match Group ssh + PasswordAuthentication yes