-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[FEATURE]: Kibana to watch certificate changes and reload them on-the-fly #54368
Comments
Pinging @elastic/kibana-operations (Team:Operations) |
|
I'm running Kibana 7.5.1 and a SIGHUP does not reload the certs. Here is the error after the SIGHUP.
|
It shoudn't need a |
Agreed, and that was my expectation but it's not the case. Kibana is not detecting certificate changes and consequently not reloading them. Currently I need a full restart to get them updated. |
Hacky workaround until it's implemented, (if we're lucky enough!): use |
That's what I have in place atm, so once a month (we have short lived certs) we do a full restart to reload the cert. SIGHUP or SIGUSR1 doesn't work! |
I can't understand why this ticket hasn't been resolved yet... Everybody who uses LetsEncrypt to update the certificates faces with this reloading issue. Taking into account that Elasticsearch instance is already capable of on-the-fly reloading (and all other major open source servers I know), it should be a piece of cake to fix. |
We're trying to move to automating Let's Encrypt certificate renewals since most browsers have announced their intent to limit the lifetime of certificates. However, rebooting Kibana once a month is not an option. Read more here: Mozilla Joins Apple, Google in Reducing TLS Certificate Lifespans. |
This is affecting us all, and more and more, since the whole industry is moving towards shorter lifetimes on certificates (not just Let's Encrypt). Either a way for kibana to automatically reload certificates, or at least a trigger which starts a restart (optional of course). |
Pinging @elastic/kibana-core (Team:Core) |
Pinging @elastic/kibana-security (Team:Security) |
Any updates on this? Even with two year certificates this is becoming a real issue for us. |
Is a real issue for everyone who uses Kibana, Elastic and so on with all security recommendations in place. |
PRs are always welcome @pestevao |
Still restart required or at least signals are fixed ? Find nothing in documentation about one or the other. |
@pgayvallet since you mentioned PRs are welcome, could you give directions on the places in the codebase that would need to be touched for such a contribution? That would make it easier for new contributors |
Sure thing, my apologies for not having done it sooner. First notable information, HAPI is the underlying HTTP library we're using on Kibana. Technical pointersFrom config definition to consumption to utilization to create the HAPI server: SSL config definitionThis is the kibana/packages/kbn-server-http-tools/src/ssl/ssl_config.ts Lines 22 to 78 in 265cc76
which is then used when building the global
kibana/packages/kbn-server-http-tools/src/ssl/ssl_config.ts Lines 82 to 85 in 265cc76
Config creation / consumptionThe
Note that atm, even if the config is an observable (therefore can be hot-reloaded via
kibana/packages/core/http/core-http-server-internal/src/http_service.ts Lines 160 to 163 in 2aa8e6d
Which is one of the things that will have to change. Conversion to HAPI primitiveOur configuration is then converted to its HAPI version to be able to pass it down to the underlying HAPI server instantiation: kibana/packages/core/http/core-http-server-internal/src/http_server.ts Lines 216 to 219 in 8727c68
The SSL config conversion, in particular, is done within kibana/packages/kbn-server-http-tools/src/get_server_options.ts Lines 53 to 72 in 265cc76
Starting the HAPI serverThe underlying kibana/packages/core/http/core-http-server-internal/src/http_server.ts Lines 289 to 295 in 8727c68
What must be done1. Having the
|
const { registerRouter, ...serverContract } = await this.httpServer.setup( | |
config, | |
deps.executionContext | |
); |
That way, the HttpServer
will be able to subscribe to configuration changes.
2. Having the HttpServer
react to config changes
That's the tricky part. Here to, we have identified two options (but there might be more):
a.
have the underlying HAPI server hot-reload the certificate changesb.
fully recreate the server when the certificate changes
a. Hot reloading the underlying HAPI server
recommended
Last time we checked, HAPI doesn't support hot reloading natively. However, it should still be possible to access the raw http
/tls
server it creates under the hood to use either setSecureContext or SNICallback.
HAPI.Server
has a listener: http.Server
property that should be a tls.Server
when tls
is configured.
This would be our recommended approach: find a way to use either of those low-level APIs to perform the certificate hot-reloading operation.
b. Fully recreating the server
discouraged
The alternative would be to fully stop and recreate the server when a config change is encountered. This would be significantly more complex though, given I think we would need to fully reinstantiate a new HAPI.server
instance, which would break the assumption we have within the http domain layer that this instance is not replaceable.
E.g this is the way we're registering a onRequest
hook today:
kibana/packages/core/http/core-http-server-internal/src/http_server.ts
Lines 491 to 500 in 8727c68
private registerOnPreRouting(fn: OnPreRoutingHandler) { | |
if (this.server === undefined) { | |
throw new Error('Server is not created yet'); | |
} | |
if (this.stopping || this.stopped) { | |
this.log.warn(`registerOnPreRouting called after stop`); | |
} | |
this.server.ext('onRequest', adoptToHapiOnRequest(fn, this.log)); | |
} |
Or the way we channel the server contract though our service contract:
kibana/packages/core/http/core-http-server-internal/src/http_service.ts
Lines 167 to 168 in 2aa8e6d
this.internalSetup = { | |
...serverContract, |
Going down the "fully recreate the server" path would mean that we would be forced to change the way all those APIs function to make sure that the new server gets everything re-registered and that the upstream contracts are updated to use the new reference.
TLDR
-
find a way to properly hot reload TLS certificates on a vanilla
HAPI
server -
then follow the same approach for Kibana's internal HAPI wrapper
- use the already-in-place
SIGHUP
-based configuration reload - have the server react to those signals to recreate the TLS configuration and forward it to the HAPI server.
- use the already-in-place
I'm available for any further questions.
I opened #171823 that should close the issue (and happy thanksgiving). |
) ## Summary Fix elastic#54368 Add support for hot reloading the Kibana server's TLS configuration, using the same `SIGHUP`-based reload signal, as already implemented for other parts of the Kibana configuration (e.g `logging`) **Note:** - hot reloading is only supported for the server TLS configuration (`server.ssl`), not for the whole `server.*` config prefix - swaping the certificate files (without modifying the kibana config itself) is supported - it is not possible to toggle TLS (enabling or disabling) without restarting Kibana - hot reloading requires to force the process to reload its configuration by sending a `SIGHUP` signal ### Example / how to test #### Before ```yaml server.ssl.enabled: true server.ssl.certificate: /path-to-kibana/packages/kbn-dev-utils/certs/kibana.crt server.ssl.key: /path-to-kibana/packages/kbn-dev-utils/certs/kibana.key ``` <img width="550" alt="Screenshot 2023-11-23 at 15 11 28" src="https://github.com/elastic/kibana/assets/1532934/1226d161-a9f2-4d62-a3de-37161829f187"> #### Changing the config ```yaml server.ssl.enabled: true server.ssl.certificate: /path-to-kibana/packages/kbn-dev-utils/certs/elasticsearch.crt server.ssl.key: /path-to-kibana/packages/kbn-dev-utils/certs/elasticsearch.key ``` ```bash kill -SIGHUP {KIBANA_PID} ``` <img width="865" alt="Screenshot 2023-11-23 at 15 18 21" src="https://github.com/elastic/kibana/assets/1532934/c9412b2e-d70e-4cf0-8eaf-4db70a45af60"> #### After <img width="547" alt="Screenshot 2023-11-23 at 15 18 43" src="https://github.com/elastic/kibana/assets/1532934/c839f04f-4adb-456d-a174-4f0ebd5c234c"> ## Release notes It is now possible to hot reload Kibana's TLS (`server.ssl`) configuration by updating it and then sending a `SIGHUP` signal to the Kibana process. Note that TLS cannot be toggled (disabled/enabled) that way, and that hot reload only works for the TLS configuration, not other properties of the `server` config prefix. --------- Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit 87213e7) # Conflicts: # src/core/tsconfig.json
) ## Summary Fix elastic#54368 Add support for hot reloading the Kibana server's TLS configuration, using the same `SIGHUP`-based reload signal, as already implemented for other parts of the Kibana configuration (e.g `logging`) **Note:** - hot reloading is only supported for the server TLS configuration (`server.ssl`), not for the whole `server.*` config prefix - swaping the certificate files (without modifying the kibana config itself) is supported - it is not possible to toggle TLS (enabling or disabling) without restarting Kibana - hot reloading requires to force the process to reload its configuration by sending a `SIGHUP` signal ### Example / how to test #### Before ```yaml server.ssl.enabled: true server.ssl.certificate: /path-to-kibana/packages/kbn-dev-utils/certs/kibana.crt server.ssl.key: /path-to-kibana/packages/kbn-dev-utils/certs/kibana.key ``` <img width="550" alt="Screenshot 2023-11-23 at 15 11 28" src="https://github.com/elastic/kibana/assets/1532934/1226d161-a9f2-4d62-a3de-37161829f187"> #### Changing the config ```yaml server.ssl.enabled: true server.ssl.certificate: /path-to-kibana/packages/kbn-dev-utils/certs/elasticsearch.crt server.ssl.key: /path-to-kibana/packages/kbn-dev-utils/certs/elasticsearch.key ``` ```bash kill -SIGHUP {KIBANA_PID} ``` <img width="865" alt="Screenshot 2023-11-23 at 15 18 21" src="https://github.com/elastic/kibana/assets/1532934/c9412b2e-d70e-4cf0-8eaf-4db70a45af60"> #### After <img width="547" alt="Screenshot 2023-11-23 at 15 18 43" src="https://github.com/elastic/kibana/assets/1532934/c839f04f-4adb-456d-a174-4f0ebd5c234c"> ## Release notes It is now possible to hot reload Kibana's TLS (`server.ssl`) configuration by updating it and then sending a `SIGHUP` signal to the Kibana process. Note that TLS cannot be toggled (disabled/enabled) that way, and that hot reload only works for the TLS configuration, not other properties of the `server` config prefix. --------- Co-authored-by: kibanamachine <[email protected]>
…tic#171823) (elastic#171907) # Backport This will backport the following commits from `main` to `8.11`: - [[HTTP Server] support TLS config hot reload via `SIGHUP` (elastic#171823)](elastic#171823) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Pierre Gayvallet","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-11-24T09:05:27Z","message":"[HTTP Server] support TLS config hot reload via `SIGHUP` (elastic#171823)\n\n## Summary\r\n\r\nFix https://github.com/elastic/kibana/issues/54368\r\n\r\nAdd support for hot reloading the Kibana server's TLS configuration,\r\nusing the same `SIGHUP`-based reload signal, as already implemented for\r\nother parts of the Kibana configuration (e.g `logging`)\r\n\r\n**Note:**\r\n- hot reloading is only supported for the server TLS configuration\r\n(`server.ssl`), not for the whole `server.*` config prefix\r\n- swaping the certificate files (without modifying the kibana config\r\nitself) is supported\r\n- it is not possible to toggle TLS (enabling or disabling) without\r\nrestarting Kibana\r\n- hot reloading requires to force the process to reload its\r\nconfiguration by sending a `SIGHUP` signal\r\n\r\n### Example / how to test\r\n\r\n#### Before\r\n\r\n```yaml\r\nserver.ssl.enabled: true\r\nserver.ssl.certificate: /path-to-kibana/packages/kbn-dev-utils/certs/kibana.crt\r\nserver.ssl.key: /path-to-kibana/packages/kbn-dev-utils/certs/kibana.key\r\n```\r\n\r\n<img width=\"550\" alt=\"Screenshot 2023-11-23 at 15 11 28\"\r\nsrc=\"https://github.com/elastic/kibana/assets/1532934/1226d161-a9f2-4d62-a3de-37161829f187\">\r\n\r\n#### Changing the config\r\n\r\n```yaml\r\nserver.ssl.enabled: true\r\nserver.ssl.certificate: /path-to-kibana/packages/kbn-dev-utils/certs/elasticsearch.crt\r\nserver.ssl.key: /path-to-kibana/packages/kbn-dev-utils/certs/elasticsearch.key\r\n```\r\n\r\n```bash\r\nkill -SIGHUP {KIBANA_PID}\r\n```\r\n\r\n<img width=\"865\" alt=\"Screenshot 2023-11-23 at 15 18 21\"\r\nsrc=\"https://github.com/elastic/kibana/assets/1532934/c9412b2e-d70e-4cf0-8eaf-4db70a45af60\">\r\n\r\n#### After\r\n\r\n<img width=\"547\" alt=\"Screenshot 2023-11-23 at 15 18 43\"\r\nsrc=\"https://github.com/elastic/kibana/assets/1532934/c839f04f-4adb-456d-a174-4f0ebd5c234c\">\r\n\r\n## Release notes\r\n\r\nIt is now possible to hot reload Kibana's TLS (`server.ssl`)\r\nconfiguration by updating it and then sending a `SIGHUP` signal to the\r\nKibana process.\r\n\r\nNote that TLS cannot be toggled (disabled/enabled) that way, and that\r\nhot reload only works for the TLS configuration, not other properties of\r\nthe `server` config prefix.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"87213e7efe4420b0edf72d471056fe78cbd9df60","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Feature:http","Team:Core","backport:prev-minor","v8.12.0"],"number":171823,"url":"https://github.com/elastic/kibana/pull/171823","mergeCommit":{"message":"[HTTP Server] support TLS config hot reload via `SIGHUP` (elastic#171823)\n\n## Summary\r\n\r\nFix https://github.com/elastic/kibana/issues/54368\r\n\r\nAdd support for hot reloading the Kibana server's TLS configuration,\r\nusing the same `SIGHUP`-based reload signal, as already implemented for\r\nother parts of the Kibana configuration (e.g `logging`)\r\n\r\n**Note:**\r\n- hot reloading is only supported for the server TLS configuration\r\n(`server.ssl`), not for the whole `server.*` config prefix\r\n- swaping the certificate files (without modifying the kibana config\r\nitself) is supported\r\n- it is not possible to toggle TLS (enabling or disabling) without\r\nrestarting Kibana\r\n- hot reloading requires to force the process to reload its\r\nconfiguration by sending a `SIGHUP` signal\r\n\r\n### Example / how to test\r\n\r\n#### Before\r\n\r\n```yaml\r\nserver.ssl.enabled: true\r\nserver.ssl.certificate: /path-to-kibana/packages/kbn-dev-utils/certs/kibana.crt\r\nserver.ssl.key: /path-to-kibana/packages/kbn-dev-utils/certs/kibana.key\r\n```\r\n\r\n<img width=\"550\" alt=\"Screenshot 2023-11-23 at 15 11 28\"\r\nsrc=\"https://github.com/elastic/kibana/assets/1532934/1226d161-a9f2-4d62-a3de-37161829f187\">\r\n\r\n#### Changing the config\r\n\r\n```yaml\r\nserver.ssl.enabled: true\r\nserver.ssl.certificate: /path-to-kibana/packages/kbn-dev-utils/certs/elasticsearch.crt\r\nserver.ssl.key: /path-to-kibana/packages/kbn-dev-utils/certs/elasticsearch.key\r\n```\r\n\r\n```bash\r\nkill -SIGHUP {KIBANA_PID}\r\n```\r\n\r\n<img width=\"865\" alt=\"Screenshot 2023-11-23 at 15 18 21\"\r\nsrc=\"https://github.com/elastic/kibana/assets/1532934/c9412b2e-d70e-4cf0-8eaf-4db70a45af60\">\r\n\r\n#### After\r\n\r\n<img width=\"547\" alt=\"Screenshot 2023-11-23 at 15 18 43\"\r\nsrc=\"https://github.com/elastic/kibana/assets/1532934/c839f04f-4adb-456d-a174-4f0ebd5c234c\">\r\n\r\n## Release notes\r\n\r\nIt is now possible to hot reload Kibana's TLS (`server.ssl`)\r\nconfiguration by updating it and then sending a `SIGHUP` signal to the\r\nKibana process.\r\n\r\nNote that TLS cannot be toggled (disabled/enabled) that way, and that\r\nhot reload only works for the TLS configuration, not other properties of\r\nthe `server` config prefix.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"87213e7efe4420b0edf72d471056fe78cbd9df60"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/171823","number":171823,"mergeCommit":{"message":"[HTTP Server] support TLS config hot reload via `SIGHUP` (elastic#171823)\n\n## Summary\r\n\r\nFix https://github.com/elastic/kibana/issues/54368\r\n\r\nAdd support for hot reloading the Kibana server's TLS configuration,\r\nusing the same `SIGHUP`-based reload signal, as already implemented for\r\nother parts of the Kibana configuration (e.g `logging`)\r\n\r\n**Note:**\r\n- hot reloading is only supported for the server TLS configuration\r\n(`server.ssl`), not for the whole `server.*` config prefix\r\n- swaping the certificate files (without modifying the kibana config\r\nitself) is supported\r\n- it is not possible to toggle TLS (enabling or disabling) without\r\nrestarting Kibana\r\n- hot reloading requires to force the process to reload its\r\nconfiguration by sending a `SIGHUP` signal\r\n\r\n### Example / how to test\r\n\r\n#### Before\r\n\r\n```yaml\r\nserver.ssl.enabled: true\r\nserver.ssl.certificate: /path-to-kibana/packages/kbn-dev-utils/certs/kibana.crt\r\nserver.ssl.key: /path-to-kibana/packages/kbn-dev-utils/certs/kibana.key\r\n```\r\n\r\n<img width=\"550\" alt=\"Screenshot 2023-11-23 at 15 11 28\"\r\nsrc=\"https://github.com/elastic/kibana/assets/1532934/1226d161-a9f2-4d62-a3de-37161829f187\">\r\n\r\n#### Changing the config\r\n\r\n```yaml\r\nserver.ssl.enabled: true\r\nserver.ssl.certificate: /path-to-kibana/packages/kbn-dev-utils/certs/elasticsearch.crt\r\nserver.ssl.key: /path-to-kibana/packages/kbn-dev-utils/certs/elasticsearch.key\r\n```\r\n\r\n```bash\r\nkill -SIGHUP {KIBANA_PID}\r\n```\r\n\r\n<img width=\"865\" alt=\"Screenshot 2023-11-23 at 15 18 21\"\r\nsrc=\"https://github.com/elastic/kibana/assets/1532934/c9412b2e-d70e-4cf0-8eaf-4db70a45af60\">\r\n\r\n#### After\r\n\r\n<img width=\"547\" alt=\"Screenshot 2023-11-23 at 15 18 43\"\r\nsrc=\"https://github.com/elastic/kibana/assets/1532934/c839f04f-4adb-456d-a174-4f0ebd5c234c\">\r\n\r\n## Release notes\r\n\r\nIt is now possible to hot reload Kibana's TLS (`server.ssl`)\r\nconfiguration by updating it and then sending a `SIGHUP` signal to the\r\nKibana process.\r\n\r\nNote that TLS cannot be toggled (disabled/enabled) that way, and that\r\nhot reload only works for the TLS configuration, not other properties of\r\nthe `server` config prefix.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>","sha":"87213e7efe4420b0edf72d471056fe78cbd9df60"}}]}] BACKPORT-->
Thanks a lot for hot-reloading the Kibana X.509 server certificate. For tracking:
And issue #101072 has been closed as a duplicate of this issue #54368. My use case is related to Kibana's connection to Elasticsearch. |
@pgayvallet Thanks for the assessment. And make no mistake, I really appreaciate your work on Kibana! |
Describe the feature:
Kibana should reload certificates on-the-fly if the certificate files are renewed / replaced. Right now it requires a full restart to reload certificates.
Describe a specific use case for the feature:
We have a very dynamic environment where certificates are short lived and managed by Vault. Every time a certificate is renewed and/or replaced by Vault it requires a full Kibana restart. I've tried doing a SIGHUP and SIGUSR1 in the kibana process to force a certificate reload but that didn't help.
Note: Elasticsearch is able to reload certificates on-the-fly already so I just assumed Kibana would be able to do the same.
The text was updated successfully, but these errors were encountered: