This commit is contained in:
GROUPE 6 2023-05-23 03:47:37 +02:00
parent 860c225880
commit ff95d9308d
13 changed files with 272 additions and 1 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.swp

View File

@ -2,6 +2,9 @@
root_password_hashed: "{{ vault_root_password_hashed }}" root_password_hashed: "{{ vault_root_password_hashed }}"
user_password_hashed: "{{ vault_user_password_hashed }}" user_password_hashed: "{{ vault_user_password_hashed }}"
maverik_password_hashed: "{{ vault_user_password_hashed }}"
charlie_password_hashed: "{{ vault_user_password_hashed }}"
goose_password_hashed: "{{ vault_user_password_hashed }}"
user_ssh_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDl05rLhOKK4M2pqp7xRbKzIYlnkLRvp61NLrP2E0fiU l01@L01" user_ssh_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDl05rLhOKK4M2pqp7xRbKzIYlnkLRvp61NLrP2E0fiU l01@L01"
ansible_become_password: "toto" #FIXME ansible_become_password: "toto" #FIXME

0
playbooks/ssh.yml Normal file
View File

View File

@ -1,6 +1,6 @@
Listen 8000 Listen 8000
<VirtualHost *:8000> <VirtualHost localhost:8000>
DocumentRoot /usr/share/wordpress DocumentRoot /usr/share/wordpress
Alias /wp-content /var/lib/wordpress/wp-content Alias /wp-content /var/lib/wordpress/wp-content

View File

@ -0,0 +1,33 @@
---
users:
- name: maverik
groups:
- TOPGUN
- sudo
config: "maverik ALL = (maverik) /usr/sbin/reboot,/usr/bin/apt"
- name: charlie
groups:
- TOPGUN
- sudo
config: |
Defaults:charlie timestamp_timeout=15
charlie ALL=(ALL:ALL) ALL
- name: goose
groups:
- TOPGUN
config: ""
ssh_config:
- option: Port
value: 22
- option: ListenAddress
value: "0.0.0.0"
- option: PermitRootLogin
value: no
- option: LogLevel
value: VERBOSE
- option: ChallengeResponseAuthentication
value: yes
- option: UsePAM
value: yes

26
roles/ssh/files/sudoers Normal file
View File

@ -0,0 +1,26 @@
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# group privilege specification
# See sudoers(5) for more information on "@include" directives:
@includedir /etc/sudoers.d

16
roles/ssh/tasks/main.yml Normal file
View File

@ -0,0 +1,16 @@
---
- name: Users
remote_user: ansible
become: True
ansible.builtin.import_tasks: users.yml
- name: Users permissions
remote_user: ansible
become: True
ansible.builtin.import_tasks: permissions.yml
- name: SSH config
remote_user: ansible
become: True
ansible.builtin.import_tasks: ssh.yml

View File

@ -0,0 +1,19 @@
---
- name: Default sudo config
ansible.builtin.copy:
src: sudoers
dest: /etc/sudoers.conf
owner: root
group: root
mode: '0440'
- name: Permissions for user "{{ user.name }}"
ansible.builtin.lineinfile:
path: /etc/sudoers
state: present
insertafter: "^# User privilege specification$"
line: "{{ user.config }}"
loop: "{{ users }}"
loop_control:
loop_var: user

8
roles/ssh/tasks/ssh.yml Normal file
View File

@ -0,0 +1,8 @@
---
- name: SSHD configuration
ansible.builtin.linefile:
path: "/etc/ssh/sshd_config"
regex: "^(# *)?{{ item.option }}"
line: "{{ item.option }} {{ item.value }}"
loop: "{{ ssh_config }}"

39
roles/ssh/tasks/users.yml Normal file
View File

@ -0,0 +1,39 @@
---
- name: Add TOPGUN group
ansible.builtin.group:
name: TOPGUN
state: present
- name: Add maverik account
ansible.builtin.user:
name: maverik
state: present
shell: /bin/bash
groups:
- TOPGUN
- sudo
append: yes
password: "{{ maverik_password_hashed }}"
- name: Add charlie account
ansible.builtin.user:
name: charlie
state: present
shell: /bin/bash
groups:
- TOPGUN
- sudo
append: yes
password: "{{ charlie_password_hashed }}"
- name: Add goose account
ansible.builtin.user:
name: goose
state: present
shell: /bin/bash
groups:
- TOPGUN
- sudo
append: yes
password: "{{ goose_password_hashed }}"

View File

@ -325,3 +325,6 @@ if __name__ == "__main__":
elif parsed_arguments.host: elif parsed_arguments.host:
LOGGER.debug("host flag found") LOGGER.debug("host flag found")
print(json.dumps(dict())) print(json.dumps(dict()))
else:
LOGGER.debug("no flag found, listing")
print(json.dumps(list_all_hosts()))

123
sshd_config Normal file
View File

@ -0,0 +1,123 @@
# $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/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.
Include /etc/ssh/sshd_config.d/*.conf
#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
# Logging
SyslogFacility AUTH
LogLevel DEBUG3
# Authentication:
#LoginGraceTime 2m
PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#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 yes
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange 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'.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem sftp /usr/lib/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server