-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pillar and use it to configure the state #9
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
split-ssh-role: | ||
client-template: True | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
split-ssh-role: | ||
client: True |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Load config | ||
#{% load_yaml as config %} | ||
#{% include 'split-ssh/config.yaml' %} | ||
#{% endload %} | ||
--- | ||
split-ssh-clients: | ||
{{ config.clients }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
vaults: | ||
- name: ssh-vault | ||
template: fedora-32 | ||
label: black | ||
mem: 400 | ||
vcpus: 2 | ||
autostart: True | ||
|
||
clients: | ||
- name: ssh-client | ||
template: fedora-32 | ||
label: blue | ||
mem: 400 | ||
vcpus: 2 | ||
autostart: False | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
## Load config | ||
#{% load_yaml as config %} | ||
#{% include 'split-ssh/config.yaml' %} | ||
#{% endload %} | ||
# | ||
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This template must yield valid YAML. A simple way to prevent the output of these Jinja statements and expressions from breaking the YAML is to comment them ( |
||
## Collect information about the client(s) | ||
#{% set client_names = [] %} | ||
#{% set client_templates = [] %} | ||
# | ||
#{% for client in config.clients %} | ||
#{{ client_names.append(client.name) }} | ||
#{{ client_templates.append(client.template) }} | ||
#{% endfor %} | ||
# | ||
## Collect information about the vault(s) | ||
#{% set vault_names = [] %} | ||
#{% set vault_templates = [] %} | ||
# | ||
#{% for vault in config.vaults %} | ||
#{{ vault_names.append(vault.name) }} | ||
#{{ vault_templates.append(vault.template) }} | ||
#{% endfor %} | ||
# | ||
## Deduplicate and sort the lists to allow comparisons | ||
## and ensure consistency | ||
#{% set client_names = client_names|unique|sort %} | ||
#{% set client_templates = client_templates|unique|sort %} | ||
#{% set vault_names = vault_names|unique|sort %} | ||
#{% set vault_templates = vault_templates|unique|sort %} | ||
--- | ||
user: | ||
dom0: | ||
- split-ssh.clients | ||
- split-ssh.vaults | ||
|
||
{# Prevent duplicate keys error when client and vault templates are the same #} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Salt doesn't tolerate duplicate keys in mappings. That could happen if the list of vault templates were identical to the list of client templates (e.g. both share the same |
||
{% if client_templates == vault_templates %} | ||
{{ client_templates|join(',') }}: | ||
- match: list | ||
- split-ssh.client-template | ||
- split-ssh.vault-template | ||
{% else %} | ||
{{ client_templates|join(',') }}: | ||
- match: list | ||
- split-ssh.client-template | ||
|
||
{{ vault_templates|join(',') }}: | ||
- match: list | ||
- split-ssh.vault-template | ||
{% endif %} | ||
|
||
{# The clients and vaults themselves won't be the same qubes (split-SSH) #} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are Jinja comments because they wouldn't be of any use in the resulting YAML file. |
||
|
||
{{ client_names|join(',') }}: | ||
- match: list | ||
- split-ssh.client | ||
|
||
{{ vault_names|join(',') }}: | ||
- match: list | ||
- split-ssh.vault |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
split-ssh-role: | ||
vault-template: True |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
split-ssh-role: | ||
vault: True |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Load config | ||
#{% load_yaml as config %} | ||
#{% include 'split-ssh/config.yaml' %} | ||
#{% endload %} | ||
--- | ||
split-ssh-vaults: | ||
{{ config.vaults }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ make install DESTDIR=%{buildroot} | |
%files | ||
%license LICENSE | ||
%doc README.md | ||
%config /srv/user_pillar/config.yaml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allows the configuration file to be kept when the package is updated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For future reference: the correct path is |
||
/srv/user_pillar/split-ssh | ||
/srv/user_salt/split-ssh | ||
|
||
%changelog | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ user: | |
dom0: | ||
- split-ssh.client.vm | ||
|
||
fedora-32: | ||
'split-ssh-role:client-template': | ||
- match: pillar | ||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assigning roles in the pillar allows to match qubes without relying on Salt grains. |
||
- split-ssh.client.packages | ||
|
||
ssh-client: | ||
'split-ssh-role:client': | ||
- match: pillar | ||
- split-ssh.client.sock |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# Ensure the SSH socket discoverability | ||
# | ||
# See /srv/salt/split-ssh in dom0 for details. | ||
SSH_VAULT_VM="ssh-vault" | ||
SSH_VAULT_VM="{{ pillar.split-ssh-vaults|first }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a current limitation: even if multiple vaults were defined in the configuration ( I didn't find any convenient way to specify which client should use which vault, and I am OK with this limitation until someone actually needs to use multiple vaults. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For future reference: the correct syntax is ( |
||
|
||
if [[ "$SSH_VAULT_VM" != "" ]]; then | ||
export SSH_AUTH_SOCK=~user/.SSH_AGENT_$SSH_VAULT_VM | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
ssh-socket-present: | ||
file.append: | ||
- name: /rw/config/rc.local | ||
- source: salt://split-ssh/client/files/rc.local.d/sock | ||
- source: salt://split-ssh/client/files/rc.local.d/sock.jinja | ||
- template: jinja | ||
|
||
ssh-socket-discoverable: | ||
file.append: | ||
- name: ~user/.bashrc | ||
- source: salt://split-ssh/client/files/bashrc.d/sock | ||
- source: salt://split-ssh/client/files/bashrc.d/sock.jinja | ||
- template: jinja |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
ssh-client-present: | ||
{% for client in pillar.split-ssh-clients %} | ||
{{ client.name }}-present: | ||
qvm.present: | ||
- name: ssh-client | ||
- template: fedora-32 | ||
- label: blue | ||
- mem: 400 | ||
- vcpus: 2 | ||
- name: {{ client.name }} | ||
- template: {{ client.template }} | ||
- label: {{ client.label }} | ||
- mem: {{ client.mem }} | ||
- vcpus: {{ client.vcpus }} | ||
|
||
{{ client.name }}-autostarts: | ||
qvm.prefs: | ||
- name: {{ client.name }} | ||
- autostart: {{ client.autostart }} | ||
{% endfor %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
ssh-client ssh-vault ask | ||
{% for vault in pillar.split-ssh-vault %} | ||
{% for client in pillar.split-ssh-client %} | ||
{{ client.name }} {{ vault.name }} ask | ||
{% endfor %} | ||
{% endfor %} | ||
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All clients can ask any of the vaults for SSH keys. The default behavior ( |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
- mode: '0755' | ||
- makedirs: True | ||
- source: salt://split-ssh/policy/files/qubes.SSHAgent | ||
- template: jinja | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the default for |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
split-ssh-role
value must be a mapping to allow a qube to assume multiple roles. (For example,fedora-32
could be both theclient-template
andvault-template
.)When the value is not a mapping, the latter value overrides the earlier one when the different
.sls
files are merged by Salt. (I believe that is standard YAML behavior.)