xref: /openbmc/linux/Documentation/admin-guide/nfs/nfs-idmapper.rst (revision 8dd06ef34b6e2f41b29fbf5fc1663780f2524285)
1*fbdcd0b8SDaniel W. S. Almeida=============
2*fbdcd0b8SDaniel W. S. AlmeidaNFS ID Mapper
3*fbdcd0b8SDaniel W. S. Almeida=============
4*fbdcd0b8SDaniel W. S. Almeida
5*fbdcd0b8SDaniel W. S. AlmeidaId mapper is used by NFS to translate user and group ids into names, and to
6*fbdcd0b8SDaniel W. S. Almeidatranslate user and group names into ids.  Part of this translation involves
7*fbdcd0b8SDaniel W. S. Almeidaperforming an upcall to userspace to request the information.  There are two
8*fbdcd0b8SDaniel W. S. Almeidaways NFS could obtain this information: placing a call to /sbin/request-key
9*fbdcd0b8SDaniel W. S. Almeidaor by placing a call to the rpc.idmap daemon.
10*fbdcd0b8SDaniel W. S. Almeida
11*fbdcd0b8SDaniel W. S. AlmeidaNFS will attempt to call /sbin/request-key first.  If this succeeds, the
12*fbdcd0b8SDaniel W. S. Almeidaresult will be cached using the generic request-key cache.  This call should
13*fbdcd0b8SDaniel W. S. Almeidaonly fail if /etc/request-key.conf is not configured for the id_resolver key
14*fbdcd0b8SDaniel W. S. Almeidatype, see the "Configuring" section below if you wish to use the request-key
15*fbdcd0b8SDaniel W. S. Almeidamethod.
16*fbdcd0b8SDaniel W. S. Almeida
17*fbdcd0b8SDaniel W. S. AlmeidaIf the call to /sbin/request-key fails (if /etc/request-key.conf is not
18*fbdcd0b8SDaniel W. S. Almeidaconfigured with the id_resolver key type), then the idmapper will ask the
19*fbdcd0b8SDaniel W. S. Almeidalegacy rpc.idmap daemon for the id mapping.  This result will be stored
20*fbdcd0b8SDaniel W. S. Almeidain a custom NFS idmap cache.
21*fbdcd0b8SDaniel W. S. Almeida
22*fbdcd0b8SDaniel W. S. Almeida
23*fbdcd0b8SDaniel W. S. AlmeidaConfiguring
24*fbdcd0b8SDaniel W. S. Almeida===========
25*fbdcd0b8SDaniel W. S. Almeida
26*fbdcd0b8SDaniel W. S. AlmeidaThe file /etc/request-key.conf will need to be modified so /sbin/request-key can
27*fbdcd0b8SDaniel W. S. Almeidadirect the upcall.  The following line should be added:
28*fbdcd0b8SDaniel W. S. Almeida
29*fbdcd0b8SDaniel W. S. Almeida``#OP	TYPE	DESCRIPTION	CALLOUT INFO	PROGRAM ARG1 ARG2 ARG3 ...``
30*fbdcd0b8SDaniel W. S. Almeida``#======	=======	===============	===============	===============================``
31*fbdcd0b8SDaniel W. S. Almeida``create	id_resolver	*	*		/usr/sbin/nfs.idmap %k %d 600``
32*fbdcd0b8SDaniel W. S. Almeida
33*fbdcd0b8SDaniel W. S. Almeida
34*fbdcd0b8SDaniel W. S. AlmeidaThis will direct all id_resolver requests to the program /usr/sbin/nfs.idmap.
35*fbdcd0b8SDaniel W. S. AlmeidaThe last parameter, 600, defines how many seconds into the future the key will
36*fbdcd0b8SDaniel W. S. Almeidaexpire.  This parameter is optional for /usr/sbin/nfs.idmap.  When the timeout
37*fbdcd0b8SDaniel W. S. Almeidais not specified, nfs.idmap will default to 600 seconds.
38*fbdcd0b8SDaniel W. S. Almeida
39*fbdcd0b8SDaniel W. S. Almeidaid mapper uses for key descriptions::
40*fbdcd0b8SDaniel W. S. Almeida
41*fbdcd0b8SDaniel W. S. Almeida	  uid:  Find the UID for the given user
42*fbdcd0b8SDaniel W. S. Almeida	  gid:  Find the GID for the given group
43*fbdcd0b8SDaniel W. S. Almeida	 user:  Find the user  name for the given UID
44*fbdcd0b8SDaniel W. S. Almeida	group:  Find the group name for the given GID
45*fbdcd0b8SDaniel W. S. Almeida
46*fbdcd0b8SDaniel W. S. AlmeidaYou can handle any of these individually, rather than using the generic upcall
47*fbdcd0b8SDaniel W. S. Almeidaprogram.  If you would like to use your own program for a uid lookup then you
48*fbdcd0b8SDaniel W. S. Almeidawould edit your request-key.conf so it look similar to this:
49*fbdcd0b8SDaniel W. S. Almeida
50*fbdcd0b8SDaniel W. S. Almeida``#OP	TYPE	DESCRIPTION	CALLOUT INFO	PROGRAM ARG1 ARG2 ARG3 ...``
51*fbdcd0b8SDaniel W. S. Almeida``#======	=======	===============	===============	===============================``
52*fbdcd0b8SDaniel W. S. Almeida``create	id_resolver	uid:*	*		/some/other/program %k %d 600``
53*fbdcd0b8SDaniel W. S. Almeida``create	id_resolver	*	*		/usr/sbin/nfs.idmap %k %d 600``
54*fbdcd0b8SDaniel W. S. Almeida
55*fbdcd0b8SDaniel W. S. Almeida
56*fbdcd0b8SDaniel W. S. AlmeidaNotice that the new line was added above the line for the generic program.
57*fbdcd0b8SDaniel W. S. Almeidarequest-key will find the first matching line and corresponding program.  In
58*fbdcd0b8SDaniel W. S. Almeidathis case, /some/other/program will handle all uid lookups and
59*fbdcd0b8SDaniel W. S. Almeida/usr/sbin/nfs.idmap will handle gid, user, and group lookups.
60*fbdcd0b8SDaniel W. S. Almeida
61*fbdcd0b8SDaniel W. S. AlmeidaSee Documentation/security/keys/request-key.rst for more information
62*fbdcd0b8SDaniel W. S. Almeidaabout the request-key function.
63*fbdcd0b8SDaniel W. S. Almeida
64*fbdcd0b8SDaniel W. S. Almeida
65*fbdcd0b8SDaniel W. S. Almeidanfs.idmap
66*fbdcd0b8SDaniel W. S. Almeida=========
67*fbdcd0b8SDaniel W. S. Almeida
68*fbdcd0b8SDaniel W. S. Almeidanfs.idmap is designed to be called by request-key, and should not be run "by
69*fbdcd0b8SDaniel W. S. Almeidahand".  This program takes two arguments, a serialized key and a key
70*fbdcd0b8SDaniel W. S. Almeidadescription.  The serialized key is first converted into a key_serial_t, and
71*fbdcd0b8SDaniel W. S. Almeidathen passed as an argument to keyctl_instantiate (both are part of keyutils.h).
72*fbdcd0b8SDaniel W. S. Almeida
73*fbdcd0b8SDaniel W. S. AlmeidaThe actual lookups are performed by functions found in nfsidmap.h.  nfs.idmap
74*fbdcd0b8SDaniel W. S. Almeidadetermines the correct function to call by looking at the first part of the
75*fbdcd0b8SDaniel W. S. Almeidadescription string.  For example, a uid lookup description will appear as
76*fbdcd0b8SDaniel W. S. Almeida"uid:user@domain".
77*fbdcd0b8SDaniel W. S. Almeida
78*fbdcd0b8SDaniel W. S. Almeidanfs.idmap will return 0 if the key was instantiated, and non-zero otherwise.
79