add principal to the data being tracked by nfsdcld
Subsystems (2)
cover add principal to the data being tracked by nfsdcld
At the spring bakeathon, Chuck suggested that we should store the kerberos principal in addition to the client id string in nfsdcld. The idea is to prevent an illegitimate client from reclaiming another client's opens by supplying that client's id string. This is an initial attempt at doing that.
The first patch adds support for a "GetVersion" upcall which allows nfsd to determine the maximum message version that nfsdcld supports. Right now it's based on the value of CLD_UPCALL_VERSION from cld.h, but I was thinking we may wish to add a command-line option (and an nfs.conf) option to make it possible to use a lower version than CLD_UPCALL_VERSION. My thinking here is that an older nfsdcld daemon won't be compatible with the new database schema... rather than worrying about messing with downgrading the database, just use the command-line option to make it behave like an older daemon.
The second patch adds handling for the v2 Cld_Create and Cld_GraceStart upcalls, which can include the kerberos principal which we'll store along with the client id string in the database. Note that if we're talking to an old kernel that does the v1 upcall, everything still works (we just ignore the new columns in the database).
Question: Why do we have a copy of cld.h in support/include? It seems unnecessary... maybe we should get rid of it so that we're always using the cld.h from the kernel headers?
Scott Mayhew (2):
nfsdcld: add a "GetVersion" upcall
nfsdcld: add support for upcall version 2
support/include/cld.h | 37 +++++- utils/nfsdcld/cld-internal.h | 13 +- utils/nfsdcld/nfsdcld.c | 140 +++++++++++++++++---- utils/nfsdcld/sqlite.c | 238 +++++++++++++++++++++++++++++------ utils/nfsdcld/sqlite.h | 2 + 5 files changed, 366 insertions(+), 64 deletions(-)
Signature · 1 line
2.17.2
RFC PATCH 1/2 nfsdcld: add a "GetVersion" upcall
Add a "GetVersion" upcall to allow the kernel to determine the maximum upcall version that nfsdcld supports.
--- support/include/cld.h | 11 ++++++++- utils/nfsdcld/cld-internal.h | 4 ++- utils/nfsdcld/nfsdcld.c | 47 ++++++++++++++++++++++++++++++------ utils/nfsdcld/sqlite.c | 2 +- 4 files changed, 53 insertions(+), 11 deletions(-)
support/include/cld.h +10 -1
@@ -33,7 +33,8 @@ enum cld_command { Cld_Remove,/* remove record of this cm_id */ Cld_Check,/* is this cm_id allowed? */ Cld_GraceDone,/* grace period is complete */ - Cld_GraceStart, + Cld_GraceStart,/* grace start (upload client records) */ + Cld_GetVersion, /* query max supported upcall version */ };/* representation of long-form NFSv4 client ID */
@@ -51,7 +52,15 @@ struct cld_msg {union {int64_t cm_gracetime;/* grace period start time */ struct cld_name cm_name; +uint8_t cm_version;/* for getting max version */ } __attribute__((packed)) cm_u; } __attribute__((packed)); +struct cld_msg_hdr { +uint8_t cm_vers;/* upcall version */ +uint8_t cm_cmd;/* upcall command */ +int16_t cm_status;/* return code */ +uint32_t cm_xid;/* transaction id */ +} __attribute__((packed)); +#endif /* !_NFSD_CLD_H */
utils/nfsdcld/cld-internal.h +3 -1
@@ -21,7 +21,9 @@struct cld_client {int cl_fd;struct event cl_event; -struct cld_msg cl_msg; +union { +struct cld_msg cl_msg; + } cl_u; };uint64_t current_epoch;
utils/nfsdcld/nfsdcld.c +39 -8
106 lines not on this page · raw message
utils/nfsdcld/sqlite.c +1 -1
@@ -1152,7 +1152,7 @@ sqlite_iterate_recovery(int (*cb)(struct cld_client *clnt), struct cld_client *c {int ret;sqlite3_stmt *stmt =NULL ; -struct cld_msg *cmsg = &clnt->cl_msg; +struct cld_msg *cmsg = &clnt->cl_u.cl_msg;if (recovery_epoch ==0 ) {xlog (D_GENERAL ,"%s: not in grace!" , __func__);
Signature · 1 line
2.17.2
RFC PATCH 2/2 nfsdcld: add support for upcall version 2
In reply to Scott MayhewVersion 2 upcalls will allow the nfsd to include the kerberos principal string (actually the first 1024 bytes of it) in the Cld_Create upcall. If present, the principal will be stored along with the client id string in the database, and will be included in the Cld_GraceStart downcall whenever nfsd restarts.
--- support/include/cld.h | 26 +++- utils/nfsdcld/cld-internal.h | 11 +- utils/nfsdcld/nfsdcld.c | 97 +++++++++++--- utils/nfsdcld/sqlite.c | 236 +++++++++++++++++++++++++++++------ utils/nfsdcld/sqlite.h | 2 + 5 files changed, 316 insertions(+), 56 deletions(-)
support/include/cld.h +25 -1
@@ -23,7 +23,7 @@#define _NFSD_CLD_H/* latest upcall version available */ -#define CLD_UPCALL_VERSION 1 +#define CLD_UPCALL_VERSION 2/* defined by RFC3530 */ #define NFS4_OPAQUE_LIMIT 1024
@@ -43,6 +43,17 @@ struct cld_name {unsigned char cn_id[NFS4_OPAQUE_LIMIT ];/* client-provided */ } __attribute__((packed)); +/* principal of the form servicetype@hostname */ +struct cld_principal { +uint16_t cp_len;/* length of cp_data */ +unsigned char cp_data[NFS4_OPAQUE_LIMIT ];/* princ from cred */ +} __attribute__((packed)); + +struct cld_clntinfo { +struct cld_name cc_name; +struct cld_principal cc_principal; +} __attribute__((packed)); +/* message struct for communication with userspace */ struct cld_msg {uint8_t cm_vers;/* upcall version */
@@ -56,6 +67,19 @@ struct cld_msg { } __attribute__((packed)) cm_u; } __attribute__((packed)); +/* version 2 message includes the principal */ +struct cld_msg_v2 { +uint8_t cm_vers;/* upcall version */ +uint8_t cm_cmd;/* upcall command */ +int16_t cm_status;/* return code */ +uint32_t cm_xid;/* transaction id */ +union { +struct cld_name cm_name; +uint8_t cm_version;/* for getting max version */ +struct cld_clntinfo cm_clntinfo;/* name & princ */ + } __attribute__((packed)) cm_u; +} __attribute__((packed)); +struct cld_msg_hdr {uint8_t cm_vers;/* upcall version */ uint8_t cm_cmd;/* upcall command */
utils/nfsdcld/cld-internal.h +10 -1
@@ -18,11 +18,20 @@#ifndef _CLD_INTERNAL_H_#define _CLD_INTERNAL_H_ +#if CLD_UPCALL_VERSION >=2 +#define UPCALL_VERSION 2 +#else +#define UPCALL_VERSION 1 +#endif +struct cld_client {int cl_fd;struct event cl_event;union { -struct cld_msg cl_msg; +struct cld_msg cl_msg; +#if UPCALL_VERSION >=2 +struct cld_msg_v2 cl_msg_v2; +#endif } cl_u; };
utils/nfsdcld/nfsdcld.c +79 -18
222 lines not on this page · raw message
utils/nfsdcld/sqlite.c +200 -36
368 lines not on this page · raw message
utils/nfsdcld/sqlite.h +2 -0
@@ -24,6 +24,8 @@ struct cld_client;int sqlite_prepare_dbh (const char *topdir);int sqlite_insert_client (const unsigned char *clname,const size_t namelen); +int sqlite_insert_client_and_princ (const unsigned char *clname,const size_t namelen, +const unsigned char *clprinc,const size_t princlen);int sqlite_remove_client (const unsigned char *clname,const size_t namelen);int sqlite_check_client (const unsigned char *clname,const size_t namelen);int sqlite_grace_start (void );
Signature · 1 line
2.17.2