this post was submitted on 21 Jul 2023
15 points (85.7% liked)

Linux

47237 readers
3343 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Hi all. I'm hoping to get some help from folks with more Linux experience than me. I'm not a Linux noob, but I'm far from an expert, and I have some huge gaps in my knowledge.

I have a Synology NAS that I am using for media storage, and I have a separate Linux server that is using that data. Currently the NAS is mounted with samba. it automatically mounts at boot via an entry in /etc/fstab. This is working okay, but I don't like how samba handles file ownership. The whole volume mounts as the user who mounts it (specified in fstab for me), and all the files in the volume are owned by that user. So if I wanted two users on my server to have their own directory, I would need to mount each directory separately for each user. This is workable in simple scenarios, but if I wanted to move my Lemmy instance volumes to my NAS, the file ownership of the DB and the pictrs volumes would get lost and the users in the containers wouldn't be able to access the data.

Is there a way to configure samba to preserve ownership? Or is there an alternate to samba that I can use that supports this?

Edit:

Okay, so I set up NFS, and it appears to do what I want. All of the user IDs carry over when I cp -a my files. My two users can write to directories that I set up for them that are owned by them. It seems all good on the surface. So I copied my whole lemmy folder over and tried to start up the containers, and postgres still crashes. The logs say "Permssion denied" and "chmod operation not permitted" back and forth forever. I tried to log into my container and see what is going on. Inside the container, root can't access a directory, which is bizarre. The container's root user can access that directory when I am running the container in my local filesystem. As a test, I tried copying the whole lemmy directory from my local filesystem to my local filesystem (instead of from local to NFS), and it worked fine.

I think this exact thing might be out of the scope of my original question, and I might need to make a post on [email protected] instead, as what I wanted originally has been accomplished with NFS.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 3 points 1 year ago (1 children)

Keep in mind that NFS only does what you want if the user numbers and group numbers match on both systems.

[–] [email protected] 1 points 1 year ago (1 children)

That is not true. I don't have matching IDs on my MacBook vs. my Linux server and the only thing it affects is wrong user/group displayed in e.g. ls output (and I kinda feel like that's idmap not working correctly on the Mac, though I'm also not too familiar with how it should work). If that's what you mean by "does what you want", sure, but permissions are handled correctly.

[–] [email protected] 0 points 1 year ago (1 children)

Yes, displaying the wrong user is a symptom of it not enforcing security.

I'm not sure what idmap is. Does it allow the user numbers to be translated per folder?

Consider this setup: Two users on the server, Bob: 1001 and Jane 1002, and they have each been given ownership and exclusive access to separate folders.

Then you mount that to another machine where the user numbers are swapped. In that case, Bob gets Jane's files and Jane gets Bob's files.

Or worse, someone else on the network connects to the share with the 1001 user number. Then they get access to all of Bob's files. This can be prevented by limiting access to the share from a single IP.

[–] [email protected] 2 points 1 year ago

Okay sure, if you're talking about using it without authentication, then all bets are off anyway. IP-based access isn't secure if you have a malicious/misconfigured device in the same network (and don't lock your network down specifically to prevent this).

As far as I can tell (i.e. partially infer from behavior since I can't find detailed documentation), idmap does two things:

  • Map between local uids/gids and NFS user/group names (NFS v4 users/groups are strings, not integers), both for display purposes on the client (exactly for the ID mismatch problem) and access control on the server (since FS permissions use local IDs)
  • Map between krb5 principal and NFS user names, for access control on the server

Also, idmap falls back to nobody/nogroup if it can't map (which is configurable).

For example, my network uses the krb5 realm HOME.DBLSAIKO.NET. My user saiko has three parts, the local user saiko (with uid 1000 on NFS server and my desktop, but not the MacBook), the principal [email protected] and the nfs user string [email protected] which is automatically inferred from the two other names.

In a directory listing, the nfs server reads the directory, idmap converts the stored uid 1000 to [email protected] and sends that to the client, the client converts that back to uid 1000 to display in an ls listing or whatever.

When the client tries to access a file, the security ticket it sends with the request is for [email protected], which the server maps to uid 1000 and checks the permissions on the file system. So for security, the only thing that matters is that idmap correctly works on the server but is independent of client uids.

As a result, the displayed permissions and the actually enforced permissions are independent from one another since they map to two different things. That's why on my MacBook, even though my user has id 501 and for some reason idmap doesn't work so it shows my directory on the NFS share being owned by "1000 _lpoperator" instead of "saiko users", I can still access it because I have the correct security ticket. (And conversely, if I get a security ticket for a different principal while logged in as saiko with working clientside idmap, the nfs share looks like I could access it according to displayed permissions but I get a permission denied error.)

Note that idmap can also work without authentication, but has to be explicitly enabled on the nfs/nfsd kernel module or in /sys. I assume then, instead of the security ticket, the client sends the nfs username with each request and that's what it checks against.