You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m using a docker image and I uploaded the realm.json in /opt/keycloak/data/import to get the nice auto import functionality.
When I add now to start --import-realm I get:
2022-04-26 08:28:56,195 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to start server in (production) mode
2022-04-26 08:28:56,195 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Failed to import realm: myrealm
2022-04-26 08:28:56,195 ERROR [org.keycloak.quarkus.runtime.cli.ExecutionExceptionHandler] (main) ERROR: Script upload is disabled
which confuses me, because
Script Upload should be removed (why is import using that?) and
doesn’t work.
Without the --import-realm all works fine
The same error I get also when I try to upload a realm from the interface/admin console: Uncaught server error: java.lang.RuntimeException: Script upload is disabled
@edwint88 Is your realm declaring providers that rely on scripts such as mappers, authenticators, or policies?
I had the same issue and based on your feedback I search and found I had these policies for one of the realm clients:
"policies": [
{
"id": "b56eebd7-8e73-4449-b110-30dfdbc77f03",
"name": "Default Policy",
"description": "A policy that grants access only for users within this realm",
"type": "js",
"logic": "POSITIVE",
"decisionStrategy": "AFFIRMATIVE",
"config": {
"code": "// by default, grants any permission associated with this policy\n$evaluation.grant();\n"
}
},
{ ... },
{
"id": "1428ae4c-b767-41b9-aaf9-bd8b0d8497e2",
"name": "Default Permission",
"description": "A permission that applies to the default resource type",
"type": "resource",
"logic": "POSITIVE",
"decisionStrategy": "UNANIMOUS",
"config": {
"defaultResourceType": "urn:api:resources:default",
"applyPolicies": "[\"Default Policy\"]"
}
},
{...}
]
I checked and these were not referenced anywhere else so I proceeded to delete them and it worked.
I guess it was created automatically by a previous version of KC.
For anyone else experiencing the same issue: search for "type": "js" to pin-point the root cause in the realm export file.
Reacted by niwde, arman, Dominik Guhr, jfrantzius, xojc, Miguel Alorda, Sam Theisens, Oleksandr Porunov, Joao Bento Candido Bezerra, Sébastien Moreno and 45 more
Reacted by Felipe Maeda, Lalit Rao, Natanael Silva Lima, Josimar Lopes, FedericoHeichou, Gregor Kistler, axi92, Agustín Bravo, Philippe Doussot, Victor Cordoș and 23 more
``> @edwint88 Is your realm declaring providers that rely on scripts such as mappers, authenticators, or policies?
If so, the realm configuration is now invalid and you should not be able to import. See the note here about the removal of the upload-scripts feature.
We have an Authenticator, but not a JavaScript one. It's a simple Java SPI that we add through .jar in /opt/keycloak/providers and then, yes, configured in the realm.json.
Is this affected too?
LE: thanks for the "type": "js" hint!
we got a default policy - that we didn't create it, I'll check without that in the config.
{ "id": "cf9f7684-45c2-4bcd-89a5-38c2a41b55fd", "name": "Default Policy", "description": "A policy that grants access only for users within this realm", "type": "js", "logic": "POSITIVE", "decisionStrategy": "AFFIRMATIVE", "config": { "code": "// by default, grants any permission associated with this policy\n$evaluation.grant();\n" } }
That was the problem! So when I've created a dummy confidential client in 17.0.1 the Default JS policies were activated!
Reacted by Stefan Maric, Dominik Guhr, 5aaee9 and Abdelrahman Moussa
We would like to reopen this discussion. We are just starting with a project using Keycloak (18.0.2). We have create a realm via the user interface with some basic settings. We exported the realm using the Manage > Export > Partial Export feature in the user interface.
When we try to import this export using the --import-realm option in a clean container (also 18.0.2), we get the mentioned error. It seems like a bug when Keycloak does not generate a compatible export for the same version?
It works when we remove the policies element enterily (not when we only remove the policy with the "js"-type). But as new users we are not sure whether that's a safe thing to do.
Hi,
Deleting the default policies is safe. Later on you want to have your own
there. The error I think is still relate to the js thing, because if you
delete just that policy some reference will remain to it and therefore will
fail your import.
Cheers
On Mon, Jul 11, 2022, 13:34 ericwout-overheid ***@***.***> wrote:
We would like to reopen this discussion. We are just starting with a
project using Keycloak (18.0.2). We have create a realm via the user
interface with some basic settings. We exported the realm using the Manage
> Export > Partial Export feature in the user interface.
When we try to import this export using the --import-realm option in a
clean container (also 18.0.2), we get the mentioned error. It seems like a
bug when Keycloak does not generate a compatible export for the same
version?
It works when we remove the policies element enterily (not when we only
remove the policy with the "js"-type). But as new users we are not sure
whether that's a safe thing to do.
—
Reply to this email directly, view it on GitHub
<#11664 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAV67TIICGL7DHKCGE3CYTTVTQBF3ANCNFSM5ULDLUPA>
.
You are receiving this because you modified the open/close state.Message
ID: ***@***.***>
Ah, thanks for clearing that up. But shouldn't it be registered as a bug that when you create an export, it cannot be imported without removing this by hand (after googling for it?).
Reacted by Nicholas Quentin Haas, Aaron Parsons, Егор Малыгин, zharkov-ruslan, Torsten Schlieder, Kevin M Granger and Angelo
Change the default policy type to the script-jsfilename:
{
"id": "834d0278-8eda-4533-911b-78a1d983ffc9",
"name": "Default Policy",
"description": "A policy that grants access only for users within this realm",
"type": "script-default-policy.js",
"logic": "POSITIVE",
"decisionStrategy": "AFFIRMATIVE"
},
put the jar to providers, then
kc.sh build
and
kc.sh start
.
The default-policy.js in one sample jar photoz-uma-js-policies.jar. photoz-uma-js-policies.jar
shouldn't it be registered as a bug that when you create an export, it cannot be imported without removing this by hand
I agree, this issue should be re-opened, this problem still exists in keycloak 20.0 (and 25.0)
The workaround described above seems to still work (using the quay.io/keycloak/keycloak docker image), here is a minimal, reproducible example of the issue and the workaround:
Start an interactive docker container: docker run --name auth1 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=12345 -it --entrypoint=/bin/bash -p 8080:8080 quay.io/keycloak/keycloak:20.0
Start the keycloak service: /opt/keycloak/bin/kc.sh start-dev
From the host or another system, login to localhost:8080 after it spins up and create the realm, users, clients, etc. as one sees fit, for this example, the realm will be myrealm
Copy the exported realm out of the docker instance to a temporary file: docker cp auth1:/tmp/realm-export.json.tmp realm-export.json.tmp
Copy said temporary file to an import folder: cp realm-export.json.tmp import/realm-export.json
Verify import bug still exists by attempting to import said realm upon container instance spinup:
$ docker run --name auth2 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=12345 -v $(pwd)/import/:/opt/keycloak/data/import/:ro --rm quay.io/keycloak/keycloak:20.0 start-dev --import-realm
...
Unable to import realm myrealm from file /opt/keycloak/bin/../data/import/realm-export.json.: java.lang.RuntimeException: Script upload is disabled
Stop the service with CTRL-C and let the docker instance exit and remove itself
Remove the policies using jq to avoid editing by hand: cat realm-export.json.tmp | jq 'del(.clients[].authorizationSettings.policies)' > import/realm-export.json
Verify import now works: docker run --name auth2 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=12345 -v $(pwd)/import/:/opt/keycloak/data/import/:ro --rm -p 8080:8080 quay.io/keycloak/keycloak:20.0 start-dev --import-realm
Updated for KC25
Reacted by Aaron Parsons, tavhid, Kevin M Granger, bdsWind and martin-private
Replacing the Default Policy setting with the one below resolves the issue and maintains the expected behavior.
{
"id": "98bb844e-5524-4c42-914b-cc5121d3124d",
"name": "Default Policy",
"description": "A policy that grants access only for users within this realm",
"type": "role",
"logic": "POSITIVE",
"decisionStrategy": "AFFIRMATIVE",
"config": {
"roles": "[{\"id\":\"default-roles-main\",\"required\":false}]"
}
}
Reacted by Fabio Rodriguez, morco, Ken McCormack, Theo Bouras, Nicholas Quentin Haas, lasith011, zharkov-ruslan, Meelis, Mert Acar, Max Reble and 4 more
put the jar to providers, then
kc.sh build
and
kc.sh start
.
The default-policy.js in one sample jar photoz-uma-js-policies.jar. photoz-uma-js-policies.jar
But the problem is with upgrade from wildfly(15) distro to keycloak(20) , as in database have of type js entry for default policy.
And we can not ask end user/admin to change the type of Policy type.
What is the recommendation in the scenarios of migration?
IMO, given this is still an issue with 25.0.x, likely deserves a new issue.
I'd be interested in someone with more keycloak expertise than I to explain the consequences of stefanmaric's workaround vs herbertscruz's workaround given defaults / behaviors have likely changed since they were first proposed as a workaround.
@bornav the script upload error was most recently resolved as #32269 - if that is your underlying problem, please see that issue. If you are experiencing something else, then please open a new issue.
Activity
edwint88 commentedon Apr 26, 2022
The same error I get also when I try to upload a realm from the interface/admin console:
Uncaught server error: java.lang.RuntimeException: Script upload is disabledstefanmaric commentedon Apr 27, 2022
Linking this discussion I opened a few ago: #11658
edwint88 commentedon Apr 27, 2022
And also here: https://keycloak.discourse.group/t/import-realm-in-keycloak-18-0-0-failed/15166
pedroigor commentedon Apr 27, 2022
@edwint88 Is your realm declaring providers that rely on scripts such as mappers, authenticators, or policies?
If so, the realm configuration is now invalid and you should not be able to import. See the note here about the removal of the
upload-scriptsfeature.stefanmaric commentedon Apr 27, 2022
I had the same issue and based on your feedback I search and found I had these policies for one of the realm clients:
I checked and these were not referenced anywhere else so I proceeded to delete them and it worked.
I guess it was created automatically by a previous version of KC.
For anyone else experiencing the same issue: search for
"type": "js"to pin-point the root cause in the realm export file.edwint88 commentedon Apr 27, 2022
``> @edwint88 Is your realm declaring providers that rely on scripts such as mappers, authenticators, or policies?
We have an Authenticator, but not a JavaScript one. It's a simple Java SPI that we add through .jar in
/opt/keycloak/providersand then, yes, configured in the realm.json.Is this affected too?
LE: thanks for the
"type": "js"hint!we got a default policy - that we didn't create it, I'll check without that in the config.
{ "id": "cf9f7684-45c2-4bcd-89a5-38c2a41b55fd", "name": "Default Policy", "description": "A policy that grants access only for users within this realm", "type": "js", "logic": "POSITIVE", "decisionStrategy": "AFFIRMATIVE", "config": { "code": "// by default, grants any permission associated with this policy\n$evaluation.grant();\n" } }That was the problem! So when I've created a dummy confidential client in 17.0.1 the Default JS policies were activated!
ericwout-overheid commentedon Jul 11, 2022
We would like to reopen this discussion. We are just starting with a project using Keycloak (18.0.2). We have create a realm via the user interface with some basic settings. We exported the realm using the Manage > Export > Partial Export feature in the user interface.
When we try to import this export using the --import-realm option in a clean container (also 18.0.2), we get the mentioned error. It seems like a bug when Keycloak does not generate a compatible export for the same version?
It works when we remove the policies element enterily (not when we only remove the policy with the "js"-type). But as new users we are not sure whether that's a safe thing to do.
See also:
edwint88 commentedon Jul 11, 2022
ericwout-overheid commentedon Jul 11, 2022
Ah, thanks for clearing that up. But shouldn't it be registered as a bug that when you create an export, it cannot be imported without removing this by hand (after googling for it?).
edwint88 commentedon Jul 11, 2022
Sure, I don't know if there is a ticket already or to be fixed in the next version.
yangboyd commentedon Jul 14, 2022
Change the default policy type to the script-jsfilename:
put the jar to providers, then
kc.sh build
and
kc.sh start
.
The default-policy.js in one sample jar photoz-uma-js-policies.jar.
photoz-uma-js-policies.jar
qhaas commentedon Nov 22, 2022
I agree, this issue should be re-opened, this problem still exists in keycloak 20.0 (and 25.0)
The workaround described above seems to still work (using the
quay.io/keycloak/keycloakdocker image), here is a minimal, reproducible example of the issue and the workaround:docker run --name auth1 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=12345 -it --entrypoint=/bin/bash -p 8080:8080 quay.io/keycloak/keycloak:20.0/opt/keycloak/bin/kc.sh start-devlocalhost:8080after it spins up and create the realm, users, clients, etc. as one sees fit, for this example, the realm will bemyrealm--users same_file):/opt/keycloak/bin/kc.sh export --realm myrealm --users same_file --file /tmp/realm-export.json.tmpexitdocker cp auth1:/tmp/realm-export.json.tmp realm-export.json.tmpimportfolder:cp realm-export.json.tmp import/realm-export.jsonjqto avoid editing by hand:cat realm-export.json.tmp | jq 'del(.clients[].authorizationSettings.policies)' > import/realm-export.jsondocker run --name auth2 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=12345 -v $(pwd)/import/:/opt/keycloak/data/import/:ro --rm -p 8080:8080 quay.io/keycloak/keycloak:20.0 start-dev --import-realmUpdated for KC25
herbertscruz commentedon Nov 24, 2022
Replacing the
Default Policysetting with the one below resolves the issue and maintains the expected behavior.{ "id": "98bb844e-5524-4c42-914b-cc5121d3124d", "name": "Default Policy", "description": "A policy that grants access only for users within this realm", "type": "role", "logic": "POSITIVE", "decisionStrategy": "AFFIRMATIVE", "config": { "roles": "[{\"id\":\"default-roles-main\",\"required\":false}]" } }ajaiswal595 commentedon Dec 22, 2022
@yangboyd this works
put the jar to providers, then
kc.sh build
and
kc.sh start
.
The default-policy.js in one sample jar photoz-uma-js-policies.jar.
photoz-uma-js-policies.jar
But the problem is with upgrade from wildfly(15) distro to keycloak(20) , as in database have of type js entry for default policy.

And we can not ask end user/admin to change the type of Policy type.
What is the recommendation in the scenarios of migration?
pedroigor commentedon Dec 22, 2022
@edwint88 @yangboyd I'm working on it. Can we discuss this issue at #16074?
remove default policies from keycloack config
hantsy commentedon Jul 1, 2024
I encountered the same issue in the newest 25.0.1.
hantsy commentedon Jul 1, 2024
@qhaas 's solution resolved my problem.
goekhantopcu commentedon Aug 9, 2024
The solution of @qhaas worked for me as well, thanks a lot men <3 (using keycloak 24.0.4)
qhaas commentedon Sep 22, 2024
IMO, given this is still an issue with 25.0.x, likely deserves a new issue.
I'd be interested in someone with more keycloak expertise than I to explain the consequences of stefanmaric's workaround vs herbertscruz's workaround given defaults / behaviors have likely changed since they were first proposed as a workaround.
bornav commentedon Mar 9, 2025
Why is this closed?
export/import is unsuccessful if docs are followed do to 2 policies that are generated not by the user
shawkins commentedon Mar 10, 2025
@bornav the script upload error was most recently resolved as #32269 - if that is your underlying problem, please see that issue. If you are experiencing something else, then please open a new issue.