Michael Hunziker
Michael Hunziker

Reputation: 2679

"cf ssh" into java buildpack app - how to run script that uses java?

I have deployed Keycloak-Server (as a Wildfly Swarm fraction) to the Swisscom Cloud Foundry environment (with a Java build pack).

When I try to access the Keycloak admin console I get the following error:

"You need local access to create the initial admin user. Open http://localhost:8080/auth or use the add-user-keycloak script."

How could I resolve this?

Can I somehow open an ssh tunnel to my Java buildpack app in order to access it with http://localhost:8080?

I also tried to "cf login" and "cf ssh" into my app. I created the "add-user-kecloak.sh" by copy/pasting it. When I try to execute it I get the error "java command not found"?

This is the script: https://github.com/keycloak/keycloak/blob/master/distribution/feature-packs/server-feature-pack/src/main/resources/content/bin/add-user-keycloak.sh

Upvotes: 0

Views: 660

Answers (1)

dkoper
dkoper

Reputation: 1485

You can use cf ssh to open an ssh tunnel into your container and access a URL within: cf ssh your-app -N -L 8080:localhost:8080.
This will listen to port 8080 on your machine, and forward any requests to it to port 8080 on your app container. So you should be able to point your browser to http://localhost:8080/auth to get to the console.

Running the script may be a bit more complicated; at least the Java Buildpack has not standardized where it stores the java executable and it's not added to the PATH when you cf ssh into the container, so you'd first need to find it.

I have not used Keycloak myself so my answer is limited to how to tunnel into your app container to access a local console.

Either way, note that if this admin user is saved to local disk, and not to some external storage, next time the app is restaged (either by you or by the system to apply patches to its rootfs), you may need to go through this again.

Upvotes: 3

Related Questions