Skip to content

Instantly share code, notes, and snippets.

@robinsmidsrod
Created November 4, 2021 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinsmidsrod/73e58fd751f1f4c6d29945a16c5b8ab4 to your computer and use it in GitHub Desktop.
Save robinsmidsrod/73e58fd751f1f4c6d29945a16c5b8ab4 to your computer and use it in GitHub Desktop.
userns.sls subuid subgid podman-compatible saltstack formula
# 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