Linux-Fsdevel Archive on lore.kernel.org
 help / color / Atom feed
From: Andreas Dilger <adilger@dilger.ca>
To: Dave Chinner <david@fromorbit.com>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>,
	Wang Shilong <wangshilong1991@gmail.com>,
	linux-xfs <linux-xfs@vger.kernel.org>,
	Linux FS-devel Mailing List <linux-fsdevel@vger.kernel.org>,
	Ext4 Developers List <linux-ext4@vger.kernel.org>,
	Li Xi <lixi@ddn.com>, Wang Shilong <wshilong@ddn.com>
Subject: Re: [Project Quota]file owner could change its project ID?
Date: Wed, 23 Oct 2019 17:01:45 -0600
Message-ID: <6B0D1F84-0718-4E43-87D4-C8AFC94C0163@dilger.ca> (raw)
In-Reply-To: <20191021233547.GA2681@dread.disaster.area>

[-- Attachment #1: Type: text/plain, Size: 10759 bytes --]

On Oct 21, 2019, at 5:35 PM, Dave Chinner <david@fromorbit.com> wrote:
> 
> On Wed, Oct 16, 2019 at 06:28:08PM -0600, Andreas Dilger wrote:
>> On Oct 16, 2019, at 3:37 PM, Darrick J. Wong <darrick.wong@oracle.com> wrote:
>>> 
>>> On Wed, Oct 16, 2019 at 07:51:15PM +0800, Wang Shilong wrote:
>>>> On Mon, Oct 14, 2019 at 12:41 AM Darrick J. Wong
>>>> <darrick.wong@oracle.com> wrote:
>>>>> 
>>>>> On Sat, Oct 12, 2019 at 02:33:36PM +0800, Wang Shilong wrote:
>>>>>> Steps to reproduce:
>>>>>> [wangsl@localhost tmp]$ mkdir project
>>>>>> [wangsl@localhost tmp]$ lsattr -p project -d
>>>>>>   0 ------------------ project
>>>>>> [wangsl@localhost tmp]$ chattr -p 1 project
>>>>>> [wangsl@localhost tmp]$ lsattr -p -d project
>>>>>>   1 ------------------ project
>>>>>> [wangsl@localhost tmp]$ chattr -p 2 project
>>>>>> [wangsl@localhost tmp]$ lsattr -p -d project
>>>>>>   2 ------------------ project
>>>>>> [wangsl@localhost tmp]$ df -Th .
>>>>>> Filesystem     Type  Size  Used Avail Use% Mounted on
>>>>>> /dev/sda3      xfs    36G  4.1G   32G  12% /
>>>>>> [wangsl@localhost tmp]$ uname -r
>>>>>> 5.4.0-rc2+
>>>>>> 
>>>>>> As above you could see file owner could change project ID of file its self.
>>>>>> As my understanding, we could set project ID and inherit attribute to account
>>>>>> Directory usage, and implement a similar 'Directory Quota' based on this.
>>>>> 
>>>>> So the problem here is that the admin sets up a project quota on a
>>>>> directory, then non-container users change the project id and thereby
>>>>> break quota enforcement?  Dave didn't sound at all enthusiastic, but I'm
>>>>> still wondering what exactly you're trying to prevent.
>>>> 
>>>> Yup, we are trying to prevent no-root users to change their project ID.
>>>> As we want to implement 'Directory Quota':
>>>> 
>>>> If non-root users could change their project ID, they could always try
>>>> to change its project ID to steal space when EDQUOT returns.
>>>> 
>>>> Yup, if mount option could be introduced to make this case work,
>>>> that will be nice.
>>> 
>>> Well then we had better discuss and write down the exact behaviors of
>>> this new directory quota feature and how it differs from ye olde project
>>> quota.  Here's the existing definition of project quotas in the
>>> xfs_quota manpage:
>>> 
>>>      10.    XFS  supports  the notion of project quota, which can be
>>>             used to implement a form of directory tree  quota  (i.e.
>>>             to  restrict  a directory tree to only being able to use
>>>             up a component of the filesystems  available  space;  or
>>>             simply  to  keep  track  of the amount of space used, or
>>>             number of inodes, within the tree).
>>> 
>>> First, we probably ought to add the following to that definition to
>>> reflect a few pieces of current reality:
>>> 
>>> "Processes running inside runtime environments using mapped user or
>>> group ids, such as container runtimes, are not allowed to change the
>>> project id and project id inheritance flag of inodes."
>>> 
>>> What do you all think of this starting definition for directory quotas:
>>> 
>>>      11.    XFS supports the similar notion of directory quota.  The
>>> 	      key difference between project and directory quotas is the
>>> 	      additional restriction that only a system administrator
>>> 	      running outside of a mapped user or group id runtime
>>> 	      environment (such as a container runtime) can change the
>>> 	      project id and project id inheritenace flag.  This means
>>> 	      that unprivileged users are never allowed to manage their
>>>             own directory quotas.
>>> 
>>> We'd probably enable this with a new 'dirquota' mount option that is
>>> mutually exclusive with the old 'prjquota' option.
>> 
>> I don't think that this is really "directory quotas" in the end, since it
>> isn't changing the semantics that the same projid could exist in multiple
>> directory trees.
> 
> 
> The quota ID associated with a directory is an admin choice - admins
> are free to have multiple directories use the same quota ID if
> that's how they want to control usage across those directories.

Sure, I understand that, and am not suggesting anything change here.

> i.e. "directory quota" does not mean "quota IDs must be unique for
> different directory heirarchies", it just means quota IDs are
> assigned to new directory entries based on the current directory
> quota ID.

Essentially you mean "PROJID_INHERIT" is the difference between
"project quota" and "directory quota"?

>> The real difference is the ability to enforce existing
>> project quota limits for regular users outside of a container.
>> Basically, it is the same as regular users not being able to
>> change the UID of their files to dump quota to some other user.
> 
> No, no it isn't - project IDs are not user IDs. In fact, UIDs and
> permission bits are used to determine if the user has permission to
> change the project ID of the file. i.e. anyone who can write data to
> the file can change the project ID and "dump quota to some other
> user".

I fully understand that project IDs do no controlling file access.
That is IMHO one of the benefits of project quotas - that users can be
grouped together without automatically granting file access permissions.
My point is that people use quotas to track and limit space usage.  In
this regard, "project quotas" are only "project accounting" since can
be set arbitrarily, which inhibits the ability to limit project space
usage.

> That's the way it's always worked, and there are many users out
> there that rely on users setting project quotas correctly for their
> data sets. i.e. the default project quota is set up as a directory
> quota and they are set low to force people creating large data sets
> account them to the project that the space is being used for.

While this may be the way it's always worked, several new sites using
project quotas found this completely unintuitive.  Their objection is
that the benefit of project quota tracking is lost if users can easily
circumvent the tracking itself.  If there are no restrictions on which
projid values can be set on a file, how do users even know if they are
not arbitrarily using conflicting or incorrect projid values?

> IOWs, directory-based project quotas and project-based project quotas
> are often used in the same filesystem, and users are expected to
> manage them directly.
> 
> What is being asked for here is a strict interpretation of directory
> quotas to remove the capability of mixing directory and project
> based quotas in the one filesystem. That's not the same thing as
> an "enforced project quota".

Might I ask how would you implement "enforced project quota"?  Presumably
it mush prevent users from changing the project ID of a file arbitrarily,
as is allowed today?  It isn't a rhetorical question, I'm genuinely
interested what you would do as this is what users are asking for.

>> So rather than rename this "dirquota", it would be better to have a
>> an option like "projid_enforce" or "projid_restrict", or maybe some
> 
> If only specific admins can change project quotas, then the only way
> that project quotas can be used is either:
> 
> 	1. inherit project ID from parent directory at create time;
> 	or
> 	2. admin manually walks newly created files classifying them
> 	into the correct project after the fact.
> 
> #2 is pretty much useless to anyone - who wants to look at thousands
> of files a day and classify them to this project or that one? I
> haven't seen that admin model in use anywhere in the real world.

I wouldn't imagine admins doing this on a file-by-file basis either.

Rather, non-root admins could create new project directories (e.g.
when a new project is added to a system) and/or (in presumably rare
cases) change the projid of an existing tree.  This wouldn't be any
different than admins doing other quota admin, and not needing root
to do it is good security practice.

> Which leaves #1 - default project IDs inherited from the parent
> directory, and users can't change them. And that is the very
> definition of a strict directory quota...

I've previously steered away from using the term "directory quota"
(even though that's what exists in other filesystems) because it
isn't what it is called in XFS.

> Quite frankly, people are going to understand what "dirquota" means
> and how it behaves intuitively, as opposed to having to understand
> what a project quota is, how project IDs work and what the magical
> "projid_restrict" mount option does and when you'd want to use it.

Naming of the mount option aside, I don't see a tangible difference
in complexity for users to understand what a project ID is whether
they are allowed to change it or not?

Note users *could* still change the project ID of files even if project
quota is enforced by moving the files into a different directory that
has a different project ID assigned. The current XFS/ext4 implementation
returns -EXDEV for rename() between directories with different projid,
forcing userspace to do a file copy.  It isn't clear to me that this
restriction is useful (for ext4 at least, you wrote previously that
there were implementation complexities for XFS for this case), since
userspace doing "copy + unlink" is not really a win in my books.

It seems possible to change the projid directly in ext4 on rename() to
that of the target directory, assuming the user has write permission.
That shouldn't be more complex than chgrp() changing the group quota
of a file, or in case the user currently changes the projid directly
and assigns quota to a new project (ext4_ioctl_setproject() calling
__dquot_transfer(inode, <new projid>))?

> They do the same things - one API is easy to understand for users,
> the other is a horrible "designed by an engineer to meet a specific
> requirement" interface. I know which one I'd prefer as a user...

It isn't clear to me what you are unhappy about?  Is it the mount option
naming?  Feel free to suggest something better.  Some alternatives "setprojid=on/off/setprojid_gid=N", "dirquota/nodirquota.dirquota_gid=N",
or something else?  It doesn't seem to me that having a different *name*
for the mount option turns functionality from "intuitive" to "horrible"
in one shot (especially since the admin only has to set this once), so
I'm genuinely at a loss how "chattr -p <any_projid> <file>" (or equivalent
XFS command) being allowed/forbidden for a regular user is a "horrible"?

Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 873 bytes --]

      reply index

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-12  6:33 Wang Shilong
2019-10-12 20:51 ` Dave Chinner
2019-10-13 16:41 ` Darrick J. Wong
2019-10-16 11:51   ` Wang Shilong
2019-10-16 21:22     ` Dave Chinner
2019-10-16 21:37     ` Darrick J. Wong
2019-10-17  0:28       ` Andreas Dilger
2019-10-17 12:12         ` Theodore Y. Ts'o
2019-10-20 20:19           ` Andreas Dilger
2019-10-20 22:25             ` Theodore Y. Ts'o
2019-10-21 21:15               ` Andreas Dilger
2019-10-21 23:35         ` Dave Chinner
2019-10-23 23:01           ` Andreas Dilger [this message]

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6B0D1F84-0718-4E43-87D4-C8AFC94C0163@dilger.ca \
    --to=adilger@dilger.ca \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=lixi@ddn.com \
    --cc=wangshilong1991@gmail.com \
    --cc=wshilong@ddn.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Fsdevel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-fsdevel/0 linux-fsdevel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-fsdevel linux-fsdevel/ https://lore.kernel.org/linux-fsdevel \
		linux-fsdevel@vger.kernel.org
	public-inbox-index linux-fsdevel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-fsdevel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git