nixos/keycloak: add realmImportsDirectory config#206729
nixos/keycloak: add realmImportsDirectory config#206729costrouc wants to merge 1 commit intoNixOS:masterfrom
Conversation
a2f2459 to
076d83a
Compare
|
Ready for review. I have tested this out locally. When the realm configuration files are large I'm seeing an error but this seems to be this related to this issue keycloak/keycloak#14733 but is not an issue with this specific PR. |
076d83a to
9eead0e
Compare
|
Hi! Thanks for working on this. One issue I can see arising from this is file/directory permissions - the service runs with A solution could be to treat them the same way we already do ssl certificates / keys and create Additionally, this should be added to the tests. |
|
@talyz thanks for getting back!
This isn't in the PR but keycloak supports environment variables within the json files see https://www.keycloak.org/server/importExport in the
For me personally I like the idea of it overriding every time since this would allow me to declaratively manage users/groups/clients etc but I definitely see how only importing if the realm doesn't exist is valuable (and probably preferred by most). Maybe I add an option for override true/false?
Will work on this once we have the scope down. |
I suppose this could be done with
I would love to support declarative realms as well, but in my mind, that would entail having a |
If I reworked this PR in this way how would you feel? Last time I added a bunch of nixos options there was some pushback due to the complexity. I would be happy to add this similar to how it was done for grafana https://github.com/nixos/nixpkgs/blob/nixpkgs-unstable/nixos/modules/services/monitoring/grafana.nix. The specification is reasonably easy to find with an export. Here is an example with some of the options. let keycloak-realms = pkgs.runCommand "keycloak-realms" {} ''
mkdir -p $out
echo '${builtins.toJSON example-realm}' > $out/example-realm.json
'';
# https://github.com/keycloak/keycloak-demo/blob/master/demo-realm.json
example-realm = {
realm = "demo1";
enabled = true;
users = [{
username = "costrouc";
enabled = true;
firstName = "Chris";
lastName = "Ostrouchov";
credentials = [{
type = "password";
value = "test";
}];
realmRoles = [
"user"
];
}];
groups = [{
name = "admin-group";
path = "/admin-group";
attributes = {
key = ["value1" "value2"];
};
realmRoles = [];
}];
roles = {
realm = [
{
name = "user";
description = "User privileges";
attributes = {};
}
{
name = "admin";
description = "Administrator privileges";
attributes = {};
}
];
};
defaultRoles = [
"user"
];
clients = [
{
clientId = "conda-store";
enabled = true;
publicClient = false;
serviceAccountsEnabled = true;
redirectUris = [
"https://example.com/callback"
];
webOrigins = [
"https://example.com"
];
}
{
clientId = "demo-new-one";
enabled = true;
publicClient = false;
clientAuthenticatorType = "client-secret";
secret = "mysupersecret";
redirectUris = [
"https://demo-new-one.com/callback"
];
}
];
};
in {
services.keycloak.realmImportsDirectory = "${keycloak-realm}";
```} |
Description of changes
Adding an option to the keycloak nixos module that allows for importing/updating realms via nixos configuration. This uses https://www.keycloak.org/server/importExport in keycloak.
Things done
Added option
services.keycloak.realmImportsDirectorysandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes