From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796311003; b=ZQNAy3jRlsGZQvznDDaRRFBDVyGpqfGjarVt/gUtQi81a9Uo9CEi3o5PskQCGEqL4tC3 HcMXQfVAzmxOAi7oKs9s75C6s9qWCFwypwXH1sRiO2U5XWOZ21PFlgEGic46ZJ6f07zqu DOnS0OLPfRS4W1d3MKNehpX29OXKEnstSSqgPC3rNZNvRq5TSWPyTDdtYq54DYfSNFJOA odV4tb08E8VpulZwrgoDNrd+LDMex5beaTPM0ICd6fLUGw8GT2qtfXhxtIVp6iKEwVMdQ KIgPZYXRAjLj75PE0HYGPDc6/pY4wIrrvDjVn52nlUYbSLsQ//JDM9DW37qsymNzmPg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796311003; h=Received:DKIM-Signature:From:To:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=DBvbDUac4WpOpzAwdzl6GKWZNSuyY9PXEyinjI3TgK0=; b=JP3UxiF32X04KWIBtlZqn7NcovZhmNQoTgkNAiw1ZABbIKaulTLxEyFVht/hi4ken1D5 eRTgaMczwLNBQdMxLTKnPiNZ21OjKbIlc12uIpMnLG8tY5YCmPA2Uz0AaWN0IzhdzxR4o hymAiXJp3aTtY81M7CqUPqh6d9CZ67XG3c3HyHurafCJAN7h3eWhBHasFv8NWD9Sz9zYQ 1/FALGZqSjdXjOnRqbzItDqePgGUjgEbWHr7HWoCanqvSFuZODFHznRBmxUtNi6luOpq2 QJqf184rz+IsxPFau6Lz87xEkCvS1aomJ41R76agIFl8WnjYcfJBZtlUggS+/yZZMZQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XkZ3zOjS; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10188606A32F for ; Thu, 3 Dec 2026 15:16:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XkZ3zOjS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 654DF1F000C1 for ; Thu, 3 Dec 2026 15:16:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796311002; bh=DBvbDUac4WpOpzAwdzl6GKWZNSuyY9PXEyinjI3TgK0=; h=From:To:Subject:Date; b=XkZ3zOjSbJDV3nouRiwqe1YsZQ5rr9U9onhTYqmSQpS9UgyaphYKZqIEFK0xyjU56 pcGgmvk9Q8bkY99g/88Mlhi7oU9qXKZbGDI1nLsvqZlXUxoHVSFwaU2+x2PiR4tLXL bpXQz9lAwEYex0DgTWs3TmrkzJlm4GGwOIrliGjGpxRXzYEA7y+auNcozEynDuz6uE RNFJydxD6IQNG4evKpAodnK9eIAGkK2k8Z6FDHh1UVjK7FhbUDbCQ2cW0akgQ4UEnU Tl1dvAEX1K4IPsfd+4jA2fpXvtGx/o2OQ4zYJCvECNDW9b4+twq5NeLACZSzjrC+w+ 2K8Bt1yCHDJ7A== From: Chuck Lever To: Subject: [PATCH pynfs] server41tests: Test READ and WRITE alongside machine-credential cleanup Date: Thu, 3 Dec 2026 10:16:41 -0500 Message-ID: <20261203151641.406497-1-cel@kernel.org> X-Mailer: git-send-email 2.56.0 X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit RFC 8881 Section 18.35.3 lets a client ID that uses SP4_MACH_CRED send only the operations in spo_must_allow with the machine credential. A server that looks only for one spo_must_allow operation in a COMPOUND lets a READ or WRITE in the same COMPOUND bypass the export's sec= list. No test covers that case. Add MACHCRED1 through MACHCRED8. Each opens a file with krb5p on an export that permits only krb5p. With the krb5i machine credential, each then sends PUTFH, a READ or WRITE, and a CLOSE, OPEN_DOWNGRADE, LOCKU, or DELEGRETURN, and expects NFS4ERR_WRONGSEC. PUTFH followed by the spo_must_allow operation alone has to succeed. MACHCRED7 and MACHCRED8 report UNSUPPORTED when the server does not grant a delegation. Add a --krb5pdir option to name the directory. The tests report UNSUPPORTED without --krb5pdir or --security=krb5i. Signed-off-by: Chuck Lever --- nfs4.1/server41tests/__init__.py | 1 + nfs4.1/server41tests/st_mach_cred.py | 210 +++++++++++++++++++++++++++ nfs4.1/testserver.py | 11 ++ 3 files changed, 222 insertions(+) create mode 100644 nfs4.1/server41tests/st_mach_cred.py diff --git a/nfs4.1/server41tests/__init__.py b/nfs4.1/server41tests/__init__.py index c654212c617e..9141c1ea1933 100644 --- a/nfs4.1/server41tests/__init__.py +++ b/nfs4.1/server41tests/__init__.py @@ -7,6 +7,7 @@ __all__ = ["st_exchange_id.py", # draft 21 "st_reclaim_complete.py", "st_secinfo_no_name.py", "st_secinfo.py", + "st_mach_cred.py", "st_sequence.py", "st_trunking.py", "st_open.py", diff --git a/nfs4.1/server41tests/st_mach_cred.py b/nfs4.1/server41tests/st_mach_cred.py new file mode 100644 index 000000000000..6b97b79f7275 --- /dev/null +++ b/nfs4.1/server41tests/st_mach_cred.py @@ -0,0 +1,210 @@ +from xdrdef.nfs4_const import * +from xdrdef.nfs4_type import state_protect4_a, state_protect_ops4 +from xdrdef.nfs4_type import locker4, lock_owner4, open_to_lock_owner4 +from .environment import check, open_create_file_op, use_obj +from rpc.security import AuthGss +from rpc.gss_const import rpc_gss_svc_integrity, rpc_gss_svc_privacy +import rpc.rpc as rpc +import nfs_ops +op = nfs_ops.NFS4ops() + +def _privacy_cred(env): + """Return a krb5p credential for the principal behind env.cred1""" + c1 = env.c1 + call = c1.make_call_function(c1.c1, 0, c1.default_prog, c1.default_vers) + cred = AuthGss().init_cred(call, target="nfs@%s" % env.opts.server) + cred.service = rpc_gss_svc_privacy + return cred + +def _mach_cred_session(t, env, allow): + """Create a session whose client ID uses SP4_MACH_CRED + + The machine credential is env.cred1, so the test has to run + with --security=krb5i. + """ + if env.opts.krb5pdir is None: + t.fail_support("Needs --krb5pdir") + if env.opts.flavor != rpc.RPCSEC_GSS or \ + env.opts.service != rpc_gss_svc_integrity: + t.fail_support("Needs --security=krb5i") + + protect = state_protect4_a(SP4_MACH_CRED, + spa_mach_ops=state_protect_ops4(0, allow)) + c = env.c1.new_client(env.testname(t), protect=protect) + if c.protect.type != SP4_MACH_CRED: + t.fail_support("Server does not support SP4_MACH_CRED") + sess = c.create_session() + sess.compound([op.reclaim_complete(FALSE)]) + return sess + +def _close(stateid): + return op.close(0, stateid) + +def _open_downgrade(stateid): + return op.open_downgrade(stateid, 0, OPEN4_SHARE_ACCESS_READ, + OPEN4_SHARE_DENY_NONE) + +def _locku(stateid): + return op.locku(WRITE_LT, 0, stateid, 0, NFS4_UINT64_MAX) + +def _delegreturn(stateid): + return op.delegreturn(stateid) + +def _got_deleg(deleg): + return deleg.delegation_type not in (OPEN_DELEGATE_NONE, + OPEN_DELEGATE_NONE_EXT) + +def _io_with_mach_op(t, env, io_op, io_name, mach_op=_close, mach_name="CLOSE"): + """Send PUTFH, io_op(stateid), mach_op(stateid) with the machine + credential + + The client ID uses SP4_MACH_CRED with CLOSE, OPEN_DOWNGRADE, LOCKU, + and DELEGRETURN in spo_must_allow. The file is on an export that + permits only krb5p, and the machine credential is krb5i. RFC 8881 + Section 18.35.3 lets the machine credential send those operations + but not READ or WRITE, so PUTFH has to return + NFS4ERR_WRONGSEC. PUTFH, mach_op(stateid) alone has to succeed. + For LOCKU, a LOCK sent with krb5p supplies the lock stateid. For + DELEGRETURN, the krb5p OPEN asks for a delegation. + """ + sess = _mach_cred_session(t, env, + (1 << OP_CLOSE) | (1 << OP_OPEN_DOWNGRADE) | + (1 << OP_LOCKU) | (1 << OP_DELEGRETURN)) + cred_p = _privacy_cred(env) + + name = env.testname(t) + owner = b"owner_%s" % name + path = env.opts.krb5pdir + [name] + access = OPEN4_SHARE_ACCESS_BOTH + if mach_op is _delegreturn: + access |= OPEN4_SHARE_ACCESS_WANT_ANY_DELEG + ops = open_create_file_op(sess, owner, path, access=access, + open_create=OPEN4_CREATE) + res = sess.compound(ops, credinfo=cred_p) + check(res, msg="OPEN of a file in --krb5pdir with krb5p") + fh = res.resarray[-1].object + stateid = res.resarray[-2].stateid + + mach_stateid = stateid + if mach_op is _delegreturn: + deleg = res.resarray[-2].delegation + if not _got_deleg(deleg): + # The server may not have probed the callback channel yet. + ops = open_create_file_op(sess, owner, path, access=access) + res = sess.compound(ops, credinfo=cred_p) + check(res, msg="Second OPEN of the test file with krb5p") + stateid = res.resarray[-2].stateid + deleg = res.resarray[-2].delegation + if deleg.delegation_type == OPEN_DELEGATE_WRITE: + mach_stateid = deleg.write.stateid + elif deleg.delegation_type == OPEN_DELEGATE_READ: + mach_stateid = deleg.read.stateid + else: + t.fail_support("Server did not grant a delegation") + elif mach_op is _locku: + locker = locker4(open_owner=open_to_lock_owner4(0, stateid, 0, + lock_owner4(0, b"lock_%s" % name)), + new_lock_owner=True) + res = sess.compound([op.putfh(fh), + op.lock(WRITE_LT, False, 0, NFS4_UINT64_MAX, + locker)], + credinfo=cred_p) + check(res, msg="LOCK of the test file with krb5p") + mach_stateid = res.resarray[-1].lock_stateid + + res = sess.compound([op.putfh(fh), io_op(stateid), mach_op(mach_stateid)]) + check(res, NFS4ERR_WRONGSEC, + msg="PUTFH, %s, %s with the krb5i machine credential" % + (io_name, mach_name)) + + res = sess.compound([op.putfh(fh), mach_op(mach_stateid)]) + check(res, msg="PUTFH, %s with the krb5i machine credential" % mach_name) + + if mach_op is not _close: + if mach_op is _open_downgrade: + stateid = res.resarray[-1].open_stateid + res = sess.compound([op.putfh(fh), _close(stateid)]) + check(res, msg="PUTFH, CLOSE with the krb5i machine credential") + + res = sess.compound(use_obj(env.opts.krb5pdir) + [op.remove(name)], + credinfo=cred_p) + check(res, msg="REMOVE of the test file with krb5p") + +def testWriteClose(t, env): + """A spo_must_allow CLOSE does not exempt a WRITE in its COMPOUND + + FLAGS: all + CODE: MACHCRED1 + """ + _io_with_mach_op(t, env, + lambda stateid: op.write(stateid, 0, FILE_SYNC4, b"machcred"), + "WRITE") + +def testReadClose(t, env): + """A spo_must_allow CLOSE does not exempt a READ in its COMPOUND + + FLAGS: all + CODE: MACHCRED2 + """ + _io_with_mach_op(t, env, lambda stateid: op.read(stateid, 0, 4096), "READ") + +def testWriteOpenDowngrade(t, env): + """A spo_must_allow OPEN_DOWNGRADE does not exempt a WRITE in its + COMPOUND + + FLAGS: all + CODE: MACHCRED3 + """ + _io_with_mach_op(t, env, + lambda stateid: op.write(stateid, 0, FILE_SYNC4, b"machcred"), + "WRITE", _open_downgrade, "OPEN_DOWNGRADE") + +def testReadOpenDowngrade(t, env): + """A spo_must_allow OPEN_DOWNGRADE does not exempt a READ in its + COMPOUND + + FLAGS: all + CODE: MACHCRED4 + """ + _io_with_mach_op(t, env, lambda stateid: op.read(stateid, 0, 4096), + "READ", _open_downgrade, "OPEN_DOWNGRADE") + +def testWriteLocku(t, env): + """A spo_must_allow LOCKU does not exempt a WRITE in its COMPOUND + + FLAGS: all + CODE: MACHCRED5 + """ + _io_with_mach_op(t, env, + lambda stateid: op.write(stateid, 0, FILE_SYNC4, b"machcred"), + "WRITE", _locku, "LOCKU") + +def testReadLocku(t, env): + """A spo_must_allow LOCKU does not exempt a READ in its COMPOUND + + FLAGS: all + CODE: MACHCRED6 + """ + _io_with_mach_op(t, env, lambda stateid: op.read(stateid, 0, 4096), + "READ", _locku, "LOCKU") + +def testWriteDelegreturn(t, env): + """A spo_must_allow DELEGRETURN does not exempt a WRITE in its + COMPOUND + + FLAGS: deleg all + CODE: MACHCRED7 + """ + _io_with_mach_op(t, env, + lambda stateid: op.write(stateid, 0, FILE_SYNC4, b"machcred"), + "WRITE", _delegreturn, "DELEGRETURN") + +def testReadDelegreturn(t, env): + """A spo_must_allow DELEGRETURN does not exempt a READ in its + COMPOUND + + FLAGS: deleg all + CODE: MACHCRED8 + """ + _io_with_mach_op(t, env, lambda stateid: op.read(stateid, 0, 4096), + "READ", _delegreturn, "DELEGRETURN") diff --git a/nfs4.1/testserver.py b/nfs4.1/testserver.py index f38279b36cba..a769fe360547 100755 --- a/nfs4.1/testserver.py +++ b/nfs4.1/testserver.py @@ -151,6 +151,9 @@ def scan_options(p): help="Use SERVER:/DIRPATH for ROFS tests") g.add_option("--usefh", default=None, metavar="FH", help="Use FH for certain specialized tests") + g.add_option("--krb5pdir", default=None, metavar="DIRPATH", + help="Use SERVER:/DIRPATH, on an export that permits " + "only sec=krb5p, for the SP4_MACH_CRED tests") p.add_option_group(g) g = OptionGroup(p, "Inter-server copy options", @@ -296,6 +299,14 @@ def main(): p.error(e) setattr(opt, attr, [comp for comp in path if comp]) + # --krb5pdir has no default, so the tests that need it can skip + if opt.krb5pdir is not None: + try: + path = nfs4lib.path_components(os.fsencode(opt.krb5pdir)) + except Exception as e: + p.error(e) + opt.krb5pdir = [comp for comp in path if comp] + # Check that --security option is valid # FIXME STUB tempd = {'none' : (rpc.AUTH_NONE, 0), -- 2.56.0