-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
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
nixos/nfs: Allow Kerberized NFS #73989
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
59a0e58
nixos/nfs: convert test to python
kwohlfahrt 7b83883
nfs-utils: build svcgssd
kwohlfahrt ea55a2d
linux: patch request-key binary path
kwohlfahrt 0dce66a
nixos/nfs: test nfs with kerberos authentication
kwohlfahrt b1c10bc
nfs: set up request-key for id mapping
kwohlfahrt e0b9b5f
keyutils: patch to allow symlinks in config dir
kwohlfahrt e71bd33
nfs-utils: link nfs tests
Mic92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ version ? 4 | ||
, system ? builtins.currentSystem | ||
, pkgs ? import ../../.. { inherit system; } | ||
}: { | ||
simple = import ./simple.nix { inherit version system pkgs; }; | ||
} // pkgs.lib.optionalAttrs (version == 4) { | ||
# TODO: Test kerberos + nfsv3 | ||
kerberos = import ./kerberos.nix { inherit version system pkgs; }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import ../make-test-python.nix ({ pkgs, lib, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
krb5 = | ||
{ enable = true; | ||
domain_realm."nfs.test" = "NFS.TEST"; | ||
libdefaults.default_realm = "NFS.TEST"; | ||
realms."NFS.TEST" = | ||
{ admin_server = "server.nfs.test"; | ||
kdc = "server.nfs.test"; | ||
}; | ||
}; | ||
|
||
hosts = | ||
'' | ||
192.168.1.1 client.nfs.test | ||
192.168.1.2 server.nfs.test | ||
''; | ||
|
||
users = { | ||
users.alice = { | ||
isNormalUser = true; | ||
name = "alice"; | ||
uid = 1000; | ||
}; | ||
}; | ||
|
||
in | ||
|
||
{ | ||
name = "nfsv4-with-kerberos"; | ||
|
||
nodes = { | ||
client = { lib, ... }: | ||
{ inherit krb5 users; | ||
|
||
networking.extraHosts = hosts; | ||
networking.domain = "nfs.test"; | ||
networking.hostName = "client"; | ||
|
||
fileSystems = lib.mkVMOverride | ||
{ "/data" = { | ||
device = "server.nfs.test:/"; | ||
fsType = "nfs"; | ||
options = [ "nfsvers=4" "sec=krb5p" "noauto" ]; | ||
}; | ||
}; | ||
}; | ||
|
||
server = { lib, ...}: | ||
{ inherit krb5 users; | ||
|
||
networking.extraHosts = hosts; | ||
networking.domain = "nfs.test"; | ||
networking.hostName = "server"; | ||
|
||
networking.firewall.allowedTCPPorts = [ | ||
111 # rpc | ||
2049 # nfs | ||
88 # kerberos | ||
749 # kerberos admin | ||
]; | ||
|
||
services.kerberos_server.enable = true; | ||
services.kerberos_server.realms = | ||
{ "NFS.TEST".acl = | ||
[ { access = "all"; principal = "admin/admin"; } ]; | ||
}; | ||
|
||
services.nfs.server.enable = true; | ||
services.nfs.server.createMountPoints = true; | ||
services.nfs.server.exports = | ||
'' | ||
/data *(rw,no_root_squash,fsid=0,sec=krb5p) | ||
''; | ||
}; | ||
}; | ||
|
||
testScript = | ||
'' | ||
server.succeed("mkdir -p /data/alice") | ||
server.succeed("chown alice:users /data/alice") | ||
|
||
# set up kerberos database | ||
server.succeed( | ||
"kdb5_util create -s -r NFS.TEST -P master_key", | ||
"systemctl restart kadmind.service kdc.service", | ||
) | ||
server.wait_for_unit(f"kadmind.service") | ||
server.wait_for_unit(f"kdc.service") | ||
|
||
# create principals | ||
server.succeed( | ||
"kadmin.local add_principal -randkey nfs/server.nfs.test", | ||
"kadmin.local add_principal -randkey nfs/client.nfs.test", | ||
"kadmin.local add_principal -pw admin_pw admin/admin", | ||
"kadmin.local add_principal -pw alice_pw alice", | ||
) | ||
|
||
# add principals to server keytab | ||
server.succeed("kadmin.local ktadd nfs/server.nfs.test") | ||
server.succeed("systemctl start rpc-gssd.service rpc-svcgssd.service") | ||
server.wait_for_unit(f"rpc-gssd.service") | ||
server.wait_for_unit(f"rpc-svcgssd.service") | ||
|
||
client.wait_for_unit("network-online.target") | ||
|
||
# add principals to client keytab | ||
client.succeed("echo admin_pw | kadmin -p admin/admin ktadd nfs/client.nfs.test") | ||
client.succeed("systemctl start rpc-gssd.service") | ||
client.wait_for_unit("rpc-gssd.service") | ||
|
||
with subtest("nfs share mounts"): | ||
client.succeed("systemctl restart data.mount") | ||
client.wait_for_unit("data.mount") | ||
|
||
with subtest("permissions on nfs share are enforced"): | ||
client.fail("su alice -c 'ls /data'") | ||
client.succeed("su alice -c 'echo alice_pw | kinit'") | ||
client.succeed("su alice -c 'ls /data'") | ||
|
||
client.fail("su alice -c 'echo bla >> /data/foo'") | ||
client.succeed("su alice -c 'echo bla >> /data/alice/foo'") | ||
server.succeed("test -e /data/alice/foo") | ||
|
||
with subtest("uids/gids are mapped correctly on nfs share"): | ||
ids = client.succeed("stat -c '%U %G' /data/alice").split() | ||
expected = ["alice", "users"] | ||
assert ids == expected, f"ids incorrect: got {ids} expected {expected}" | ||
''; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import ../make-test-python.nix ({ pkgs, version ? 4, ... }: | ||
|
||
let | ||
|
||
client = | ||
{ pkgs, ... }: | ||
{ fileSystems = pkgs.lib.mkVMOverride | ||
[ { mountPoint = "/data"; | ||
# nfs4 exports the export with fsid=0 as a virtual root directory | ||
device = if (version == 4) then "server:/" else "server:/data"; | ||
fsType = "nfs"; | ||
options = [ "vers=${toString version}" ]; | ||
} | ||
]; | ||
networking.firewall.enable = false; # FIXME: only open statd | ||
}; | ||
|
||
in | ||
|
||
{ | ||
name = "nfs"; | ||
meta = with pkgs.stdenv.lib.maintainers; { | ||
maintainers = [ eelco ]; | ||
}; | ||
|
||
nodes = | ||
{ client1 = client; | ||
client2 = client; | ||
|
||
server = | ||
{ ... }: | ||
{ services.nfs.server.enable = true; | ||
services.nfs.server.exports = | ||
'' | ||
/data 192.168.1.0/255.255.255.0(rw,no_root_squash,no_subtree_check,fsid=0) | ||
''; | ||
services.nfs.server.createMountPoints = true; | ||
networking.firewall.enable = false; # FIXME: figure out what ports need to be allowed | ||
}; | ||
}; | ||
|
||
testScript = | ||
'' | ||
import time | ||
|
||
server.wait_for_unit("nfs-server") | ||
server.succeed("systemctl start network-online.target") | ||
server.wait_for_unit("network-online.target") | ||
|
||
start_all() | ||
|
||
client1.wait_for_unit("data.mount") | ||
client1.succeed("echo bla > /data/foo") | ||
server.succeed("test -e /data/foo") | ||
|
||
client2.wait_for_unit("data.mount") | ||
client2.succeed("echo bla > /data/bar") | ||
server.succeed("test -e /data/bar") | ||
|
||
with subtest("restarting 'nfs-server' works correctly"): | ||
server.succeed("systemctl restart nfs-server") | ||
# will take 90 seconds due to the NFS grace period | ||
client2.succeed("echo bla >> /data/bar") | ||
|
||
with subtest("can get a lock"): | ||
client2.succeed("time flock -n -s /data/lock true") | ||
|
||
with subtest("client 2 fails to acquire lock held by client 1"): | ||
client1.succeed("flock -x /data/lock -c 'touch locked; sleep 100000' &") | ||
client1.wait_for_file("locked") | ||
client2.fail("flock -n -s /data/lock true") | ||
|
||
with subtest("client 2 obtains lock after resetting client 1"): | ||
client2.succeed( | ||
"flock -x /data/lock -c 'echo acquired; touch locked; sleep 100000' >&2 &" | ||
) | ||
client1.crash() | ||
client1.start() | ||
client2.wait_for_file("locked") | ||
|
||
with subtest("locks survive server reboot"): | ||
client1.wait_for_unit("data.mount") | ||
server.shutdown() | ||
server.start() | ||
client1.succeed("touch /data/xyzzy") | ||
client1.fail("time flock -n -s /data/lock true") | ||
|
||
with subtest("unmounting during shutdown happens quickly"): | ||
t1 = time.monotonic() | ||
client1.shutdown() | ||
duration = time.monotonic() - t1 | ||
assert duration < 30, f"shutdown took too long ({duration} seconds)" | ||
''; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comments here that tell what happens on a higher level could all be
subtest
s, so this information even appears in the log.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry i already stated this in another comment in the same PR and didn't remember.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed most of the other ones. Here, this is really set-up code that is not related to the functionality under test. Is
subtest
intended for this use as well?