Created
November 4, 2021 18:32
-
-
Save robinsmidsrod/73e58fd751f1f4c6d29945a16c5b8ab4 to your computer and use it in GitHub Desktop.
userns.sls subuid subgid podman-compatible saltstack formula
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Only supported on Ubuntu 18.04 and newer | |
{% if grains.osmajorrelease >= 18 %} | |
userns.uidmap: | |
file.touch: | |
- name: /etc/subuid | |
- unless: test -f /etc/subuid | |
userns.gidmap: | |
file.touch: | |
- name: /etc/subgid | |
- unless: test -f /etc/subgid | |
{% set users = salt.user.getent() %} | |
{% set ns = namespace( count = 65536, start = 0) %} | |
{% for user in users %} | |
{% if user.uid >= 1000 and user.uid < 65534 %} | |
{% set ns.start = ns.start + 100000 %} | |
{% set ns.stop = ns.start + ns.count %} | |
userns.{{ user.name }}: | |
cmd.run: | |
- name: usermod --add-subuids {{ ns.start }}-{{ ns.stop }} --add-subgids {{ ns.start }}-{{ ns.stop }} {{ user.name }} | |
- unless: "grep -q '^{{ user.name }}:' /etc/subuid /etc/subgid 2>/dev/null" | |
- require: | |
- userns.uidmap | |
- userns.gidmap | |
{% endif %} | |
{% endfor %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment