Repository navigation
Conversation
|
If it's for dev purposes, what is the issue with just shutting down the server and just doing |
I cannot speak for @shawkins , but you can only do that if you have persistent storage that lives after you stopped the server. I invested few hours trying to do it with h2 devfile for we would like to having ability to export realms configured by users in Keycloak Dev Service and I never managed it. That is a separate issue (I know about all other export related issues and I watch them), because we are not using DEV mode now in Quarkus, so this PR won't help us (which is not your motivation, so np). |
Yeah, dev-mem DB would be probably the only use case. However, isn't it the whole purpose of using dev-mem that it's ephemeral? As a user I need to count with its limitations. |
it is absolutely fine if it is ephemeral, but I still would like to having ability to do full export when using dev-mem (not just in DEV mode), we had users asking for it and interestingly, when I re-read #33800 there was also user using Quarkus keycloak dev service who tried to do it manually. Anyway, I don't want to steal the show, let's go back to @shawkins proposal :-) I just tried to provide one of contexts from my user experience. |
To add onto what @michalvavrik and users on the issue are saying that is either not possible with dev-mem (which I'm not sure that users are explicitly configuring via dev services) or not straight-forward with dev-file - see the workarounds to copy the h2 files out of the container. |
|
Ok, thanks for expanding on the reasoning @shawkins @michalvavrik, makes sense. @ahus1 @pedroigor Do you have any concerns with this? |
|
@shawkins +1 I like this minimalistic approach. It'd be maybe good to mention why it's possible only in dev mode to prevent any additional questions. Like briefly mention why it should not be used in prod. WDYT? Then, providing the docs should happen. Thanks! |
Do you mean on the issue, in the operation doc, or in our other docs? An explanation could include:
Anything else? |
Wondering, whether we should even straight disable that endpoint in prod profile... |
There was a problem hiding this comment.
We should not support full realm export over REST. I get this is in dev mode only, but this can lead to folks actually using dev in production to workaround this, and also if there is a bug it could lead to the full export being available in prod as well. It also leads to confusion as there is different things support in dev/testing vs what is supported in production.
You mean instead of a check in the method, use a mechanism so that the endpoint isn't available?
I fully agree that this is not ideal. However #33800 is probably the most voted upon issue we have and we've yet to offer a satisfactory solution in quite some time, so I think we should expand what we're willing to consider to give new users of Keycloak a better experience. If restricting only to dev mode seems too weak, I would also consider checking that the db must be dev-mem or dev-file, or even add a restriction that the request can only come from localhost. If the full export over rest is not acceptable under any circumstance, the next thought is that dev-export rather than returning the realm will save it to data/import or other well-known path. |
|
Updated based upon the previous comment. The endpoint is now performing an export to the file system under our temp directory /realm-name It seems fine if we also restrict to localhost (not yet added to the pr) - unless the user sets up a mount ahead of time, they will have to go into the container in some way to get the file. It was also changed to check only for the db type, not dev mode. @michalvavrik indicated quarkus use cases where a dev database is intentionally used in prod mode. Alternatives and/or other considerations:
|
|
@stianst are you ok to move ahead with the endpoint that exports to a file as described in the previous comment? |
closes: keycloak#33800 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Signed-off-by: Steve Hawkins <shawkins@redhat.com>
|
Refined to show this as fully working. What's left to do if this is acceptable:
|
|
I'm really not keen on having this in the Admin APIs at all. I get that it's only for h2 dev database, but some folks actually use that in production, and I could see this being unintentionally expanded on in the future. I'd like to keep a pretty hard stance on the no export through Admin APIs, regardless if it's dumping to a file or sending via REST; some alternative ideas:
|
|
One other option maybe:
That could be documented as an example |
|
For dev-mem I'd just do a warning at startup stating you are using a transient database, and changes will be lost |
|
Just trying to capture the actual use-case behind this; it seems the use-case is folks want a convinient way to use the admin console as an editor to create a realm export that can later be used for testing, or bootstrapping a real production realm. If that is it, then I'd say it would be nice to focus on a good solution to that; it can even be a different start-up mode of the server; even a different distribution of KC, or something like that. Basically by focusing the use-case we can better focus the approach. Just to illustrate let's say it's something like: |
This sounds like it is an export against the running container, which won't work as the db file will be locked (also we are not currently ensuring you can run import/export commands along side the server process).
Unless that would be hidden and/or restricted to only h2 scenarios, that could cause even more confusion than the endpoint approach. Do you want to flesh this out as an enhancement in another issue? Does it accept realm(s), a path, etc.? This would probably need to be enabled in some way by default when using h2 as well - see the final discussion point.
This is discussed on the issue. It does not seem like something that should be documented. Also the container must not be running or you risk getting a corrupted copy (h2 warns against doing this).
Can you create an issue for that? dev-mem was brought into the discussion here because the approaches initially discussed here would work for both h2 variants. In particular if you want to persue previous approach of documenting shutting down the container and copying the database file, then we'll want as strong as warning as possible for dev-mem.
I'm not sure that's a good phrasing. Users are currently simply following the existing quickstarts, or using quarkus dev services, then find it hard to propagate any of the work to a real instance. You could certainly start going down the path of introducing new commands or distributions, but without consistently pointing users to that and/or warning them not to do any work they'll want to later save with a non-production database, some will still hit this problem. |
closes: #33800
Based upon the previous attempts to resolve this and the continued comments on the issue, I'd like to propose adding a special purpose endpoint for this. It's not ideal and not something that is applicable to production, but it has a minimal code footprint and will work without a lot of additional documentation. We can just show using kcadm.sh (via docker):
kcadm.sh get dev-export -r name > name-realm.jsonThoughts @keycloak/cloud-native ?