diff --git a/ansible/README.md b/ansible/README.md index b504c3a..fef1054 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -4,8 +4,37 @@ Ansible playbooks, roles, modules, etc will come here. Documentation to come soo Each playbook should have comments or a name descripter that explains what the playbook does or how it is used. If not available, README-... files can be used in place. +## Management Node Structure + +Loosely copied from the CentOS ansible infrastructure. This structure is represented in this repository. + +``` +. +├── ansible.cfg +├── files -> playbooks/files +├── handlers -> playbooks/handlers +├── inventory +├── pkistore +├── playbooks +│ ├── files +│ ├── group_vars +│ ├── host_vars +│ ├── handlers +│ ├── tasks +│ ├── templates +│ ├── vars +│ └── requirements.yml +├── roles +│ ├── +├── tasks -> playbooks/tasks +├── templates -> playbooks/templates +└── vars -> playbooks/vars +``` + ## Structure +What each folder represents + ``` files -> As the name implies, non-templated files go here group_vars -> Group Variables go here if they are not fulfilled in an inventory @@ -15,7 +44,6 @@ roles -> Custom roles can go here tasks -> Common tasks come here templates -> Templates go here vars -> Global variables that are called with vars_files go here. This - is mainly for init and encpass.yml ``` ## Current Playbook Naming diff --git a/ansible/ansible.cfg b/ansible/ansible.cfg new file mode 100644 index 0000000..b7db254 --- /dev/null +++ b/ansible/ansible.cfg @@ -0,0 +1 @@ +# Empty diff --git a/ansible/files b/ansible/files new file mode 120000 index 0000000..e92b7a2 --- /dev/null +++ b/ansible/files @@ -0,0 +1 @@ +playbooks/files \ No newline at end of file diff --git a/ansible/handlers b/ansible/handlers new file mode 120000 index 0000000..1d3863c --- /dev/null +++ b/ansible/handlers @@ -0,0 +1 @@ +playbooks/handlers \ No newline at end of file diff --git a/ansible/adhoc-facts-refresh.yml b/ansible/playbooks/adhoc-facts-refresh.yml similarity index 100% rename from ansible/adhoc-facts-refresh.yml rename to ansible/playbooks/adhoc-facts-refresh.yml diff --git a/ansible/adhoc-ipagroups.yml b/ansible/playbooks/adhoc-ipagroups.yml similarity index 100% rename from ansible/adhoc-ipagroups.yml rename to ansible/playbooks/adhoc-ipagroups.yml diff --git a/ansible/adhoc-ipausers.yml b/ansible/playbooks/adhoc-ipausers.yml similarity index 100% rename from ansible/adhoc-ipausers.yml rename to ansible/playbooks/adhoc-ipausers.yml diff --git a/ansible/playbooks/handlers/handlers b/ansible/playbooks/handlers/handlers new file mode 120000 index 0000000..1d3863c --- /dev/null +++ b/ansible/playbooks/handlers/handlers @@ -0,0 +1 @@ +playbooks/handlers \ No newline at end of file diff --git a/ansible/handlers/main.yml b/ansible/playbooks/handlers/main.yml similarity index 100% rename from ansible/handlers/main.yml rename to ansible/playbooks/handlers/main.yml diff --git a/ansible/import-rockygroups.yml b/ansible/playbooks/import-rockygroups.yml similarity index 100% rename from ansible/import-rockygroups.yml rename to ansible/playbooks/import-rockygroups.yml diff --git a/ansible/import-rockysudo.yml b/ansible/playbooks/import-rockysudo.yml similarity index 100% rename from ansible/import-rockysudo.yml rename to ansible/playbooks/import-rockysudo.yml diff --git a/ansible/import-rockyusers.yml b/ansible/playbooks/import-rockyusers.yml similarity index 100% rename from ansible/import-rockyusers.yml rename to ansible/playbooks/import-rockyusers.yml diff --git a/ansible/init-rocky-install-kvm-hosts.yml b/ansible/playbooks/init-rocky-install-kvm-hosts.yml similarity index 100% rename from ansible/init-rocky-install-kvm-hosts.yml rename to ansible/playbooks/init-rocky-install-kvm-hosts.yml diff --git a/ansible/init-rocky-ipa-internal-dns.yml b/ansible/playbooks/init-rocky-ipa-internal-dns.yml similarity index 100% rename from ansible/init-rocky-ipa-internal-dns.yml rename to ansible/playbooks/init-rocky-ipa-internal-dns.yml diff --git a/ansible/init-rocky-ipa-team.yml b/ansible/playbooks/init-rocky-ipa-team.yml similarity index 100% rename from ansible/init-rocky-ipa-team.yml rename to ansible/playbooks/init-rocky-ipa-team.yml diff --git a/ansible/playbooks/init-rocky-system-config.yml b/ansible/playbooks/init-rocky-system-config.yml new file mode 100644 index 0000000..b652021 --- /dev/null +++ b/ansible/playbooks/init-rocky-system-config.yml @@ -0,0 +1,28 @@ +--- +# Basic system configuration. All hardening should also be imported here. +- name: Configure system + hosts: all + become: true + + pre_tasks: + - name: Check if ansible cannot be run here + stat: + path: /etc/no-ansible + register: no_ansible + + - name: Verify if we can run ansible + assert: + that: + - "not no_ansible.stat.exists" + msg: "/etc/no-ansible exists - skipping run on this node" + + tasks: + - name: Configure SSH + include: tasks/ssh-config.yml + + post_tasks: + - name: Touching run file that ansible has ran here + file: + path: /var/log/ansible.run + state: touch + diff --git a/ansible/requirements.yml b/ansible/playbooks/requirements.yml similarity index 100% rename from ansible/requirements.yml rename to ansible/playbooks/requirements.yml diff --git a/ansible/role-rocky-ipa-client.yml b/ansible/playbooks/role-rocky-ipa-client.yml similarity index 100% rename from ansible/role-rocky-ipa-client.yml rename to ansible/playbooks/role-rocky-ipa-client.yml diff --git a/ansible/role-rocky-ipa-replica.yml b/ansible/playbooks/role-rocky-ipa-replica.yml similarity index 97% rename from ansible/role-rocky-ipa-replica.yml rename to ansible/playbooks/role-rocky-ipa-replica.yml index d3e6954..45f58de 100644 --- a/ansible/role-rocky-ipa-replica.yml +++ b/ansible/playbooks/role-rocky-ipa-replica.yml @@ -36,7 +36,7 @@ - name: Ensure resolv.conf is pointing to main master template: - src: templates/resolv.conf.j2 + src: etc/resolv.conf.j2 dest: /etc/resolv.conf owner: root group: root diff --git a/ansible/role-rocky-ipa.yml b/ansible/playbooks/role-rocky-ipa.yml similarity index 100% rename from ansible/role-rocky-ipa.yml rename to ansible/playbooks/role-rocky-ipa.yml diff --git a/ansible/tasks/main.yml b/ansible/playbooks/tasks/main.yml similarity index 100% rename from ansible/tasks/main.yml rename to ansible/playbooks/tasks/main.yml diff --git a/ansible/playbooks/tasks/ssh-config.yml b/ansible/playbooks/tasks/ssh-config.yml new file mode 100644 index 0000000..53ae809 --- /dev/null +++ b/ansible/playbooks/tasks/ssh-config.yml @@ -0,0 +1,34 @@ +--- +- name: Ensure SSH is installed - it should be + package: + name: openssh-server + state: present + +- name: ssh configuration - global + block: + - name: ssh configuration - base + template: + src: "etc/ssh/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}-sshd_config.j2" + dest: /etc/ssh/sshd_config + owner: root + group: root + mode: '0600' + validate: /usr/sbin/sshd -t -f %s + backup: yes + notify: restart_ssh + + - name: ssh banner + copy: + src: "etc/banner" + dest: "{{ ssh_banner }}" + owner: root + group: root + notify: restart_ssh + + - name: Remove dsa keys + file: + path: "{{ item }}" + state: absent + with_items: + - /etc/ssh/ssh_host_dsa_key.pub + - /etc/ssh/ssh_host_dsa_key diff --git a/ansible/templates/resolv.conf b/ansible/playbooks/templates/etc/resolv.conf similarity index 100% rename from ansible/templates/resolv.conf rename to ansible/playbooks/templates/etc/resolv.conf diff --git a/ansible/playbooks/templates/etc/rockybanner b/ansible/playbooks/templates/etc/rockybanner new file mode 100644 index 0000000..a589aa8 --- /dev/null +++ b/ansible/playbooks/templates/etc/rockybanner @@ -0,0 +1,11 @@ + ******* ** +/**////** /** ** ** +/** /** ****** ***** /** ** //** ** +/******* **////** **///**/** ** //*** +/**///** /** /**/** // /**** /** +/** //** /** /**/** **/**/** ** +/** //**//****** //***** /**//** ** +// // ////// ///// // // // + +All access is logged and monitors. Unauthorized access is prohibited. + diff --git a/ansible/playbooks/templates/etc/ssh/CentOS-7-sshd_config.j2 b/ansible/playbooks/templates/etc/ssh/CentOS-7-sshd_config.j2 new file mode 120000 index 0000000..1e7292c --- /dev/null +++ b/ansible/playbooks/templates/etc/ssh/CentOS-7-sshd_config.j2 @@ -0,0 +1 @@ +RedHat-7-sshd_config.j2 \ No newline at end of file diff --git a/ansible/playbooks/templates/etc/ssh/CentOS-8-sshd_config.j2 b/ansible/playbooks/templates/etc/ssh/CentOS-8-sshd_config.j2 new file mode 120000 index 0000000..33d30c5 --- /dev/null +++ b/ansible/playbooks/templates/etc/ssh/CentOS-8-sshd_config.j2 @@ -0,0 +1 @@ +RedHat-8-sshd_config.j2 \ No newline at end of file diff --git a/ansible/playbooks/templates/etc/ssh/RedHat-7-sshd_config.j2 b/ansible/playbooks/templates/etc/ssh/RedHat-7-sshd_config.j2 new file mode 100644 index 0000000..54e8fc4 --- /dev/null +++ b/ansible/playbooks/templates/etc/ssh/RedHat-7-sshd_config.j2 @@ -0,0 +1,156 @@ +# $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $ + +# This is the sshd server system-wide configuration file. See +# sshd_config(5) for more information. + +# This sshd was compiled with PATH=/usr/local/bin:/usr/bin + +# 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. + +# If you want to change the port on a SELinux system, you have to tell +# SELinux about this change. +# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER +# +#Port 22 +#AddressFamily any +#ListenAddress 0.0.0.0 +#ListenAddress :: + +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 + +# Ciphers and keying +#RekeyLimit default none + +# Logging +#SyslogFacility AUTH +SyslogFacility AUTHPRIV +#LogLevel INFO + +# Authentication: + +#LoginGraceTime 2m +#PermitRootLogin yes +#StrictModes yes +#MaxAuthTries 6 +#MaxSessions 10 + +#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 +#HostbasedAuthentication no +# Change to yes if you don't trust ~/.ssh/known_hosts for +# 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 +PasswordAuthentication yes + +# Change to no to disable s/key passwords +#ChallengeResponseAuthentication yes +#ChallengeResponseAuthentication no + +# Kerberos options +#KerberosAuthentication no +#KerberosOrLocalPasswd yes +#KerberosTicketCleanup yes +#KerberosGetAFSToken no +#KerberosUseKuserok yes + +# GSSAPI options +GSSAPIAuthentication yes +GSSAPICleanupCredentials no +#GSSAPIStrictAcceptorCheck yes +#GSSAPIKeyExchange no +#GSSAPIEnablek5users no + +# 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'. +# WARNING: 'UsePAM no' is not supported in Red Hat Enterprise Linux and may cause several +# problems. +UsePAM yes + +#AllowAgentForwarding yes +#AllowTcpForwarding yes +#GatewayPorts no +#X11Forwarding yes +#X11DisplayOffset 10 +#X11UseLocalhost yes +#PermitTTY yes +#PrintMotd yes +#PrintLastLog yes +#TCPKeepAlive yes +#UseLogin no +#UsePrivilegeSeparation sandbox +#PermitUserEnvironment no +#Compression delayed +#ClientAliveInterval 0 +#ClientAliveCountMax 3 +#ShowPatchLevel no +#UseDNS yes +#PidFile /var/run/sshd.pid +#MaxStartups 10:30:100 +#PermitTunnel no +#ChrootDirectory none +#VersionAddendum none + +# no default banner path +#Banner none + +# Accept locale-related environment variables +AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES +AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT +AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE +AcceptEnv XMODIFIERS + +# override default of no subsystems +Subsystem sftp /usr/libexec/openssh/sftp-server + +# Example of overriding settings on a per-user basis +#Match User anoncvs +# X11Forwarding no +# AllowTcpForwarding no +# PermitTTY no +# ForceCommand cvs server + +################################################################################ +# Below managed by {{ ansible_managed }} +# +Banner /etc/rockybanner +PermitRootLogin no +X11Forwarding no +LoginGraceTime 1m + +# FIPS Compliant (old) +MACs hmac-sha2-512,hmac-sha2-256 +Ciphers aes256-ctr,aes192-ctr,aes128-ctr + +# IPA +AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys +AuthorizedKeysCommandUser nobody +ChallengeResponseAuthentication yes diff --git a/ansible/playbooks/templates/etc/ssh/RedHat-8-sshd_config.j2 b/ansible/playbooks/templates/etc/ssh/RedHat-8-sshd_config.j2 new file mode 100644 index 0000000..be831c9 --- /dev/null +++ b/ansible/playbooks/templates/etc/ssh/RedHat-8-sshd_config.j2 @@ -0,0 +1,168 @@ +# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $ + +# This is the sshd server system-wide configuration file. See +# sshd_config(5) for more information. + +# This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/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. + +# If you want to change the port on a SELinux system, you have to tell +# SELinux about this change. +# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER +# +#Port 22 +#AddressFamily any +#ListenAddress 0.0.0.0 +#ListenAddress :: + +HostKey /etc/ssh/ssh_host_rsa_key +HostKey /etc/ssh/ssh_host_ecdsa_key +HostKey /etc/ssh/ssh_host_ed25519_key + +# Ciphers and keying +#RekeyLimit default none + +# System-wide Crypto policy: +# This system is following system-wide crypto policy. The changes to +# Ciphers, MACs, KexAlgoritms and GSSAPIKexAlgorithsm will not have any +# effect here. They will be overridden by command-line options passed on +# the server start up. +# To opt out, uncomment a line with redefinition of CRYPTO_POLICY= +# variable in /etc/sysconfig/sshd to overwrite the policy. +# For more information, see manual page for update-crypto-policies(8). + +# Logging +#SyslogFacility AUTH +SyslogFacility AUTHPRIV +#LogLevel INFO + +# Authentication: + +#LoginGraceTime 2m +#PermitRootLogin yes +#StrictModes yes +#MaxAuthTries 6 +#MaxSessions 10 + +#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 +#HostbasedAuthentication no +# Change to yes if you don't trust ~/.ssh/known_hosts for +# 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 +PasswordAuthentication yes + +# Change to no to disable s/key passwords +#ChallengeResponseAuthentication yes +#ChallengeResponseAuthentication no + +# Kerberos options +#KerberosAuthentication no +#KerberosOrLocalPasswd yes +#KerberosTicketCleanup yes +#KerberosGetAFSToken no +#KerberosUseKuserok yes + +# GSSAPI options +GSSAPIAuthentication yes +GSSAPICleanupCredentials no +#GSSAPIStrictAcceptorCheck yes +#GSSAPIKeyExchange no +#GSSAPIEnablek5users no + +# 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'. +# WARNING: 'UsePAM no' is not supported in Fedora and may cause several +# problems. +UsePAM yes + +#AllowAgentForwarding yes +#AllowTcpForwarding yes +#GatewayPorts no +X11Forwarding yes +#X11DisplayOffset 10 +#X11UseLocalhost yes +#PermitTTY yes + +# It is recommended to use pam_motd in /etc/pam.d/sshd instead of PrintMotd, +# as it is more configurable and versatile than the built-in version. +PrintMotd no + +#PrintLastLog yes +#TCPKeepAlive yes +#PermitUserEnvironment no +#Compression delayed +#ClientAliveInterval 0 +#ClientAliveCountMax 3 +#ShowPatchLevel no +#UseDNS no +#PidFile /var/run/sshd.pid +#MaxStartups 10:30:100 +#PermitTunnel no +#ChrootDirectory none +#VersionAddendum none + +# no default banner path +#Banner none + +# Accept locale-related environment variables +AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES +AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT +AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE +AcceptEnv XMODIFIERS + +# override default of no subsystems +Subsystem sftp /usr/libexec/openssh/sftp-server + +# Example of overriding settings on a per-user basis +#Match User anoncvs +# X11Forwarding no +# AllowTcpForwarding no +# PermitTTY no +# ForceCommand cvs server + +################################################################################ +# Below managed by {{ ansible_managed }} +# +Banner /etc/rockybanner +PermitRootLogin no +X11Forwarding no +LoginGraceTime 1m + +# FIPS Compliant +# This has no effect in RHEL 8 or Fedora. However, in the case of compliance +# higher than that of PCI, it may be a good idea to override it. +MACs hmac-sha2-512,hmac-sha2-256 +Ciphers aes256-ctr,aes192-ctr,aes128-ctr + +# IPA +AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys +AuthorizedKeysCommandUser nobody +ChallengeResponseAuthentication yes diff --git a/ansible/vars/encpass.yml b/ansible/playbooks/vars/encpass.yml similarity index 100% rename from ansible/vars/encpass.yml rename to ansible/playbooks/vars/encpass.yml diff --git a/ansible/vars/groups.yml b/ansible/playbooks/vars/groups.yml similarity index 100% rename from ansible/vars/groups.yml rename to ansible/playbooks/vars/groups.yml diff --git a/ansible/vars/sudorules.yml b/ansible/playbooks/vars/sudorules.yml similarity index 100% rename from ansible/vars/sudorules.yml rename to ansible/playbooks/vars/sudorules.yml diff --git a/ansible/vars/users.yml b/ansible/playbooks/vars/users.yml similarity index 100% rename from ansible/vars/users.yml rename to ansible/playbooks/vars/users.yml diff --git a/ansible/tasks b/ansible/tasks new file mode 120000 index 0000000..bcc0c4f --- /dev/null +++ b/ansible/tasks @@ -0,0 +1 @@ +playbooks/tasks \ No newline at end of file diff --git a/ansible/templates b/ansible/templates new file mode 120000 index 0000000..cf86767 --- /dev/null +++ b/ansible/templates @@ -0,0 +1 @@ +playbooks/templates \ No newline at end of file diff --git a/ansible/vars b/ansible/vars new file mode 120000 index 0000000..b01af0b --- /dev/null +++ b/ansible/vars @@ -0,0 +1 @@ +playbooks/vars \ No newline at end of file