-
Notifications
You must be signed in to change notification settings - Fork 13
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
Issue: GID for group already in use by a different group #509
Comments
I did some initial analysis. The error originates here: authd/internal/users/cache/update.go Lines 92 to 96 in e80ad26
We set the authd/internal/brokers/broker.go Line 397 in e80ad26
and here: authd/internal/brokers/broker.go Line 404 in e80ad26
Both of these GIDs are generated by I wonder why we store the GID in our database at all. Wouldn't it be enough to store the group name and use |
Are you sure? The logs
So, Also, relying on adduser/addgroup for storing an user and group won’t solve one of the use case for directory handling: shared ressources. If you have a disk shared with nfs for instance, you need to map your uid/gid to the ones on disk for access permissions. This is why you need predictable UIDs and GIDs, and some that are shared across multiples machines and not generated per machines. (In a previous implementation, we were just adding one increment after another in case of collision, but we decided against it in this one and wanted to see if the collision rate was high). Also, we need to predict the UID even before it’s created on disk for ssh first user access, which is doing a pre-flight even before authentication. Returning a different UID will then puzzle sshd and result in various errors on first login. This is for those reasons we didn’t went for +increments right away. Out of curiosity. can you share the conflicting ID groups name? We can probably work the generation algorithm to ensure we end up with less conflicts. |
What I meant is that
But don't we add the group to
How does the current implementation get us predictable GIDs across multiple machines? IIUC, we generate the GIDs per authd instance, and we don't support using an authd instance from a different machine. What am I missing?
What do you mean with "pre-flight even before authentication"?
I couldn't reproduce the error myself, it was reported on #496. |
No, we do add a remote user to a local groups, this is group already handled by the local group utils. There is an option to request nss to still go through groups membership even if it found one matching, but this option is not enabled on Ubuntu by default and it’s something we should explore (but we shouldn’t do that without the distro support).
The implementation is computing the GIDs only based on the string passed to it: https://github.com/ubuntu/authd/blob/main/internal/users/manager.go#L418. There is nothing random. The proof is that the tests even assert the generated id, despite CI running on different machines.
sshd needs to ensure an user potentially exists before going on with authentication. Otherwise, it raised a mock authentication (so that the remote attacker doesn’t know if the user exists or not in the machine) with an unmatchable password. To do this pre-check, it does an NSS request even before the pam authenticaiton starts and expect a real passwd entry for the user, with the UID and user name matching the one that will be returned later, after authentication. However, on first login, we don’t have such user information (we even don't know if the user exists). This is why we thus needs a predictable ID so that, if later authentication succeed, we can then return a matching user information. |
Ah, I didn't actually read the implementation and assumed it's generating a random ID 😅 This approach will inherently lead to UID/GID conflicts though. I don't see a way to both have a predictable UID/GID and avoid conflicts, so we should weigh up the benefits of a predictable UID/GID (the shared disk use case you mentioned - is there anything else?) and the drawbacks (unsuccessful logins). |
Indeed, there is none. (share disk and ssh are the 2 reasons). I think though that maybe we can come up with an algorithm that would lead to less collisions? I wouldn’t have expected to see one so fast and that worries me, so there is probably better possible implementation (which will require a transition plan). |
I'm not sure I correctly understood the SSH case, but the way I understand it, we should be able to solve it by generating a random UID ourselves until we generated one that doesn't exist yet on the system, no? That's still prone to a race, because the UID could have been taken by the time the user successfully authenticated and we actually try to create the user with that UID on the system, but that should be a rare enough case that it's fine to fail with a descriptive error message if that happens.
Given the small range of IDs we generate, I don't think there is any way to avoid collisions with an acceptable probability.
The fact that a surprisingly low number of elements from a relatively large set are needed to get a high probability of collisions is known as the birthday paradox. |
Yeah, I feel that's a potential issue, but indeed we could potentially hold that UID until done, so that it's returned by nss. |
Experiencing the same problem. The logs: |
After taking a closer look, I don't think this check is enough to avoid UID/GID clashes, because we only check if the UID/GID is already stored in our database, but we don't check if it's in use by any other NSS sources on the system, right? |
Am understanding this conversation correctly to mean that different linux cloud instances might end up with different assigned UIDs and GIDs for the same verified AAD user? If so, what happens when the home dir lives on an NFS mounted file system, where the ACLs are based on the UID and GID? Couldn't the user end up not owning their own home directory? |
Yes, that's correct. We're exploring ways to support shared network resources like NFS which rely on UIDs and GIDs for access, but for now that's a known limitation. We plan to add that to the limitations section of the authd wiki. |
Thanks -- that's what I was afraid of... Any suggestions or advice on temporary work arounds? This is a killer for trying to use authd to facilitate centralized logins with a bunch of azure linux instances. Only solution we've come up with so far is including a list of manually maintained |
Removing users from the database allows other users for which the same UID is generated (which can happen, see #509) to log in and gain access to the deleted user’s home directory. UDENG-4658
if authd randomly generates UIDs & GIDs, why not get it to instead have some function that takes fully qualified AzureAD usernames and groups as inputs, and generates UIDs/GIDs from their (numeric) hash? That way all authd's instances will always generate the same UIDs/GIDs without needing some central database. For security/privacy reasons, an improvement would be for each org to set an "org_seed" value - which gets prepended to the username/groupname - thus generating the same UID/GID across all installs with the same "org_seed" - but being undiscoverable by anyone else? Can't think of an attack vector - but that just means I don't have the imagination ;-) |
That's what authd is currently doing (see the implementation of the |
I think random IDs are going to be problematic, even if the computation is deterministic. Say Sally and Bob both hash to the same UID, then on the same machine, who gets assigned the next random unique UID will vary depending on the login order, and on two different machines, both could potentially get the same UID assigned since the machines don't communicate that a UID has already been taken... I think you'd have to scan the entire list of users and generate a complete list of UIDs in order of account creation to be sure that this was completely deterministic and UIDs don't ever change once the account is created.. I guess if you access that data, you could also just assign UIDs to everyone starting at some fixed number based on the order in which users were added to the org... If possible, seems like storing a UID in the Entra directory, if possible (don't know enough about what's possible with AAD), it would be safer. Then it's on the org to avoid collisions when adding new users. Guess you'd have to do the same for groups... |
Agree with @mazer-ai. If you resolve collisions the way you describe, @adombeck, then the same user (or group, re the topic of this ticket) on different machines could have different IDs, which will lead to permission inconsistencies on shared network-mounted drives. Storing IDs in Entra could work. |
We're aware of that. That's why I wrote above that we don't support shared network resources like NFS at the moment. It's now also mentioned in the limitations section of the wiki. |
You had said "another approach we're exploring is to store the IDs in the Entra directory." That would support shared network resources. Is this still something you're considering? It's what I was hoping to encourage with my comment. It would be very helpful. |
Thank you for your input, hearing about actual user needs helps us prioritize! The outcome of the research regarding storing IDs in the Entra directory is that it would come with some drawbacks. We have not yet made a decision if we want to support that or not, but will do so within the next few weeks. |
That's great. Thanks for your response, @adombeck, and thank you for your work on authd. |
I'm running into this error after renaming a group in EntraID.
The group named XXXX was renamed to YYYY after initially setting up authd and logging in with a user that is a member of the group. Would this be solved somehow by explicitly rebuilding the cache of group names? |
@arion-ch That sounds like an interesting edge case which we probably don't support well currently. Do you mind creating a separate issue for that, including the exact steps to reproduce? |
We decided to not store UIDs and GIDs centrally in the Entra directory. Instead, we will generate random UIDs and GIDs and document how to use Samba and NFS + Kerberos with ID mapping (see #653). The main reasons for this decision are:
|
Thank you for the update. FYI, the use case we expected and hoped for was that we would create the UIDs and store them in Entra outside of authd. We would be responsible for worrying about and resolving any race conditions, etc. Authd would simply be configured to read those values. This is disappointing, as supporting a network mounted drive is a requirement for us. We'll have to find an alternative to authd (or keep our fingers crossed for the day when you decide to support this, should we not find a viable alternative). |
To solve the issues with UID/GID generation (see #509 and UDENG-4874), we decided to generate random unique UIDs/GIDs. That means that using authd with network filesystems will result in permission issues unless it's correctly configured to use map IDs. Since there don't seem to be any good existing resources on how to do that, we document it ourselves. Closes #653 UDENG-5414
We have now documented how you can use authd with network filesystems (NFS or Samba). The starting point is: https://canonical-authd.readthedocs-hosted.com/en/latest/reference/troubleshooting/#file-ownership-on-shared-network-resources-e-g-nfs-samba |
Describe the issue
Reported by @jhaar on #496:
The text was updated successfully, but these errors were encountered: