Skip to content
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

Implement zfs native ACL support #9709

Closed
wants to merge 7 commits into from
Closed

Implement zfs native ACL support #9709

wants to merge 7 commits into from

Conversation

pbhenson
Copy link
Contributor

@pbhenson pbhenson commented Dec 10, 2019

Motivation and Context

No explanation is required as to why it would be nice to support the native zfs ACL

This will resolve #4966

Description

Implement ZFS native ACL support, including both an illumos compatible and a FreeBSD compatible library API for accessing them, along with ports of the FreeBSD getfacl/setfacl utilities (installed prefaced with a z) to manage them. Also provide the standard linux system.nfs4_acl extended attribute to provide an NFSv4 compatible API that can both be used with existing NFSv4 ACL management tools and hopefully future NFS server integration.

Note that this pull request has been repurposed from its original intent and is currently only partially complete.

How Has This Been Tested?

This was built and tested under Ubuntu 18.04 LTS; only a limited amount of testing to verify basic functionality has been performed at this point pending review of the code.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [X ] New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

@behlendorf behlendorf added the Status: Code Review Needed Ready for review and testing label Dec 10, 2019
@behlendorf behlendorf self-requested a review December 10, 2019 01:31
@behlendorf
Copy link
Contributor

@pbhenson thank you, I'll add it to my review list so we can move this forward.

Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for rebasing and updating this. We expect to be able to merge the bulk of the remaining FreeBSD work in January. At which point, we'll be in a good position to be able to move forward with this work. As part of that we'll be able to add back the ZTS ACL tests and run them on FreeBSD as part of the CI. I expect we'll be able to round up some help for that work. Thanks for your patience!

man/man8/zfsprops.8 Outdated Show resolved Hide resolved
include/sys/fs/zfs.h Outdated Show resolved Hide resolved
include/sys/zfs_acl.h Outdated Show resolved Hide resolved
lib/libspl/include/sys/acl.h Outdated Show resolved Hide resolved
cmd/nfsidmap.zfs/nfsidmap.zfs Outdated Show resolved Hide resolved
config/kernel-acl.m4 Outdated Show resolved Hide resolved
if (ITOZSB(ip)->z_acl_type == ZFS_ACLTYPE_NFS4ACL) {
/*
* XXX - mask could also include
* MAY_APPEND|MAY_ACCESS|MAY_OPEN|MAY_CHDIR, do we care?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there analogs for these we should be using? For example, does MAY_APPEND map to V_APPEND?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an excellent question which I hoped a reviewer with more detailed knowledge of the linux vfs implementation might have an opinion on :).

V_APPEND is a flag, which can be passed in the third argument to zfs_access. If this flag is set, and the initial permission checks in zfs_zaccess fail it calls zfs_zaccess_append. I think if the mask includes MAY_APPEND we could pass in the V_APPEND flag; but I'm not completely sure of the interaction. On the zfs side, I think it asks for write privs, which might fail, but then if you want write privs just for appending, it lets you through if the ACL allows ACE_APPEND_DATA. On the linux side, does it call with both MAY_WRITE and MAY_APPEND for an appended write or just MAY_APPEND?

Also, zfs_access in this use ends up calling zfs_zaccess_rwx which converts the mode bits mask to acl format bits and then calls zfs_zaccess. If it would work out better we could convert the modes bits and other flags into acl format bits directly in zpl_permission and bypass the conversion in zfs_zaccess_rwx by passing V_ACE_MASK in the flags for the call to zfs_access.

I just don't know enough about the linux vfs permission layer to say what's best at this point 8-/.

@pbhenson
Copy link
Contributor Author

We expect to be able to merge the bulk of the remaining FreeBSD work in January. At which point, we'll be in a good position to be able to move forward with this work. As part of that we'll be able to add back the ZTS ACL tests and run them on FreeBSD as part of the CI. I expect we'll be able to round up some help for that work. Thanks for your patience!

Sounds good, thanks. Let me know when you're ready and I'll rebase again, looks like there's already a conflict :).

@codecov
Copy link

codecov bot commented Dec 20, 2019

Codecov Report

Merging #9709 into master will increase coverage by 1%.
The diff coverage is 82%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #9709     +/-   ##
=========================================
+ Coverage      79%      79%     +1%     
=========================================
  Files         379      418     +39     
  Lines      114915   123781   +8866     
=========================================
+ Hits        90213    97934   +7721     
- Misses      24702    25847   +1145
Flag Coverage Δ
#kernel 80% <ø> (+1%) ⬆️
#user 67% <82%> (-1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ed53cc3...3a41121. Read the comment docs.

ghost pushed a commit to zfsonfreebsd/ZoF that referenced this pull request Jan 29, 2020
This replaces the placeholder ZFS_PROP_PRIVATE with ZFS_PROP_ACLMODE,
matching what is done in the NFSv4 ACLs PR (openzfs#9709).

On FreeBSD we hide ZFS_PROP_ACLTYPE, while on Linux we hide
ZFS_PROP_ACLMODE.

The tests already assume this arrangement.

Signed-off-by: Ryan Moeller <[email protected]>
@ghost ghost mentioned this pull request Jan 29, 2020
12 tasks
ghost pushed a commit to zfsonfreebsd/ZoF that referenced this pull request Jan 30, 2020
This replaces the placeholder ZFS_PROP_PRIVATE with ZFS_PROP_ACLMODE,
matching what is done in the NFSv4 ACLs PR (openzfs#9709).

On FreeBSD we hide ZFS_PROP_ACLTYPE, while on Linux we hide
ZFS_PROP_ACLMODE.

The tests already assume this arrangement.

Signed-off-by: Ryan Moeller <[email protected]>
behlendorf pushed a commit that referenced this pull request Feb 4, 2020
This replaces the placeholder ZFS_PROP_PRIVATE with ZFS_PROP_ACLMODE,
matching what is done in the NFSv4 ACLs PR (#9709).

On FreeBSD we hide ZFS_PROP_ACLTYPE, while on Linux we hide
ZFS_PROP_ACLMODE.

The tests already assume this arrangement.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #9913
@pbhenson
Copy link
Contributor Author

pbhenson commented Apr 7, 2020

How goes the FreeBSD integration? Any thoughts on a timeline for following up on this pull request?

It looks like there are a few merge conflicts that popped up, but they seems pretty simple to resolve. Let me know when you're ready and I'll rebase.

Thanks...

@behlendorf
Copy link
Contributor

@pbhenson thanks for your patience. We're close to wrapping up the FreeBSD merge, once it happens I'll be sure to let you know so you can get this rebased.

@behlendorf
Copy link
Contributor

@pbhenson the FreeBSD work has been merged to master and the CI enabled for FreeBSD 12 and head. You can rebase this PR on master and add back the existing ACL tests. It shouldn't be too hard to get them passing in the FreeBSD CI bots. I'm sure @freqlabs who updated the test suite for FreeBSD would be happy to help. For now you'll want to add the new tests to the tests/runfiles/freebsd.run run file. Once we have things working for Linux they can be moved to the common runfile.

@pbhenson
Copy link
Contributor Author

Ok, rebased, compiles successfully and seems to function ok. Still pending the opinions of the various buildbots :).

@behlendorf, are there any other changes required in terms of code review of the implementation, or are we just stalled on the tests now?

@freqlabs, would love some input on how to move forward with the test component. Were any of the freebsd ACL tests integrated? I still only see the posix subdir in the functional/acl directory in the tests. illumos uses ls/chmod for the native ZFS ACL, freebsd uses getfacl/setfacl, and at least for now linux is stuck using nfs4_getfacl/nfs4_setfacl. The NFSv4 ACL tools only support NFSv4 ACL semantics, which is a slight subset of the actual ZFS ACL which might complicate test compatibility across the three.

I'm assuming we don't want to just import all the illumos tests? They have some for chmod options which aren't applicable, tests of ls output syntax, tests of cp/cpio/tar copying ACLs, find being able to search by ACL, etc. Maybe we could start by reviewing the tests in the trivial/nontrivial directories in the functional/acl area of illumos and deciding which ones need to be migrated? Then after that we need to sort out what kind of intermediary layer we want between the tests and the underlying commands in each OS used for ZFS ACL manipulation.

Thanks...

@codecov-io
Copy link

codecov-io commented Apr 29, 2020

Codecov Report

Merging #9709 into master will decrease coverage by 0.25%.
The diff coverage is 10.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9709      +/-   ##
==========================================
- Coverage   79.46%   79.21%   -0.26%     
==========================================
  Files         389      389              
  Lines      123120   123345     +225     
==========================================
- Hits        97834    97703     -131     
- Misses      25286    25642     +356     
Flag Coverage Δ
#kernel 79.69% <10.61%> (-0.19%) ⬇️
#user 65.53% <ø> (-0.35%) ⬇️
Impacted Files Coverage Δ
include/os/linux/kernel/linux/xattr_compat.h 100.00% <ø> (ø)
module/os/linux/zfs/zpl_inode.c 94.90% <ø> (ø)
module/os/linux/zfs/zpl_super.c 82.40% <0.00%> (-1.56%) ⬇️
module/zcommon/zfs_prop.c 99.40% <ø> (ø)
module/os/linux/zfs/zpl_xattr.c 60.02% <9.25%> (-23.24%) ⬇️
module/os/linux/zfs/zfs_vfsops.c 75.62% <40.00%> (-0.22%) ⬇️
module/os/linux/zfs/policy.c 54.05% <50.00%> (-0.12%) ⬇️
module/zfs/zfs_ioctl.c 86.35% <100.00%> (+0.03%) ⬆️
module/zfs/vdev_indirect.c 72.50% <0.00%> (-8.84%) ⬇️
cmd/ztest/ztest.c 77.13% <0.00%> (-3.98%) ⬇️
... and 53 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e5d41d...5af54c9. Read the comment docs.

@behlendorf
Copy link
Contributor

are there any other changes required in terms of code review of the implementation, or are we just stalled on the tests now?

I'd definitely like to carefully go over the changes in e24fd00 again, but skimming over them now I don't expect any major new issues. There's also nothing holding up merging these illumos commits from my point of view. If we could get just these commits in a PR (this one or a new one) and verify the bots are happy. Then we could focus on the Linux changes and adding the tests.

OpenZFS 742 - Resurrect the ZFS "aclmode" property OpenZFS 664 - Umas…
OpenZFS 3254 - add support in zfs for aclmode=restricted
OpenZFS 6764 - zfs issues with inheritance flags during chmod(2)
OpenZFS 8984 - fix for 6764 breaks ACL inheritance
OpenZFS 6762 - POSIX write should imply DELETE_CHILD on directories
OpenZFS 6765 - zfs_zaccess_delete() comments do not accurately

Maybe we could start by reviewing the tests in the trivial/nontrivial directories in the functional/acl area of illumos and deciding which ones need to be migrated? Then after that we need to sort out what kind of intermediary layer we want between the tests and the underlying commands in each OS used for ZFS ACL manipulation.

This sounds like a good approach to me.

@pbhenson
Copy link
Contributor Author

There's also nothing holding up merging these illumos commits from my point of view. If we could get just these commits in a PR (this one or a new one) and verify the bots are happy.

Cool, PR #10266 created. Once that's merged I'll rebase this one to only have the NFSv4 ACL commit.

@ghost
Copy link

ghost commented Apr 30, 2020

@pbhenson no NFSv4 tests have been added yet. Take a look at the xattr tests and wrappers in libtest for an example of how to approach the getfacl/setfacl abstraction.

The ZFS acl tests in FreeBSD are here: https://github.com/freebsd/freebsd/tree/master/tests/sys/cddl/zfs/tests/acl
I'm not familiar with them at all, but maybe @asomers can speak to how much of that we actually run in FreeBSD.

@behlendorf
Copy link
Contributor

Once that's merged I'll rebase this one to only have the NFSv4 ACL commit.

@pbhenson merged.

@pbhenson
Copy link
Contributor Author

pbhenson commented May 5, 2020

@pbhenson merged.

Ok, I updated the pull request with just the NFSv4 ACL patch. Although there are a bunch of upstream merge commits in it too that my git-fu doesn't know how to get rid of? Do they matter?

@pbhenson
Copy link
Contributor Author

pbhenson commented May 5, 2020

The ZFS acl tests in FreeBSD are here: https://github.com/freebsd/freebsd/tree/master/tests/sys/cddl/zfs/tests/acl
I'm not familiar with them at all, but maybe @asomers can speak to how much of that we actually run in FreeBSD.

Based on: https://github.com/freebsd/freebsd/blob/master/tests/sys/cddl/zfs/tests/acl/acl_common.kshlib -

# FreeBSD doesn't support ZFS extended attributes.  It also doesn't support the
# same ACL mechanisms Solaris does for testing.
if [[ $os_name != "FreeBSD" ]]; then
	export ZFS_XATTR="true"
	export ZFS_ACL="true"
else
	log_note "On FreeBSD most xattr and ACL tests are disabled"
fi

It looks like the freebsd implementation doesn't currently run any of the upstream illumos tests...

@ghost
Copy link

ghost commented May 5, 2020

We certainly have support for the extended attributes and ACLs so it must just be the tests specifically that are incompatible.
These are likely the ones we use then, just a shame they're not drop-in compatible with ZTS:
https://github.com/freebsd/freebsd/tree/master/tests/sys/acl

@trasz
Copy link

trasz commented May 5, 2020

FreeBSD accesses ACLs through the ACL kernel API (see https://www.freebsd.org/cgi/man.cgi?query=acl_get_file&apropos=0&sektion=0&manpath=FreeBSD+12.1-RELEASE+and+Ports&arch=default&format=html), not by pretending they are xattr.

IIRC subfiles (alternate data streams) from ZFS are mapped to FreeBSD xattr.

@pbhenson
Copy link
Contributor Author

pbhenson commented May 5, 2020

We certainly have support for the extended attributes and ACLs so it must just be the tests specifically that are incompatible.

Yeah, like I mentioned earlier, a lot of them test specific functionality of illumos commands like ls/chmod/tar/cpio etc. And the ones that do test general zfs functionality use ls/chmod to do so.

These are likely the ones we use then, just a shame they're not drop-in compatible with ZTS:
https://github.com/freebsd/freebsd/tree/master/tests/sys/acl

I think these were mentioned before in this pull request commentary, or maybe in the previous one. They do seem more "general acl" in terms of coverage than the illumos ones.

@ahrens
Copy link
Member

ahrens commented Jun 29, 2020

@behlendorf Great idea. While we're at it, can we change the help message/documentation to use off or disabled instead of noacl?

@behlendorf
Copy link
Contributor

can we change the help message/documentation to use off or disabled instead of noacl?

Absolutely. It looks like off would be the most consistent with the other properties and wouldn't suffer from any ambiguity.

@pbhenson
Copy link
Contributor Author

Absolutely. It looks like off would be the most consistent with the other properties and wouldn't suffer from any ambiguity.

You want to handle this in this PR along with the nfs4 acl support, or clean up the posixacl naming stuff in a separate small PR?

@behlendorf
Copy link
Contributor

@pbhenson my understanding is that @freqlabs was volunteering to handle this cleanup/renaming in new small PR.

@ghost ghost mentioned this pull request Jun 30, 2020
12 tasks
pbhenson added 2 commits July 16, 2020 05:21
implementation. First, change the acl_type to native rather than
nfs4acl. Also, while the nfs4 compatible xattr will be optional
depending upon kernel configuration, the native zfs acl xattr will
always be available. Finally, don't override the system nfs4 domain when
mapping users/groups for the nfs4 zfs xattr, as that will no longer be
the primary interface to modify them and it will be simpler for hopeful
future NFS server integration port to use the same domain as the NFS
server.
@anodos325
Copy link
Contributor

anodos325 commented Oct 12, 2020

Isn't it problematic that this appears to be implementing NFS40 ACLs rather than NFS41 ACLs per https://tools.ietf.org/html/rfc5661#section-6.2.2?

Natively ZFS has NFS41 ACLs, and that is what FreeBSD supports as well. This nuance is of particular importance if you wish to use these ACLs in Samba. The NFS41 inheritance bits that are masked off to generate a NFS40 ACL (RFC3530) are vitally important to provide correct ACL inheritance behavior for an SMB server.

@pbhenson
Copy link
Contributor Author

Isn't it problematic that this appears to be implementing NFS40 ACLs rather than NFS41 ACLs per https://tools.ietf.org/html/rfc5661#section-6.2.2?

AFAIK the linux client tools for NFS ACLs don't support the 4.1 extensions? However, if you review the comments you will see that in addition to the NFSv4 ACL support there is now also going to be a native interface to them which will support the full feature set of ZFS. This will be compatible with the sun acl interface so samba should be able to just work more or less. I'm hoping to get back to this project over Christmas break.

@anodos325
Copy link
Contributor

Isn't it problematic that this appears to be implementing NFS40 ACLs rather than NFS41 ACLs per https://tools.ietf.org/html/rfc5661#section-6.2.2?

AFAIK the linux client tools for NFS ACLs don't support the 4.1 extensions? However, if you review the comments you will see that in addition to the NFSv4 ACL support there is now also going to be a native interface to them which will support the full feature set of ZFS. This will be compatible with the sun acl interface so samba should be able to just work more or less. I'm hoping to get back to this project over Christmas break.

Samba with vfs_nfs4acl_xattr defaults to an NDR-encoded NFSv41 ACL written to the nfs4acl xattr. I'm also thinking in terms of rsync usage as well. Exposing the ACL as an xattr like this will probably allow us to rsync ACLs via rsync's xattr options, but having rsync strip permissions information (which is what will happen if we don't present the full ACL) is somewhat problematic.

BTW, I believe you also may need to set vsecp.vsa_mask = VSA_ACE in __zpl_xattr_nfs4acl_set().

@ismell
Copy link

ismell commented Nov 6, 2020

I'm curious if vfs_fruit fruit:nfs_aces = yes will automatically start using the ZFS NFSv4 ACLs once this bug is fixed.

@anodos325
Copy link
Contributor

anodos325 commented Nov 6, 2020

I'm curious if vfs_fruit fruit:nfs_aces = yes will automatically start using the ZFS NFSv4 ACLs once this bug is fixed.

No. That parameter does something different. It exposes the underlying POSIX mode through special ACL entries using MS-NFS SIDs (S-1-5-88-*). See here: https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/hh509017(v=ws.10)?redirectedfrom=MSDN

A MacOS SMB server / Client uses these special ACEs / SIDs to look under the covers at the underlying POSIX mode so that it can accurately present it to the SMB client, and also allows client to effectively chmod() through an SMB2 setinfo request.

The correct approach to Samba integration will be to either (1) present the NFSv4 ACL as a suitable xattr and use vfs_nfs4acl_xatt, (2) use acl() and facl() shim like libsunacl/FreeBSD, or (3) develop a new VFS module. (1) or (2) is preferable to something new.

There are nuances to how vfs_fruit interacts with ACLs that will need to be accounted for when configuring a samba server (typically on ZFS it's better to turn off the NFS ACEs because a stray client chmod() can really muck up permissions), but that goes pretty far outside the scope of this merge request.

jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
This replaces the placeholder ZFS_PROP_PRIVATE with ZFS_PROP_ACLMODE,
matching what is done in the NFSv4 ACLs PR (openzfs#9709).

On FreeBSD we hide ZFS_PROP_ACLTYPE, while on Linux we hide
ZFS_PROP_ACLMODE.

The tests already assume this arrangement.

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: Alexander Motin <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes openzfs#9913
@bghira
Copy link

bghira commented Apr 4, 2021

happy anniversary to this pull request!

@mjyu51
Copy link

mjyu51 commented Jun 26, 2021

Is this still moving to the working direction? Or is NFSv4 ACL already in the source tree?

@pbhenson
Copy link
Contributor Author

Is this still moving to the working direction? Or is NFSv4 ACL already in the source tree?

Unfortunately I've been tied up with day job work and paid contract jobs and haven't had time for fun hobby coding for quite a while :(. It's still on my list to get back to at some point but I don't have a timeframe right now, sorry.

@ghost
Copy link

ghost commented Jul 6, 2021

For those interested, we have a complete implementation of NFSv4 ACLs for ZFS on Linux here: truenas#10
We have also made the kernel modifications for first class support here: truenas/linux#2

@nohnaimer
Copy link

Hi everyone,
Can anyone share a manual on how to build and install an openzfs package with this zfs native ACL support?
I have rockylinux 8.4 with full work samba 4 and I need zfs acl.
Thank you!

@jumbi77
Copy link
Contributor

jumbi77 commented Jan 27, 2022

For those interested, we have a complete implementation of NFSv4 ACLs for ZFS on Linux here: truenas#10
We have also made the kernel modifications for first class support here: truenas/linux#2

Nice! Awesome work! Its been already merged the forked truenas repo, are you guys @freqlabs @anodos325 planing to upstream it to the main OpenZFS repo? What feature would be awesome.

@ghost
Copy link

ghost commented Jan 27, 2022

For those interested, we have a complete implementation of NFSv4 ACLs for ZFS on Linux here: truenas#10
We have also made the kernel modifications for first class support here: truenas/linux#2

Nice! Awesome work! Its been already merged the forked truenas repo, are you guys @freqlabs @anodos325 planing to upstream it to the main OpenZFS repo? What feature would be awesome.

Yes

@pbhenson
Copy link
Contributor Author

Yes

Cool. I'm glad somebody had the time and resources to finish this up :).

I'm sure openzfs will be glad to take this, but what about the upstream kernel? The last time I asked about ACL changes, they said if there wasn't an in-kernel filesystem that would use a feature, they didn't want it 8-/.

@ghost ghost mentioned this pull request Mar 9, 2022
13 tasks
@fracklaus
Copy link

happy anniversary to this pull request!

Happy anniversary again. Time is flying...

@pbhenson
Copy link
Contributor Author

pbhenson commented Apr 5, 2023

This pull request has been superceded by PR #13186 so I'm going to close it. Sorry I ended up leaving it half done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Code Review Needed Ready for review and testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement NFS4 ACL support