-
Notifications
You must be signed in to change notification settings - Fork 0
How to actually add users to system databases #6
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
Comments
Although I am not entirely sure I understand, I see that in the
A quick test in a Debian container with your scripts seems to work as expected, with that change applied (using Notes:
Hopefully this helps! |
This works for a container, but on a clean Ubuntu 22.04 the situation changes:
group:
|
@xenago could you please try to reproduce issue with our setup? We've prepared dedicated repo with our setup, please checki it libnss_shim_debug docker build . --platform=linux/amd64 -t shim
docker run --platform=linux/amd64 --rm -it shim |
I think I am misunderstanding the issue, can you clarify in what way libnss_shim is not working correctly? In that docker example both it and Your scripts are providing responses to passwd/group/shadow queries, so any users managed that way don't need to be duplicated anywhere else; if you just need users to have home directories, your scripts could create them on-demand. Alternatively, if you do need to store users in the |
we need shim not to imitate users, but to create them in file databases. |
if in the file replace /usr/local/bin/passwd_get_all_entries.sh#!/bin/bash
# https://serverfault.com/questions/1122226/user-account-auto-creation-using-ssh-certificate-authentication
if [ $# -eq 0 ]; then
exit 0
fi
while getopts "u:n:" opt; do
case $opt in
u)
uid=$OPTARG
name=$(find /home -maxdepth 1 -type d -uid $uid | head -1 | cut -d "/" -f 3)
echo "$name:x:$uid:1::/home/$name:/bin/bash"
;;
n)
name=$OPTARG
uid=$(stat -c %u /home/$name 2>/dev/null)
if [[ -z $uid ]]; then
uid=$(stat -c %u /home/* | sort | tail -1 | awk '{print $1+1;}')
fi
sudo_gid=27
useradd $name
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done We need libnss to create users that are not in file. |
With these tweaks, your code seems to work as originally described: https://github.com/xenago/amravyan_libnssh_shim_debug
libnss_shim provides an additional lookup source to nss; if you want to use it modify the content of other nss databases in the middle of an nss call then you will need to make edits to them with tooling that does not itself call that nss source (otherwise that is just recursive since it will end up calling every time). That, or something like adding a method to store state and enable your code to dynamically respond differently based on if user creation is in progress. See the useradd docs where it explains that useradd checks the other databases: https://linux.die.net/man/8/useradd
|
I updated the code to show that concept: amravyan/libnssh_shim_debug@main...xenago:amravyan_libnssh_shim_debug:main |
how to debug problems?
|
As per the docs, debug output is printed to the terminal:
In your comment, the lines
|
Hi!
We've recently discovered your project and related comment. It looks very promising, but we've encountered some problems: we can not correctly create users and groups in systemdb. All created users and groups are actually missing in /etc/passwd and /etc/group and even deleting of previous created users doesn't work fine.
Could you please provide any examples that will add the user to the system db with a command like adduser
All our configs are below
/etc/libnss_shim/config.json
/usr/local/bin/passwd_get_all_entries.sh
/usr/local/bin/group_get_all_entries.sh
/etc/nsswitch.conf
The text was updated successfully, but these errors were encountered: