Skip to content
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

Merged
merged 4 commits into from
Feb 27, 2021
Merged

Conversation

gonzalo-bulnes
Copy link
Owner

@gonzalo-bulnes gonzalo-bulnes commented Feb 27, 2021

Enable use of pillar in the state files that depend
directly on the clients and vaults configuration.

Note: the configuration of the SSH socket (SSH_VAULT_VM) currently
limits the number of vault qubes to one. All the clients will be
configured to use the vault that is defined first.

The configuration file is identified as such and should be kept
when the package is reinstalled.
Enable the use of those roles in the states that depend on them.

At this point, the state is entirely defined by the configuration.
Comment on lines +1 to +2
split-ssh-role:
client-template: True
Copy link
Owner Author

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 the client-template and vault-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.)

Comment on lines +1 to +5
## Load config
#{% load_yaml as config %}
#{% include 'split-ssh/config.yaml' %}
#{% endload %}
#
Copy link
Owner Author

@gonzalo-bulnes gonzalo-bulnes Feb 27, 2021

Choose a reason for hiding this comment

The 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 (#). These YAML comments do not affect the Jinja pre-processor.

- split-ssh.vault-template
{% endif %}

{# The clients and vaults themselves won't be the same qubes (split-SSH) #}
Copy link
Owner Author

Choose a reason for hiding this comment

The 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.

- split-ssh.clients
- split-ssh.vaults

{# Prevent duplicate keys error when client and vault templates are the same #}
Copy link
Owner Author

Choose a reason for hiding this comment

The 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 fedora-32 template, it is actually a common scenario). Conveniently, in that case both the vault-template and client-template roles can be assigned at once.

@@ -25,6 +25,8 @@ make install DESTDIR=%{buildroot}
%files
%license LICENSE
%doc README.md
%config /srv/user_pillar/config.yaml
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows the configuration file to be kept when the package is updated.
See http://ftp.rpm.org/max-rpm/s1-rpm-inside-files-list-directives.html

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference: the correct path is /srv/user_pillar/split-ssh/config.yaml (oops 🙄) see f3ea644

Comment on lines +5 to +6
'split-ssh-role:client-template':
- match: pillar
Copy link
Owner Author

Choose a reason for hiding this comment

The 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.

@@ -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 }}"
Copy link
Owner Author

Choose a reason for hiding this comment

The 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 (/srv/user_pillar/config.yaml), all the clients would be configured to use the first vault in the list.

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.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference: the correct syntax is (pillar.get('split-ssh-vaults') and the value must be made available in the clients for it to be accessible (in the top file: split-ssh/init.jinja). See f3ea644

Comment on lines +1 to +5
{% for vault in pillar.split-ssh-vault %}
{% for client in pillar.split-ssh-client %}
{{ client.name }} {{ vault.name }} ask
{% endfor %}
{% endfor %}
Copy link
Owner Author

Choose a reason for hiding this comment

The 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 (ask or allow) could be configured, but I don't see the need for now.

@@ -5,4 +5,5 @@
- mode: '0755'
- makedirs: True
- source: salt://split-ssh/policy/files/qubes.SSHAgent
- template: jinja
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default for file.managed, but I think being explicit makes it clearer.

@gonzalo-bulnes gonzalo-bulnes merged commit 91de1e1 into main Feb 27, 2021
@gonzalo-bulnes gonzalo-bulnes mentioned this pull request Feb 28, 2021
3 tasks
@gonzalo-bulnes gonzalo-bulnes deleted the add-pillar branch September 27, 2023 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant