Support overriding uid/gid in overlayfs
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): 1358254695.3380.16.camel@avalon
Miklos Szeredi
maintainerQuoted 6 lines · Alessandro Pignotti
Hi Miklos,
I hope you are the right person to send this. I've been working over the last few days to add uid/gid overriding support in overlayfs. I think the patch is in a fairly good state, but I'm open to suggestions about how to make it good enough for acceptance in your tree.
Please add linux-fsdevel list for overlayfs related posts.
Quoted 3 lines
The main idea is that the uid/gid of overlayfs inodes are overridden if needed so that the user space sees only the custom uid/gids.
Why?
Quoted 7 lines
Currently, even when a custom uid or gid is used, files in the upperdir are created with the actual fsuid/fsgid of the current user (as usual), but they are still seen as being owned by the custom uid/gid. I'm not sure if this is the best approach, another possibility would be to impersonate the custom uid/gid when creating objects in upperdir. I'm open to suggestions about the best way to handle this situation.
I cannot say without knowing more about what this will be used for.
Thanks,
Miklos
Hi everyone,
the proposed patch would be useful in the following scenario
1) There is a large directory tree which needs to be fully read/write accessible from many different users, although in an isolated way (i.d. the changes made by Alice should not be visible to Bob)
2) All users expect to be owning the files. (i.d. that everything is private)
With the proposed patch it is possible to store a single copy of the base directory tree and use it as the lowerdir. The upperdir is then set to a private user-writable directory. Each user as the illusion of a private fully-writable installation as required. Moreover, since all the changed files ends up in the upperdir it's easy to pack them for backup purposes.
I'm attaching an improved version of the patch, which is being currently used in our setup and seems to be working ok. I think this functionality may be useful to others and I'd like to receive feedback on how to improve it to make it fit for upstream inclusion.
Regards,
Alessandro Pignotti
Il giorno ven, 25/01/2013 alle 12.08 +0100, Miklos Szeredi ha scritto:
Quoted 25 lines
Quoted 6 lines · Alessandro Pignotti
Hi Miklos,
I hope you are the right person to send this. I've been working over the last few days to add uid/gid overriding support in overlayfs. I think the patch is in a fairly good state, but I'm open to suggestions about how to make it good enough for acceptance in your tree.
Please add linux-fsdevel list for overlayfs related posts.
Quoted 3 lines
The main idea is that the uid/gid of overlayfs inodes are overridden if needed so that the user space sees only the custom uid/gids.
Why?
Quoted 7 lines
Currently, even when a custom uid or gid is used, files in the upperdir are created with the actual fsuid/fsgid of the current user (as usual), but they are still seen as being owned by the custom uid/gid. I'm not sure if this is the best approach, another possibility would be to impersonate the custom uid/gid when creating objects in upperdir. I'm open to suggestions about the best way to handle this situation.
Quoted 4 lines
I cannot say without knowing more about what this will be used for.
Thanks,
Miklos
fs/overlayfs/copy_up.c +2 -0
@@ -320,6 +320,7 @@int ovl_copy_up (struct dentry *dentry) {int err; +struct ovl_fs *ofs = dentry->d_sb->s_fs_info; err =0 ;while (!err) {
@@ -347,6 +348,7 @@ovl_path_lower (next, &lowerpath); err =vfs_getattr (lowerpath.mnt, lowerpath.dentry, &stat); +ovl_filter_stat (&ofs->config, &stat);if (!err) err =ovl_copy_up_one (parent, next, &lowerpath, &stat);
fs/overlayfs/dir.c +6 -2
@@ -245,6 +245,7 @@int err;enum ovl_path_type type;struct path realpath; +struct ovl_fs *ofs = dentry->d_sb->s_fs_info; type =ovl_path_real (dentry, &realpath); err =vfs_getattr (realpath.mnt, realpath.dentry, stat);
@@ -253,6 +254,7 @@ stat->dev = dentry->d_sb->s_dev; stat->ino = dentry->d_inode->i_ino; +ovl_filter_stat (&ofs->config, stat);/* * It's probably not worth it to count subdirs to get the
@@ -269,6 +271,7 @@ const char *link) {int err; +struct ovl_fs *ofs = dentry->d_sb->s_fs_info;struct dentry *newdentry;struct dentry *upperdir;struct inode *inode;
@@ -304,7 +307,7 @@ } }ovl_dentry_update (dentry, newdentry); -ovl_copyattr (newdentry->d_inode, inode); +ovl_copyattr (&ofs->config,newdentry->d_inode, inode);d_instantiate (dentry, inode); inode =NULL ; newdentry =NULL ;
@@ -415,6 +418,7 @@ struct dentry *new) {int err; +struct ovl_fs *ofs = old->d_sb->s_fs_info;struct dentry *olddentry;struct dentry *newdentry;struct dentry *upperdir;
@@ -447,7 +451,7 @@ new->d_fsdata);if (!newinode) goto link_fail; -ovl_copyattr (upperdir->d_inode, newinode); +ovl_copyattr (&ofs->config,upperdir->d_inode, newinode);ovl_dentry_version_inc (new->d_parent);ovl_dentry_update (new, newdentry);
fs/overlayfs/inode.c +42 -1
70 lines not on this page · raw message
fs/overlayfs/overlayfs.h +29 -3
@@ -9,6 +9,23 @@struct ovl_entry ; +struct ovl_config { +char *lowerdir; +char *upperdir; +kuid_t uid; +kgid_t gid; +int use_uid:1 ; +int use_gid:1 ; +}; + +/* private information held for overlayfs's superblock */ +struct ovl_fs { +struct vfsmount *upper_mnt; +struct vfsmount *lower_mnt; +/* pathnames of lower and upper dirs, for show_options */ +struct ovl_config config; +}; +enum ovl_path_type {OVL_PATH_UPPER ,OVL_PATH_MERGE ,
@@ -56,10 +73,19 @@struct inode *ovl_new_inode (struct super_block *sb,umode_t mode,struct ovl_entry *oe); -static inline void ovl_copyattr (struct inode *from,struct inode *to) +static inline void ovl_copyattr (const struct ovl_config * config,struct inode *from,struct inode *to) +{ + to->i_uid = (config->use_uid)?config->uid:from->i_uid; + to->i_gid = (config->use_gid)?config->gid:from->i_gid; +} + +static inline void ovl_filter_stat (const struct ovl_config * config,struct kstat * stat) { - to->i_uid = from->i_uid; - to->i_gid = from->i_gid; +/* Override the uid and gid with the ones provided if needed */ +if (config->use_uid) + stat->uid = config->uid; +if (config->use_gid) + stat->gid = config->gid; }/* dir.c */
fs/overlayfs/super.c +30 -14
89 lines not on this page · raw message
Miklos Szeredi
maintainerQuoted 10 lines · Alessandro Pignotti
Hi everyone,
the proposed patch would be useful in the following scenario
1) There is a large directory tree which needs to be fully read/write accessible from many different users, although in an isolated way (i.d. the changes made by Alice should not be visible to Bob)
2) All users expect to be owning the files. (i.d. that everything is private)
Quoted 6 lines
With the proposed patch it is possible to store a single copy of the base directory tree and use it as the lowerdir. The upperdir is then set to a private user-writable directory. Each user as the illusion of a private fully-writable installation as required. Moreover, since all the changed files ends up in the upperdir it's easy to pack them for backup purposes.
Okay, makes sense.
One issue, though, is that stat("x") and fd=open("x"); fstat(fd) will return different file stats (the fstat one will return the stats for
the original file). This may confuse some apps.
This is a something a "true" union filesystem can do better that union-mounts or overlayfs.
Thanks,
Miklos
Miklos Szeredi:
Quoted 6 lines
One issue, though, is that
stat("x")and fd=open("x"); fstat(fd) will return different file stats (the fstat one will return the stats for
the original file). This may confuse some apps.This is a something a "true" union filesystem can do better that union-mounts or overlayfs.
Exactly.
That was one example I picked up and posted when I read overlayfs years ago.
Recently I named it "name-based union". Of course AUFS is "inode-based union." stat(2) operates upon a filename while fstat(2) operates upon a file descriptor. Overlayfs (and probably UnionMount too) may return different info for these two systemcalls even when they should be equal. All the inode-based (or file descriptor based) operations can confuse users in overlayfs, I am afraid. I was looking forward to see how overlayfs solve this problem.
Overriding uid/gid is an idea, but obviously it will not match using with system dirs such as /bin and /usr, since they often have suid binaries. So it will be used only for user dirs which is unioned as lower RO layer. It might be better to implement such feature into your lower FS (or generic VFS feature) instead of overlayfs.
If I remember correctly, some non-unix FS such as VFAT already have such feature.
J. R. Okajima
Miklos Szeredi
maintainerQuoted 9 lines · J. R. Okajima
Miklos Szeredi:
Quoted 6 lines
One issue, though, is that
stat("x")and fd=open("x"); fstat(fd) will return different file stats (the fstat one will return the stats for
the original file). This may confuse some apps.This is a something a "true" union filesystem can do better that union-mounts or overlayfs.
Quoted 10 lines
Exactly.
That was one example I picked up and posted when I read overlayfs years ago.
Recently I named it "name-based union". Of course AUFS is "inode-based union." stat(2) operates upon a filename while fstat(2) operates upon a file descriptor. Overlayfs (and probably UnionMount too) may return different info for these two systemcalls even when they should be equal. All the inode-based (or file descriptor based) operations can confuse users in overlayfs, I am afraid. I was looking forward to see how overlayfs solve this problem.
They don't "solve" this, it's a fundamental property of the implementation. Overlayfs and union-mounts behave as if copy-up was a "bind mount" over the file in question. Yes, it's a namespace trick but it seems to work in most situations.
Quoted 8 lines
Overriding uid/gid is an idea, but obviously it will not match using with system dirs such as /bin and /usr, since they often have suid binaries. So it will be used only for user dirs which is unioned as lower RO layer. It might be better to implement such feature into your lower FS (or generic VFS feature) instead of overlayfs.
If I remember correctly, some non-unix FS such as VFAT already have such feature.
The point was that uid/gid was to be overridden with *different* values for each overlayfs instance. So implementing uid/gid overriding in the lower fs doesn't help.
Thanks,
Miklos
Miklos Szeredi:
Quoted 4 lines
They don't "solve" this, it's a fundamental property of the implementation. Overlayfs and union-mounts behave as if copy-up was a "bind mount" over the file in question. Yes, it's a namespace trick but it seems to work in most situations.
It must be a sad news for overlayfs users who have every met "non-most" situations.
Quoted 3 lines
The point was that uid/gid was to be overridden with *different* values for each overlayfs instance. So implementing uid/gid overriding in the lower fs doesn't help.
For the scenario which Alessandro Pignotti posted,
- everything on the lower fs are owned by a single user, by the overriding feature.
- everything on the upper fs are owned by the user natively. Isn't it enough?
J. R. Okajima