Przeglądaj źródła

ssh keys deploy for users: set public keys, upload secret keys

sys-systemd-and-upstart
Vladimir Smagin 11 miesięcy temu
rodzic
commit
e803525173
Podpisane przez: Vladimir Smagin <21h@blindage.org> ID klucza GPG: 29AE91B1A37721C3

+ 3
- 0
keys-ansible/ansible.cfg Wyświetl plik

@@ -0,0 +1,3 @@
[defaults]
log_path=ansible.log
nocows = 1

+ 7
- 0
keys-ansible/group_vars/hetzner-balancers.yml Wyświetl plik

@@ -0,0 +1,7 @@
access_list:
- { keypath: "../keys/admin.pub", username: "root" }
- { keypath: "../keys/techguy.pub", username: "root" }
- { keypath: "../keys/interserver.pub", username: "root" }

secret_list:
- { keypath: "../keys/interserver.pem", username: "root" }

+ 8
- 0
keys-ansible/group_vars/hetzner-nodes.yml Wyświetl plik

@@ -0,0 +1,8 @@
access_list:
- { keypath: "../keys/interserver.pub", username: "root" }
- { keypath: "../keys/admin.pub", username: "root" }
- { keypath: "../keys/project-git.pub", username: "root" }
- { keypath: "../keys/developer1.pub", username: "root" }
- { keypath: "../keys/developer2.pub", username: "root" }

secret_list:

+ 4
- 0
keys-ansible/group_vars/hetzner.yml Wyświetl plik

@@ -0,0 +1,4 @@
access_list:
- { keypath: "../keys/admin.pub", username: "root" }
- { keypath: "../keys/techguy.pub", username: "root" }
secret_list:

+ 8
- 0
keys-ansible/group_vars/monitoring.yml Wyświetl plik

@@ -0,0 +1,8 @@
access_list:
- { keypath: "../keys/admin.pub", username: "root" }
- { keypath: "../keys/techguy.pub", username: "root" }
- { keypath: "../keys/interserver.pub", username: "root" }

secret_list:
- { keypath: "../keys/interserver.pem", username: "root" }


+ 15
- 0
keys-ansible/inventory.ini Wyświetl plik

@@ -0,0 +1,15 @@
[monitoring]
monitor ansible_host=44.165.225.144 ansible_user=root ansible_ssh_private_key_file="secrets/superkey.pem"

[hetzner:children]
hetzner-balancers
hetzner-nodes

[hetzner-nodes]
hetzner-node0 ansible_host=145.251.216.112 ansible_user=root ansible_ssh_private_key_file="secrets/superkey.pem"
hetzner-node1 ansible_host=154.64.4.185 ansible_user=root ansible_ssh_private_key_file="secrets/superkey.pem"
hetzner-node2 ansible_host=168.251.172.244 ansible_user=root ansible_ssh_private_key_file="secrets/superkey.pem"

[hetzner-balancers]
hetzner-balancer0 ansible_host=145.251.216.154 ansible_user=root ansible_ssh_private_key_file="secrets/superkey.pem"
hetzner-balancer1 ansible_host=78.46.246.78 ansible_user=root ansible_ssh_private_key_file="secrets/superkey.pem"

+ 1
- 0
keys-ansible/roles/master_key/meta/main.yml Wyświetl plik

@@ -0,0 +1 @@
allow_duplicates: true

+ 7
- 0
keys-ansible/roles/master_key/tasks/main.yml Wyświetl plik

@@ -0,0 +1,7 @@
---
- name: Set administrative keys and delete others
authorized_key:
user: root
state: present
exclusive: True
key: "{{ lookup('file', 'secrets/superkey.pub') }}"

+ 1
- 0
keys-ansible/roles/preinstall/meta/main.yml Wyświetl plik

@@ -0,0 +1 @@
allow_duplicates: true

+ 18
- 0
keys-ansible/roles/preinstall/tasks/main.yml Wyświetl plik

@@ -0,0 +1,18 @@
---
- name: Minimum packages for Debian-like
apt: name="{{ item }}" state=present update_cache=yes
become: yes
with_items:
- mc
- htop
when: (ansible_distribution == 'Ubuntu' or ansible_distribution == 'Debian') and preinstall is defined

- name: Minimum packages for RedHat-like
become: yes
yum: name="{{ item }}" state=present update_cache=yes
with_items:
- mc
- htop
when: (ansible_distribution == 'Red Hat' or ansible_distribution == 'Centos') and preinstall is defined



+ 1
- 0
keys-ansible/roles/ssh_access/meta/main.yml Wyświetl plik

@@ -0,0 +1 @@
allow_duplicates: true

+ 21
- 0
keys-ansible/roles/ssh_access/tasks/main.yml Wyświetl plik

@@ -0,0 +1,21 @@
---
#- debug:
# msg: "{{ access_list }}"
- name: Set authorized keys
become: true
become_user: "{{ item.username }}"
authorized_key: user="{{ item.username }}" key="{{ lookup('file', item.keypath) }}" state=present
with_items: "{{ access_list }}"
when: access_list != None and access_list is defined

#- debug:
# msg: "{{ secret_list }}"

- name: Upload secret keys
become: true
become_user: "{{ item.username }}"
copy: src="{{ item.keypath }}" dest="~/.ssh/{{ item.keypath | basename }}" mode=0600
with_items: "{{ secret_list }}"
when: secret_list != None and secret_list is defined


+ 27
- 0
keys-ansible/secrets/superkey.key Wyświetl plik

@@ -0,0 +1,27 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAwNv29GRDfroj6Ue5iPsj/E5nX7QWRPzfHIj8pMms3+YY/rt6
em077AXFGQITr874Y5tnjS7joO1LnOU71D/Yy80ty4kqL56U20OBGLrFxv/swJgf
QweSv9nFkj+sEONqu/kM7Ailu4sOkcAzH/aA8tLVpAyC5xf+wYhtX3twUkbSPgpG
N6hV/TaNMt27moWwOMui0Hm6EYriPYBD7c7wHwgLwkksq+SLLHDqJqiWrBSRnwCv
KBAIpMyqwhjLICk7LyuAZdXF+LdJXssXLnnpwl1HspkRt/QhbznRqyLqdD6pfVRv
yRalZxK7xv8akYlCzzWgCHGbw98KexUBLcw8oQIDAQABAoIBAFcjS7pyjth0bANc
B+Vva3v1RNnF+YXkJz6yWkxuXvCu+z4lIRqtvjRPCxXYjWKTBkGjFq+ArxKoBND3
9gdZba/vnbBn4iqv4RwMrQiqYvAd9C+0y/MyOcj7MTx6Dll3F2OlDISdB5zsIIIU
MEVR0ENmpWbAzGhzvARfiuNoV4CkfCMk8+1l5m0eLuFih74IW3Ka62tUx6DUIl9/
KTsgFqsGY7if6RomEWJssoDWYhfVpy2PyIR9Rvs3sTSKXKlHAZIewTbiwsjsknjw
8x6eJpi6KogZ2jsgmjOzAUkyAjFm5+Su7l0H58nJk6V0b4eskXGZD4nzzmUSmjEw
L1MmW90CgYEA59RpCp3t0MGX5IPkKezaCXC6uvP1cUPKIcz9MrYDDzX4mWUIiKza
hyPPllmV75sUk11/bMcwOlYiRlpwCRq6Wh5BV3D34/YSNF7gOyUkNrEWt04UAlSD
pwEP8RMv+GXhPGfWJrhuF3zTYoWy8347LKuKgkLxDgWYwvYaJT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l1cX4t0leyxcueenCXUeymRG39CFvOdGrIup0Pql9VG/JFqVnErvG/xqRiULPNaAIcZvD3wp7FQEtzDyh demo key. do not use it!

+ 3
- 0
keys-ansible/ssh-keys.sh Wyświetl plik

@@ -0,0 +1,3 @@
#!/bin/bash

ansible-playbook ssh-keys.yml -i inventory.ini

+ 7
- 0
keys-ansible/ssh-keys.yml Wyświetl plik

@@ -0,0 +1,7 @@
---
- hosts: all
gather_facts: True
roles:
- master_key
- preinstall
- ssh_access

Ładowanie…
Anuluj
Zapisz