feat: password change (+)

This works, however there's still stuff to do.

The configuration.nix pam stack is broken, still defaults back to
pam_unix.so if this fails.

The code is now a small mess, I need to make `Client` structs and more
separation.

And I still have to fully understand keycloak and properly use the
clients or configure them.
This commit is contained in:
2026-05-10 18:48:51 +02:00
parent 0cf366d8ff
commit bf952a5dc4
5 changed files with 496 additions and 60 deletions
+23 -1
View File
@@ -18,12 +18,34 @@ You can `cargo doc` to find the documentation for this at `keycloak_pam > args >
With the purpose of being tiny and minimal, the module uses libcurl for the few requests it makes, so HTTP/S and all networking behavior is offloaded to it.
This is also made in rust, which means default `String` and `&str` are guaranteed to be UTF-8 encoded and invalid UTF-8 input might fail. I did try to use OS and C strings for all input, but I recommend still avoiding non-UTF8 input.
This is also made in rust, which means default `String` and `&str` are guaranteed to be UTF-8 encoded and invalid UTF-8 input might fail. I did try to use OS and C strings for all input, but I recommend still avoiding non-UTF8 input. Password change needs to convert to `String` at some point and UTF-8 input is required.
The code should **NEVER** panic (aside from memory management issues), no `unwrap`, `expect` or such methods should ever be used, slice indexing is avoided and errors are gracefully managed.
To check the group, keycloak-pam uses libc's `getgrnam_r`, this takes a buffer we hardcoded to 4 KiB, if there happens to be a group bigger than this, keycloak-pam won't be able to handle and will fail explaining this.
# Policy
Keycloak can be configured in a lot of ways, so it's important to understand how this module will interact with Keylcoak. Otherwise misconfiguration can allow anyone to login as another user.
Think of this as stages, where the first one for all actions is:
Must check the subject user against the configured group. If it's not a member, it will just fallback to the next PAM module.
Here things differ a bit from login to password change:
## Login
This is simple, will only allow login if the password used to log in is not temporary, any error will fail with an error.
The client used for this is still not definitive, currently it uses a client ID and client secret for this, `account` by default, but this might change.
## Registration
Even then, a user might and should be able to login if their account is not set up (e.g. through ssh).
If they try to change their password without having one set up, it won't ask for their current one and will use the admin REST API to set the first one, this one won't be a temporary password and will fully set up their accounts.
# Behavior
To authenticate users, the module uses the endpoint `{BASE_URL}/realms/{realm}/protocol/openid-connect/token` as a configured client. This needs a client ID and its secret that you need to get and configure per realm.