Here we go.
This simple ansible playbook, made quick you can adjust as needed, can probably get you started, you should not focus only on users, consider as well cidr_list, in regards to roles try to think of them as tiering 0, 1 , 2 “to reduce the blast radius in an event of a compromise”, and make your plan accordingly, so any users in role 0 should not and must not access role 1 & 2 and vice versa as an example, not using otp role myself, using signed cert, for windows smartcard with Yubikey or yubkey - duo, with little imagination you can map users, allowed_users and cidr_list variables with jinja templating or powershell somehow.
One last thing it will be much manageable if you assign the policies by ldap groups instead of users. Hope this help.
- name: "Vault_OTP"
hosts: localhost
become: true
vars_files:
- vault_otp.yml
tasks:
- name: Enable Vault OTP ssh
ansible.builtin.shell: vault secrets enable ssh
environment:
VAULT_ADDR: "{{VAULT_ADDR}}"
VAULT_CACERT: "{{VAULT_CACERT}}"
VAULT_CLIENT_CERT: "{{VAULT_CLIENT_CERT}}"
VAULT_CLIENT_KEY: "{{VAULT_CLIENT_KEY}}"
VAULT_TOKEN: "{{VAULT_TOKEN}}"
register: vault_ssh_enabled
changed_when: false
ignore_errors: true
- name: Vault OTP ssh users
ansible.builtin.shell: vault write ssh/roles/"{{item.role}}" key_type=otp default_user="{{item.default_user}}" cidr_list="{{item.cidr_list}}" allowed_users="{{item.allowed_users}}"
environment:
VAULT_ADDR: "{{VAULT_ADDR}}"
VAULT_CACERT: "{{VAULT_CACERT}}"
VAULT_CLIENT_CERT: "{{VAULT_CLIENT_CERT}}"
VAULT_CLIENT_KEY: "{{VAULT_CLIENT_KEY}}"
VAULT_TOKEN: "{{VAULT_TOKEN}}"
changed_when: false
delegate_to: localhost
with_items: "{{ssh_otp_users}}"
when: vault_ssh_enabled.rc == 0
Variables
VAULT_ADDR: "https://active.vault.service-consul:8200"
VAULT_CACERT: "/etc/ansible/consul-agent-ca.pem"
VAULT_CLIENT_CERT: "/etc/ansible/cli--consul-0.pem"
VAULT_CLIENT_KEY: "/etc/ansible/cli-consul-0-key.pem"
VAULT_TOKEN: "xxxxxx"
ssh_otp_users:
- { role: 'siamert', default_user: 'siamert', cidr_list: '192.168.1.20/24', allowed_users: 'siamert, bob'}
- { role: 'siamert1', default_user: 'siamert', cidr_list: '192.168.1.21/24, 192.168.1.23/24', allowed_users: 'siamert1'}
- { role: 'siamert2', default_user: 'siamert', cidr_list: '192.168.1.22/24', allowed_users: 'siamert2'}
- { role: 'siamert3', default_user: 'siamert', cidr_list: '192.168.1.23/24', allowed_users: 'siamert3'}
- { role: 'siamert4', default_user: 'siamert', cidr_list: '192.168.1.24/24', allowed_users: 'siamert4'}
- { role: 'siamert5', default_user: 'siamert', cidr_list: '192.168.1.25/24', allowed_users: 'siamert5'}
- { role: 'siamert6', default_user: 'siamert', cidr_list: '192.168.1.26/24', allowed_users: 'siamert6'}
- { role: 'siamert7', default_user: 'siamert', cidr_list: '192.168.1.27/24', allowed_users: 'siamert7'}
- { role: 'siamert8', default_user: 'siamert', cidr_list: '192.168.1.28/24', allowed_users: 'siamert8'}
- { role: 'siamert9', default_user: 'siamert', cidr_list: '192.168.1.29/24', allowed_users: 'siamert9'}
- { role: 'siamert10', default_user: 'siamert', cidr_list: '192.168.1.30/24', allowed_users: 'siamert10'}
- { role: 'siamert11', default_user: 'siamert', cidr_list: '192.168.1.31/24', allowed_users: 'siamert11'}
- { role: 'siamert12', default_user: 'siamert', cidr_list: '192.168.1.32/24', allowed_users: 'siamert12'}
- { role: 'siamert13', default_user: 'siamert', cidr_list: '192.168.1.33/24', allowed_users: 'siamert13'}
- { role: 'siamert14', default_user: 'siamert', cidr_list: '192.168.1.34/24', allowed_users: 'siamert14'}
- { role: 'siamert15', default_user: 'siamert', cidr_list: '192.168.1.35/24', allowed_users: 'siamert15'}