Browse Source

Merge pull request #29 from brot/f/user_with_more_keys

Refactor auth.sls to allow more keys for one user
tags/v0.41.0
Nitin Madhok 10 years ago
parent
commit
7adb33ca01
2 changed files with 39 additions and 26 deletions
  1. +29
    -22
      openssh/auth.sls
  2. +10
    -4
      pillar.example

+ 29
- 22
openssh/auth.sls View File

include:
- openssh
{%- from "openssh/map.jinja" import openssh with context -%}
{%- set openssh_pillar = pillar.get('openssh', {}) -%}
{%- set auth = openssh_pillar.get('auth', {}) -%}
{%- for user,keys in auth.items() -%}
{%- for key in keys -%}
{% if 'present' in key and key['present'] %}
{%- macro print_name(identifier, key) -%}
{%- if 'name' in key %}
{{ key['name'] }}: {{ key['name'] }}:
ssh_auth.present:
- user: {{ user }}
{%- if 'source' in key %}
{%- else %}
{{ identifier }}:
{%- endif %}
{%- endmacro -%}

{%- macro print_ssh_auth(identifier, key) -%}
{%- if 'user' in key %}
- user: {{ key['user'] }}
{%- else %}
- user: {{ identifier }}
{%- endif %}
{%- if 'present' in key and key['present'] and 'source' in key %}
- source: {{ key['source'] }} - source: {{ key['source'] }}
{%- else %} {%- else %}
{%- if 'enc' in key %} {%- if 'enc' in key %}
- options: {{ key['options'] }} - options: {{ key['options'] }}
{%- endif -%} {%- endif -%}
{%- endif %} {%- endif %}
{%- endmacro -%}

include:
- openssh
{%- from "openssh/map.jinja" import openssh with context -%}
{%- set openssh_pillar = pillar.get('openssh', {}) -%}
{%- set auth = openssh_pillar.get('auth', {}) -%}
{%- for identifier,keys in auth.items() -%}
{%- for key in keys -%}
{% if 'present' in key and key['present'] %}
{{ print_name(identifier, key) }}:
ssh_auth.present:
{{ print_ssh_auth(identifier, key) }}
- require: - require:
- service: {{ openssh.service }} - service: {{ openssh.service }}
{%- else %} {%- else %}
{{ key['name'] }}:
{{ print_name(identifier, key) }}:
ssh_auth.absent: ssh_auth.absent:
- user: {{ user }}
{%- if 'enc' in key %}
- enc: {{ key['enc'] }}
{%- endif -%}
{%- if 'comment' in key %}
- comment: {{ key['comment'] }}
{%- endif -%}
{%- if 'options' in key %}
- options: {{ key['options'] }}
{%- endif -%}
{{ print_ssh_auth(identifier, key) }}
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
{%- endfor -%} {%- endfor -%}

+ 10
- 4
pillar.example View File



openssh: openssh:
auth: auth:
joe:
- name: JOE_VALID_SSH_PUBLIC_KEY
joe-valid-ssh-key-desktop:
- user: joe
present: True present: True
enc: ssh-rsa enc: ssh-rsa
comment: main key
- name: JOE_NON_VALID_SSH_PUBLIC_KEY
comment: main key - desktop
joe-valid-ssh-key-notebook:
- user: joe
present: True
enc: ssh-rsa
comment: main key - notebook
joe-non-valid-ssh-key:
- user: joe
present: False present: False
enc: ssh-rsa enc: ssh-rsa
comment: obsolete key - removed comment: obsolete key - removed

Loading…
Cancel
Save