I am relatively new to Micronaut framework and have less knowledge in it.
Currently, I am trying to upgrade an existing app built on Micronaut 3.9.3 to Micronaut 4.0.3 . The app has bootstrap configurations to load app secrets from Azure key vault. (I followed the Guide to read Micronaut app secrets securely from Azure Key Vault to implement the secret loading on bootstrap). It is working fine with Micronaut 3.9.x).
But the application bootstrap with secrets from Azure vault is not working as expected, with the app upgraded to Micronaut 4.0.3
. (ie: the placeholders for app secrets are not getting replaced with the real values from Azure Key Vault).
The app in version 3.9.3
is generating the following startup logs, which clearly shows the secret loading from Azure key vault and is working as expected.
| \/ (_) ___ _ __ ___ _ __ __ _ _ _| |_
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
| | | | | (__| | | (_) | | | | (_| | |_| | |_
|_| |_|_|\___|_| \___/|_| |_|\__,_|\__,_|\__|
Micronaut (v3.9.3)
{"time": "16:10:30.375", "thread": "main", "level": "INFO ", "logger":"i.m.context.DefaultBeanContext", "message": "Reading bootstrap environment configuration"}
{"time": "16:10:33.627", "thread": "ForkJoinPool.commonPool-worker-6", "level": "INFO ", "logger":"c.a.identity.ClientSecretCredential", "message": "Azure Identity => getToken() result for scopes [https://vault.azure.net/.default]: SUCCESS"}
{"time": "16:10:33.629", "thread": "ForkJoinPool.commonPool-worker-6", "level": "INFO ", "logger":"c.a.c.i.AccessTokenCache", "message": "{"az.sdk.message":"Acquired a new access token."}"}
{"time": "16:10:36.573", "thread": "main", "level": "INFO ", "logger":"i.m.d.c.c.DistributedPropertySourceLocator", "message": "Resolved 1 configuration sources from client: compositeConfigurationClient(Retrieves secrets from Azure key vaults)"}
{"time": "16:10:36.911", "thread": "main", "level": "INFO ", "logger":"io.micronaut.runtime.Micronaut", "message": "Startup completed in 8365ms. Server Running: http://localhost:8080"}
Whereas, the app upgraded with Micronaut 4.0.3
generates following logs on startup (which is not generating any logs related to Azure Key vault access).
| \/ (_) ___ _ __ ___ _ __ __ _ _ _| |_
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
| | | | | (__| | | (_) | | | | (_| | |_| | |_
|_| |_|_|\___|_| \___/|_| |_|\__,_|\__,_|\__|
{"time": "16:11:30.701", "thread": "main", "level": "INFO ", "logger":"io.micronaut.runtime.Micronaut", "message": "Startup completed in 1823ms. Server Running: http://localhost:8080"}
I tried setting the system property micronaut.bootstrap.context
as true
as documented in Bootstrap configuration of Micronaut guide , which gave an additional log as shown below.
__ __ _ _
| \/ (_) ___ _ __ ___ _ __ __ _ _ _| |_
| |\/| | |/ __| '__/ _ \| '_ \ / _` | | | | __|
| | | | | (__| | | (_) | | | | (_| | |_| | |_
|_| |_|_|\___|_| \___/|_| |_|\__,_|\__,_|\__|
{"time": "16:14:46.744", "thread": "main", "level": "INFO ", "logger":"i.m.context.DefaultBeanContext", "message": "Reading bootstrap environment configuration"}
Picked up JAVA_TOOL_OPTIONS: -Dmicronaut.bootstrap.context=true
{"time": "16:14:48.637", "thread": "main", "level": "INFO ", "logger":"io.micronaut.runtime.Micronaut", "message": "Startup completed in 2082ms. Server Running: http://localhost:8080"}
I even tried launching new demo app using Micronaut launch page.
curl --location --request GET 'https://prev.micronaut.io/create/default/com.example.demo?lang=JAVA&build=GRADLE&test=JUNIT&javaVersion=JDK_17&features=azure-key-vault' --output demo.zip
)curl --location --request GET 'https://launch.micronaut.io/create/default/com.example.demo?lang=JAVA&build=GRADLE&test=JUNIT&javaVersion=JDK_17&features=azure-key-vault&features=yaml' --output demo.zip
)I could reproduce the same issue with the demo apps too, confirming that the issue is not specific to my app.
I went through the Micronaut 4 upgrade guide and Micronaut 4 breaking changes doc closely, but couldn't find anything explicit to make the bootstrap config work with Micronaut 4.0.x
Am I missing anything here? Any help would be really appreciated.
Can you trying adding the below dependency ? It worked for me as per Micronaut community suggestion.
implementation("io.micronaut.discovery:micronaut-discovery-client")