How to add extra user to group

I was just going to file a new thread about this issue, after speaking with @jamesh about it - I was wondering if this recent thread was a similar problem, but I think it’s not, and this is a “pure” tooling issue.

Here’s how it comes up for me in practice

  • Deploy an Ubuntu core machine, interactively set up a user via my Ubuntu SSO account
  • SSH in, install the LXD snap
    • This creates the lxd group in extragroups successfully.
  • How do I add my initial user to this group?

As far as I can tell there’s no way to do this beyond actually editing extragroups myself. Neither usermod nor adduser can do it. In Ubuntu (therefore core) we have some patches to useradd to support extra{users,groups}, but they 're incomplete; usermod does not support extragroup. (There is no call to gr_setdbname for usermod.) I guess that is simply work that needs to be done.

Now that’s for the interactive case. What about when deploying using cloud-init or using a model (required-snaps) & a system-user assertion as @ogra was getting at 1 year ago? Can someone else comment - is there a declarative way here to achieve this same thing? Create user, install lxd snap, add user to lxd group. Or is it direct file modification there too?