question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Variable substitution not working?

See original GitHub issue

Describe the bug

Thank you for the great tool!

I’m trying to use variable substitution to script out a realm.json file for automated deployments, but the CLI doesn’t substitute environment variables at runtime, submitting values to Keycloak like “${env:SOME_ENV_VARIABLE}”. There aren’t any warnings or errors, and the import succeeds. I can view the new realm in the Keycloak interface. I’m running Docker locally on Mac OS. I’m passing import_var-substitution=true to the docker run command.

I should note that passing other flags, like keycloak_availability-check_enabled=true and keycloak_availability-check_timeout=120s seems to have no effect. When I run docker-compose up, the CLI will fail after the first HTTP request fails, without retrying or waiting. Am I misunderstanding how to use the CLI?

To Reproduce

Run CLI via Docker:

docker run \
    -e keycloak_url=http://docker.for.mac.localhost:8080 \
    -e keycloak_user=admin \
    -e keycloak_password=admin \
    -e IMPORT_PATH=/realms/my-realm.json \
    -e import_var-substitution=true \
    -e API_CLIENT_SECRET=somesecret \
    -v /Users/me/Projects/keycloak-example/src/realms:/realms \
    adorsys/keycloak-config-cli:master

realm.json (some detail omitted):

{
  "id": "app",
  "realm": "My App",
  "enabled": true,
  "clients": [
    {
      "clientId": "api",
      "name": "API",
      "enabled": true,
      "clientAuthenticatorType": "client-secret",
      "secret": "${env:API_CLIENT_SECRET}",
      "webOrigins": ["+"],
      "standardFlowEnabled": true,
      "implicitFlowEnabled": false,
      "serviceAccountsEnabled": true
    }
  ]
}

Expected behavior

I would expect to the see the value specified for API_CLIENT_SECRET to be injected into Keycloak.

Environment (please complete the following information):

  • Keycloak Version: 11.0.2
  • keycloak-config-cli Version: I’ve tried both master and latest

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
sandhraprakashcommented, Mar 22, 2022
  "secret": "${env:API_CLIENT_SECRET}",

Which version are you using @sandhraprakash? In the newer versions, you need to use $() format.

       "secret": "$(env:API_CLIENT_SECRET)",

sorry I immediately realized the mistake I made. it works with this “secret”: “$(API_CLIENT_SECRET)”

0reactions
charandascommented, Jul 12, 2022

On more recent versions, 5.x with 18.x JARs, you actually need:

  1. IMPORT_VARSUBSTITUTION_ENABLED: true

Haven’t tried with env: part successfully in the variable substitution itself but worked for me without. It may also work with that prefix and it was _ENABLED that I was missing all along.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bash Command Substitution doesn't work - Super User
The problem is that bash expands environment variables only once, unless you use eval , which causes the command line to be parsed...
Read more >
Variable Substitution not working correctly?! - SAP Community
Hello all, perhaps some of you faced the same problem. It depends on the variable substitution in XI (PI). We have got an...
Read more >
Variable substitution not working in environment ... - GitHub
Variable substitution not working in environment variable definitions file #14950 · Environment data. VS Code version: 1.52.0 · Expected behaviour.
Read more >
Variable Substitution is Not Working for Azure App Service ...
Deployment log messages state that variable substitution was executed successfully, but the resulting configuration values shown in Azure are not consistent ...
Read more >
Variable substitution not working to pass --exclude options to ...
You are passing --exclude='/captain/generated' from the variable substitution. Because there is no directory named literally ' relative to your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found