Create a new libsubid
Closes #154
Currently this has three functions: one which returns the
list of subuid ranges for a user, one returning the subgids,
and one which frees the ranges lists.
I might be mistaken about what -disable-man means; some of
the code suggests it means just don't re-generate them, but
not totally ignore them. But that doesn't seem to really work,
so let's just ignore man/ when -disable-man.
Remove --disable-shared. I'm not sure why it was there, but it stems
from long, long ago, and I suspect it comes from some ancient
toolchain bug.
Create a tests/run_some, a shorter version of run_all. I'll
slowly add tests to this as I verify they work, then I can
work on fixing the once which don't.
Also, don't touch man/ if not -enable-man.
Changelog:
Apr 22: change the subid list api as recomended by Dan Walsh.
Apr 23: implement get_subid_owner
Apr 24: implement range add/release
Apr 25: finish tests and rebase
May 10: make @owner const
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2020-04-19 04:33:54 +05:30
|
|
|
#include <sys/types.h>
|
2021-05-29 08:32:16 +05:30
|
|
|
#include <stdio.h>
|
subids: support nsswitch
Closes #154
When starting any operation to do with subuid delegation, check
nsswitch for a module to use. If none is specified, then use
the traditional /etc/subuid and /etc/subgid files.
Currently only one module is supported, and there is no fallback
to the files on errors. Several possibilities could be considered:
1. in case of connection error, fall back to files
2. in case of unknown user, also fall back to files
etc...
When non-files nss module is used, functions to edit the range
are not supported. It may make sense to support it, but it also
may make sense to require another tool to be used.
libsubordinateio also uses the nss_ helpers. This is how for instance
lxc could easily be converted to supporting nsswitch.
Add a set of test cases, including a dummy libsubid_zzz module. This
hardcodes values such that:
'ubuntu' gets 200000 - 300000
'user1' gets 100000 - 165536
'error' emulates an nss module error
'unknown' emulates a user unknown to the nss module
'conn' emulates a connection error ot the nss module
Changes to libsubid:
Change the list_owner_ranges api: return a count instead of making the array
null terminated.
This is a breaking change, so bump the libsubid abi major number.
Rename free_subuid_range and free_subgid_range to ungrant_subuid_range,
because otherwise it's confusing with free_subid_ranges which frees
memory.
Run libsubid tests in jenkins
Switch argument order in find_subid_owners
Move the db locking into subordinateio.c
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2021-02-01 05:08:20 +05:30
|
|
|
#include <stdbool.h>
|
Create a new libsubid
Closes #154
Currently this has three functions: one which returns the
list of subuid ranges for a user, one returning the subgids,
and one which frees the ranges lists.
I might be mistaken about what -disable-man means; some of
the code suggests it means just don't re-generate them, but
not totally ignore them. But that doesn't seem to really work,
so let's just ignore man/ when -disable-man.
Remove --disable-shared. I'm not sure why it was there, but it stems
from long, long ago, and I suspect it comes from some ancient
toolchain bug.
Create a tests/run_some, a shorter version of run_all. I'll
slowly add tests to this as I verify they work, then I can
work on fixing the once which don't.
Also, don't touch man/ if not -enable-man.
Changelog:
Apr 22: change the subid list api as recomended by Dan Walsh.
Apr 23: implement get_subid_owner
Apr 24: implement range add/release
Apr 25: finish tests and rebase
May 10: make @owner const
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2020-04-19 04:33:54 +05:30
|
|
|
|
|
|
|
#ifndef SUBID_RANGE_DEFINED
|
|
|
|
#define SUBID_RANGE_DEFINED 1
|
2021-12-05 19:27:39 +05:30
|
|
|
#define SUBID_ABI_VERSION @LIBSUBID_ABI_MAJOR@.@LIBSUBID_ABI_MINOR@.@LIBSUBID_ABI_MICRO@
|
|
|
|
#define SUBID_ABI_MAJOR @LIBSUBID_ABI_MAJOR@
|
|
|
|
#define SUBID_ABI_MINOR @LIBSUBID_ABI_MINOR@
|
|
|
|
#define SUBID_ABI_MICRO @LIBSUBID_ABI_MICRO@
|
2021-05-17 08:17:05 +05:30
|
|
|
|
|
|
|
/* subid_range is just a starting point and size of a range */
|
|
|
|
struct subid_range {
|
|
|
|
unsigned long start;
|
|
|
|
unsigned long count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* subordinage_range is a subid_range plus an owner, representing
|
|
|
|
* a range in /etc/subuid or /etc/subgid */
|
Create a new libsubid
Closes #154
Currently this has three functions: one which returns the
list of subuid ranges for a user, one returning the subgids,
and one which frees the ranges lists.
I might be mistaken about what -disable-man means; some of
the code suggests it means just don't re-generate them, but
not totally ignore them. But that doesn't seem to really work,
so let's just ignore man/ when -disable-man.
Remove --disable-shared. I'm not sure why it was there, but it stems
from long, long ago, and I suspect it comes from some ancient
toolchain bug.
Create a tests/run_some, a shorter version of run_all. I'll
slowly add tests to this as I verify they work, then I can
work on fixing the once which don't.
Also, don't touch man/ if not -enable-man.
Changelog:
Apr 22: change the subid list api as recomended by Dan Walsh.
Apr 23: implement get_subid_owner
Apr 24: implement range add/release
Apr 25: finish tests and rebase
May 10: make @owner const
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2020-04-19 04:33:54 +05:30
|
|
|
struct subordinate_range {
|
|
|
|
const char *owner;
|
|
|
|
unsigned long start;
|
|
|
|
unsigned long count;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum subid_type {
|
|
|
|
ID_TYPE_UID = 1,
|
|
|
|
ID_TYPE_GID = 2
|
|
|
|
};
|
|
|
|
|
subids: support nsswitch
Closes #154
When starting any operation to do with subuid delegation, check
nsswitch for a module to use. If none is specified, then use
the traditional /etc/subuid and /etc/subgid files.
Currently only one module is supported, and there is no fallback
to the files on errors. Several possibilities could be considered:
1. in case of connection error, fall back to files
2. in case of unknown user, also fall back to files
etc...
When non-files nss module is used, functions to edit the range
are not supported. It may make sense to support it, but it also
may make sense to require another tool to be used.
libsubordinateio also uses the nss_ helpers. This is how for instance
lxc could easily be converted to supporting nsswitch.
Add a set of test cases, including a dummy libsubid_zzz module. This
hardcodes values such that:
'ubuntu' gets 200000 - 300000
'user1' gets 100000 - 165536
'error' emulates an nss module error
'unknown' emulates a user unknown to the nss module
'conn' emulates a connection error ot the nss module
Changes to libsubid:
Change the list_owner_ranges api: return a count instead of making the array
null terminated.
This is a breaking change, so bump the libsubid abi major number.
Rename free_subuid_range and free_subgid_range to ungrant_subuid_range,
because otherwise it's confusing with free_subid_ranges which frees
memory.
Run libsubid tests in jenkins
Switch argument order in find_subid_owners
Move the db locking into subordinateio.c
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2021-02-01 05:08:20 +05:30
|
|
|
enum subid_status {
|
|
|
|
SUBID_STATUS_SUCCESS = 0,
|
|
|
|
SUBID_STATUS_UNKNOWN_USER = 1,
|
|
|
|
SUBID_STATUS_ERROR_CONN = 2,
|
|
|
|
SUBID_STATUS_ERROR = 3,
|
|
|
|
};
|
|
|
|
|
2022-01-19 16:09:53 +05:30
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-05-09 04:12:14 +05:30
|
|
|
/*
|
2021-11-27 22:19:03 +05:30
|
|
|
* subid_init: initialize libsubid
|
2021-05-09 04:12:14 +05:30
|
|
|
*
|
|
|
|
* @progname: Name to display as program. If NULL, then "(libsubid)" will be
|
|
|
|
* shown in error messages.
|
|
|
|
* @logfd: Open file pointer to pass error messages to. If NULL, then
|
|
|
|
* /dev/null will be opened and messages will be sent there. The
|
|
|
|
* default if libsubid_init() is not called is stderr (2).
|
|
|
|
*
|
|
|
|
* This function does not need to be called. If not called, then the defaults
|
|
|
|
* will be used.
|
|
|
|
*
|
|
|
|
* Returns false if an error occurred.
|
|
|
|
*/
|
2021-11-27 22:19:03 +05:30
|
|
|
bool subid_init(const char *progname, FILE *logfd);
|
2021-05-09 04:12:14 +05:30
|
|
|
|
2021-04-15 20:22:29 +05:30
|
|
|
/*
|
2021-11-27 22:19:03 +05:30
|
|
|
* subid_get_uid_ranges: return a list of UID ranges for a user
|
2021-04-15 20:22:29 +05:30
|
|
|
*
|
|
|
|
* @owner: username being queried
|
2021-05-22 22:46:50 +05:30
|
|
|
* @ranges: a pointer to an array of subid_range structs in which the result
|
|
|
|
* will be returned.
|
|
|
|
*
|
|
|
|
* The caller must free(ranges) when done.
|
2021-04-15 20:22:29 +05:30
|
|
|
*
|
|
|
|
* returns: number of ranges found, ir < 0 on error.
|
|
|
|
*/
|
2021-11-27 22:19:03 +05:30
|
|
|
int subid_get_uid_ranges(const char *owner, struct subid_range **ranges);
|
2021-04-15 20:22:29 +05:30
|
|
|
|
|
|
|
/*
|
2021-11-27 22:19:03 +05:30
|
|
|
* subid_get_gid_ranges: return a list of GID ranges for a user
|
2021-04-15 20:22:29 +05:30
|
|
|
*
|
|
|
|
* @owner: username being queried
|
2021-05-22 22:46:50 +05:30
|
|
|
* @ranges: a pointer to an array of subid_range structs in which the result
|
|
|
|
* will be returned.
|
2021-04-15 20:22:29 +05:30
|
|
|
*
|
2021-05-22 22:46:50 +05:30
|
|
|
* The caller must free(ranges) when done.
|
2021-04-15 20:22:29 +05:30
|
|
|
*
|
2021-05-22 22:46:50 +05:30
|
|
|
* returns: number of ranges found, ir < 0 on error.
|
2021-04-15 20:22:29 +05:30
|
|
|
*/
|
2021-11-27 22:19:03 +05:30
|
|
|
int subid_get_gid_ranges(const char *owner, struct subid_range **ranges);
|
2021-04-15 20:22:29 +05:30
|
|
|
|
|
|
|
/*
|
2021-11-27 22:19:03 +05:30
|
|
|
* subid_get_uid_owners: return a list of uids to which the given uid has been
|
2021-04-15 20:22:29 +05:30
|
|
|
* delegated.
|
|
|
|
*
|
|
|
|
* @uid: The subuid being queried
|
|
|
|
* @owners: a pointer to an array of uids into which the results are placed.
|
|
|
|
* The returned array must be freed by the caller.
|
|
|
|
*
|
|
|
|
* Returns the number of uids returned, or < 0 on error.
|
|
|
|
*/
|
2021-11-27 22:19:03 +05:30
|
|
|
int subid_get_uid_owners(uid_t uid, uid_t **owner);
|
2021-04-15 20:22:29 +05:30
|
|
|
|
|
|
|
/*
|
2021-11-27 22:19:03 +05:30
|
|
|
* subid_get_gid_owners: return a list of uids to which the given gid has been
|
2021-04-15 20:22:29 +05:30
|
|
|
* delegated.
|
|
|
|
*
|
|
|
|
* @uid: The subgid being queried
|
|
|
|
* @owners: a pointer to an array of uids into which the results are placed.
|
|
|
|
* The returned array must be freed by the caller.
|
|
|
|
*
|
|
|
|
* Returns the number of uids returned, or < 0 on error.
|
|
|
|
*/
|
2021-11-27 22:19:03 +05:30
|
|
|
int subid_get_gid_owners(gid_t gid, uid_t **owner);
|
2021-04-15 20:22:29 +05:30
|
|
|
|
|
|
|
/*
|
2021-11-27 22:19:03 +05:30
|
|
|
* subid_grant_uid_range: assign a subuid range to a user
|
2021-04-15 20:22:29 +05:30
|
|
|
*
|
|
|
|
* @range: pointer to a struct subordinate_range detailing the UID range
|
|
|
|
* to allocate. ->owner must be the username, and ->count must be
|
|
|
|
* filled in. ->start is ignored, and will contain the start
|
|
|
|
* of the newly allocated range, upon success.
|
|
|
|
*
|
|
|
|
* Returns true if the delegation succeeded, false otherwise. If true,
|
|
|
|
* then the range from (range->start, range->start + range->count) will
|
|
|
|
* be delegated to range->owner.
|
|
|
|
*/
|
2021-11-27 22:19:03 +05:30
|
|
|
bool subid_grant_uid_range(struct subordinate_range *range, bool reuse);
|
2021-04-15 20:22:29 +05:30
|
|
|
|
|
|
|
/*
|
2021-11-27 22:19:03 +05:30
|
|
|
* subid_grant_gid_range: assign a subgid range to a user
|
2021-04-15 20:22:29 +05:30
|
|
|
*
|
|
|
|
* @range: pointer to a struct subordinate_range detailing the GID range
|
|
|
|
* to allocate. ->owner must be the username, and ->count must be
|
|
|
|
* filled in. ->start is ignored, and will contain the start
|
|
|
|
* of the newly allocated range, upon success.
|
|
|
|
*
|
|
|
|
* Returns true if the delegation succeeded, false otherwise. If true,
|
|
|
|
* then the range from (range->start, range->start + range->count) will
|
|
|
|
* be delegated to range->owner.
|
|
|
|
*/
|
2021-11-27 22:19:03 +05:30
|
|
|
bool subid_grant_gid_range(struct subordinate_range *range, bool reuse);
|
2021-04-15 20:22:29 +05:30
|
|
|
|
|
|
|
/*
|
2021-11-27 22:19:03 +05:30
|
|
|
* subid_ungrant_uid_range: remove a subuid allocation.
|
2021-04-15 20:22:29 +05:30
|
|
|
*
|
|
|
|
* @range: pointer to a struct subordinate_range detailing the UID allocation
|
|
|
|
* to remove.
|
|
|
|
*
|
|
|
|
* Returns true if successful, false if it failed, for instance if the
|
|
|
|
* delegation did not exist.
|
|
|
|
*/
|
2021-11-27 22:19:03 +05:30
|
|
|
bool subid_ungrant_uid_range(struct subordinate_range *range);
|
2021-04-15 20:22:29 +05:30
|
|
|
|
|
|
|
/*
|
2021-11-27 22:19:03 +05:30
|
|
|
* subid_ungrant_gid_range: remove a subgid allocation.
|
2021-04-15 20:22:29 +05:30
|
|
|
*
|
|
|
|
* @range: pointer to a struct subordinate_range detailing the GID allocation
|
|
|
|
* to remove.
|
|
|
|
*
|
|
|
|
* Returns true if successful, false if it failed, for instance if the
|
|
|
|
* delegation did not exist.
|
|
|
|
*/
|
2021-11-27 22:19:03 +05:30
|
|
|
bool subid_ungrant_gid_range(struct subordinate_range *range);
|
2021-04-15 20:22:29 +05:30
|
|
|
|
2022-01-19 16:09:53 +05:30
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Create a new libsubid
Closes #154
Currently this has three functions: one which returns the
list of subuid ranges for a user, one returning the subgids,
and one which frees the ranges lists.
I might be mistaken about what -disable-man means; some of
the code suggests it means just don't re-generate them, but
not totally ignore them. But that doesn't seem to really work,
so let's just ignore man/ when -disable-man.
Remove --disable-shared. I'm not sure why it was there, but it stems
from long, long ago, and I suspect it comes from some ancient
toolchain bug.
Create a tests/run_some, a shorter version of run_all. I'll
slowly add tests to this as I verify they work, then I can
work on fixing the once which don't.
Also, don't touch man/ if not -enable-man.
Changelog:
Apr 22: change the subid list api as recomended by Dan Walsh.
Apr 23: implement get_subid_owner
Apr 24: implement range add/release
Apr 25: finish tests and rebase
May 10: make @owner const
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2020-04-19 04:33:54 +05:30
|
|
|
#define SUBID_NFIELDS 3
|
|
|
|
#endif
|