4

I've a problem regarding Wildfly/Undertow and the JBoss-CLI setting the web-context of Keycloak.

The environment-variable seems not to be resolved in undertow itself, but other environment-variable seems to be resolved.

I've create the following CLI-script:

/subsystem=keycloak-server/:write-attribute(name=web-context,value=${env.KEYCLOAK_WEB_CONTEXT:auth})

which is executed by the docker build and the result in the standalone.xml also looks good :)

When starting the Keycloak-Service it does not resolve the variable, it will just use the variable itself:

14:30:30,556 INFO  [org.wildfly.extension.undertow] (ServerService
Thread Pool -- 60) WFLYUT0021: Registered web context:
'/${env.KEYCLOAK_WEB_CONTEXT:auth}' for server 'default-server'

After connecting with the jboss-cli.sh to the container and requesting the variables I got:

[standalone@localhost:9990 subsystem=keycloak-server] ls -l
ATTRIBUTE VALUE TYPE
web-context ${env.KEYCLOAK_WEB_CONTEXT:auth} STRING

With resolved expressions:

[standalone@localhost:9990 subsystem=keycloak-server] ls -l --resolve-expressions
ATTRIBUTE VALUE TYPE
web-context helloworld/auth  STRING

So everything looks good so far. Any ideas why Undertow starts with the variable and not the resolved variable? Is it a potential bug?

Best regards and thank you for any help!

JanL
  • 41
  • 3

1 Answers1

1

I know this is two years old, but I was recently trying to solve this problem and I figured it out so I figured I'd follow up if anyone comes across this.

Instead of using the ${env.VAR} pattern in your expression, use them in the top of the script as a variable assignment. Borrowing from the parent example:

set CONTEXT=${env.KEYCLOAK_WEB_CONTEXT}
/subsystem=keycloak-server/:write-attribute(name=web-context,value=$CONTEXT)

The environment variable gets pulled in as the value of $CONTEXT, even though it never worked for me when used in the write-attribute line.

Rex Roof
  • 11
  • 3
  • I just created a cli with this but when starting the server it fails with this error: `No connection to the controller.` looks like the server should be started first, but then, if the server is running I get a different error `Can't reset to root in the middle of the path @74` ... any idea? how and when do you run your script... can you please share? – xbmono Jul 14 '21 at 00:31