mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-16 06:45:16 +01:00
nixos/keycloak: Split certificatePrivateKeyBundle into two options
Instead of requiring the user to bundle the certificate and private key into a single file, provide separate options for them. This is more in line with most other modules.
This commit is contained in:
parent
dbf91bc2f1
commit
ba00b0946e
2 changed files with 34 additions and 16 deletions
|
@ -85,13 +85,26 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
certificatePrivateKeyBundle = lib.mkOption {
|
sslCertificate = lib.mkOption {
|
||||||
type = lib.types.nullOr lib.types.path;
|
type = lib.types.nullOr lib.types.path;
|
||||||
default = null;
|
default = null;
|
||||||
example = "/run/keys/ssl_cert";
|
example = "/run/keys/ssl_cert";
|
||||||
description = ''
|
description = ''
|
||||||
The path to a PEM formatted bundle of the private key and
|
The path to a PEM formatted certificate to use for TLS/SSL
|
||||||
certificate to use for TLS connections.
|
connections.
|
||||||
|
|
||||||
|
This should be a string, not a Nix path, since Nix paths are
|
||||||
|
copied into the world-readable Nix store.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
sslCertificateKey = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.path;
|
||||||
|
default = null;
|
||||||
|
example = "/run/keys/ssl_key";
|
||||||
|
description = ''
|
||||||
|
The path to a PEM formatted private key to use for TLS/SSL
|
||||||
|
connections.
|
||||||
|
|
||||||
This should be a string, not a Nix path, since Nix paths are
|
This should be a string, not a Nix path, since Nix paths are
|
||||||
copied into the world-readable Nix store.
|
copied into the world-readable Nix store.
|
||||||
|
@ -329,7 +342,7 @@ in
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
(lib.optionalAttrs (cfg.certificatePrivateKeyBundle != null) {
|
(lib.optionalAttrs (cfg.sslCertificate != null && cfg.sslCertificateKey != null) {
|
||||||
"socket-binding-group=standard-sockets"."socket-binding=https".port = cfg.httpsPort;
|
"socket-binding-group=standard-sockets"."socket-binding=https".port = cfg.httpsPort;
|
||||||
"core-service=management"."security-realm=UndertowRealm"."server-identity=ssl" = {
|
"core-service=management"."security-realm=UndertowRealm"."server-identity=ssl" = {
|
||||||
keystore-path = "/run/keycloak/ssl/certificate_private_key_bundle.p12";
|
keystore-path = "/run/keycloak/ssl/certificate_private_key_bundle.p12";
|
||||||
|
@ -662,8 +675,9 @@ in
|
||||||
umask u=rwx,g=,o=
|
umask u=rwx,g=,o=
|
||||||
|
|
||||||
install -T -m 0400 -o keycloak -g keycloak '${cfg.database.passwordFile}' /run/keycloak/secrets/db_password
|
install -T -m 0400 -o keycloak -g keycloak '${cfg.database.passwordFile}' /run/keycloak/secrets/db_password
|
||||||
'' + lib.optionalString (cfg.certificatePrivateKeyBundle != null) ''
|
'' + lib.optionalString (cfg.sslCertificate != null && cfg.sslCertificateKey != null) ''
|
||||||
install -T -m 0400 -o keycloak -g keycloak '${cfg.certificatePrivateKeyBundle}' /run/keycloak/secrets/ssl_cert_pk_bundle
|
install -T -m 0400 -o keycloak -g keycloak '${cfg.sslCertificate}' /run/keycloak/secrets/ssl_cert
|
||||||
|
install -T -m 0400 -o keycloak -g keycloak '${cfg.sslCertificateKey}' /run/keycloak/secrets/ssl_key
|
||||||
'';
|
'';
|
||||||
startPre = ''
|
startPre = ''
|
||||||
set -o errexit -o pipefail -o nounset -o errtrace
|
set -o errexit -o pipefail -o nounset -o errtrace
|
||||||
|
@ -678,10 +692,13 @@ in
|
||||||
|
|
||||||
export JAVA_OPTS=-Djboss.server.config.user.dir=/run/keycloak/configuration
|
export JAVA_OPTS=-Djboss.server.config.user.dir=/run/keycloak/configuration
|
||||||
add-user-keycloak.sh -u admin -p '${cfg.initialAdminPassword}'
|
add-user-keycloak.sh -u admin -p '${cfg.initialAdminPassword}'
|
||||||
'' + lib.optionalString (cfg.certificatePrivateKeyBundle != null) ''
|
'' + lib.optionalString (cfg.sslCertificate != null && cfg.sslCertificateKey != null) ''
|
||||||
pushd /run/keycloak/ssl/
|
pushd /run/keycloak/ssl/
|
||||||
cat /run/keycloak/secrets/ssl_cert_pk_bundle <(echo) /etc/ssl/certs/ca-certificates.crt > allcerts.pem
|
cat /run/keycloak/secrets/ssl_cert <(echo) \
|
||||||
openssl pkcs12 -export -in /run/keycloak/secrets/ssl_cert_pk_bundle -chain \
|
/run/keycloak/secrets/ssl_key <(echo) \
|
||||||
|
/etc/ssl/certs/ca-certificates.crt \
|
||||||
|
> allcerts.pem
|
||||||
|
openssl pkcs12 -export -in /run/keycloak/secrets/ssl_cert -inkey /run/keycloak/secrets/ssl_key -chain \
|
||||||
-name "${cfg.frontendUrl}" -out certificate_private_key_bundle.p12 \
|
-name "${cfg.frontendUrl}" -out certificate_private_key_bundle.p12 \
|
||||||
-CAfile allcerts.pem -passout pass:notsosecretpassword
|
-CAfile allcerts.pem -passout pass:notsosecretpassword
|
||||||
popd
|
popd
|
||||||
|
|
|
@ -115,17 +115,17 @@
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
For HTTPS support, a TLS certificate and private key is
|
HTTPS support requires a TLS/SSL certificate and a private key,
|
||||||
required. They should be <link
|
both <link
|
||||||
xlink:href="https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail">PEM
|
xlink:href="https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail">PEM
|
||||||
formatted</link> and concatenated into a single file. The path
|
formatted</link>. Their paths should be set through <xref
|
||||||
to this file should be configured in
|
linkend="opt-services.keycloak.sslCertificate" /> and <xref
|
||||||
<xref linkend="opt-services.keycloak.certificatePrivateKeyBundle" />.
|
linkend="opt-services.keycloak.sslCertificateKey" />.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<warning>
|
<warning>
|
||||||
<para>
|
<para>
|
||||||
The path should be provided as a string, not a Nix path,
|
The paths should be provided as a strings, not a Nix paths,
|
||||||
since Nix paths are copied into the world readable Nix store.
|
since Nix paths are copied into the world readable Nix store.
|
||||||
</para>
|
</para>
|
||||||
</warning>
|
</warning>
|
||||||
|
@ -195,7 +195,8 @@ services.keycloak = {
|
||||||
<link linkend="opt-services.keycloak.initialAdminPassword">initialAdminPassword</link> = "e6Wcm0RrtegMEHl"; # change on first login
|
<link linkend="opt-services.keycloak.initialAdminPassword">initialAdminPassword</link> = "e6Wcm0RrtegMEHl"; # change on first login
|
||||||
<link linkend="opt-services.keycloak.frontendUrl">frontendUrl</link> = "https://keycloak.example.com/auth";
|
<link linkend="opt-services.keycloak.frontendUrl">frontendUrl</link> = "https://keycloak.example.com/auth";
|
||||||
<link linkend="opt-services.keycloak.forceBackendUrlToFrontendUrl">forceBackendUrlToFrontendUrl</link> = true;
|
<link linkend="opt-services.keycloak.forceBackendUrlToFrontendUrl">forceBackendUrlToFrontendUrl</link> = true;
|
||||||
<link linkend="opt-services.keycloak.certificatePrivateKeyBundle">certificatePrivateKeyBundle</link> = "/run/keys/ssl_cert";
|
<link linkend="opt-services.keycloak.sslCertificate">sslCertificate</link> = "/run/keys/ssl_cert";
|
||||||
|
<link linkend="opt-services.keycloak.sslCertificateKey">sslCertificateKey</link> = "/run/keys/ssl_key";
|
||||||
<link linkend="opt-services.keycloak.database.passwordFile">database.passwordFile</link> = "/run/keys/db_password";
|
<link linkend="opt-services.keycloak.database.passwordFile">database.passwordFile</link> = "/run/keys/db_password";
|
||||||
};
|
};
|
||||||
</programlisting>
|
</programlisting>
|
||||||
|
|
Loading…
Reference in a new issue