Mulesoft Secure Properties Config Key Not Reading Variable

10.3k views Asked by At

I am attempting to build a Mulesoft application that uses Secure Properties Config. I created a settings.unencrypted.yaml file that looks like this:

sftp_username: "unencryptedUsername"
sftp_password: "unencryptedPassword"
sftpUrl: "unencryptedUrl"

I then ran the following command java -cp .\secure-properties-tool.jar com.mulesoft.tools.SecurePropertiesTool file encrypt AES CBC secretKey .\settings.unencrypted.yaml .\settings.yaml which produced the yaml file with encrypted strings. Then inside of Mulesoft I added a Secure Properties Config that looks like this: Secure Properties Config Dialog

Next, I added ${encryptionKey} to the Run Configuration as such: Run Configurations Dialog

Now I add an SFTP "On New or Updated File" item to the flow. In there I attempt to configure the SFTP Server as follows: SFTP Config Dialog

When I click "Test Connection I get the following error:

org.mule.tooling.client.api.exception.DeploymentException: Couldn't deploy the application
  org.mule.tooling.client.api.exception.DeploymentException: Couldn't deploy the application
  org.mule.tooling.agent.rest.client.exceptions.ToolingServiceAPIException: HTTP 500 Internal Server Error. org.mule.tooling.agent.rest.client.exceptions.model.ErrorEntity@5cbbc3ae[errorType=class java.lang.RuntimeException,errorMessage=Failed to deploy tooling artifact: [application(0feb8b7f-cd8c-46d9-aa0f-f1a746676a39)(C:\StudioWorkspace\.tooling\sftp-monitor8c572465-009e-48e7-9fdf-8cc690b44827)]. Cause: org.mule.runtime.deployment.model.api.DeploymentInitException: PropertyNotFoundException: Couldn't find configuration property value for key ${encryptionKey} from properties provider environment properties provider - within resolver Deployment properties trying to process key encryptionKey - within resolver global-properties configuration attributes trying to process key encryptionKey - within resolver environment properties provider trying to process key encryptionKey,errorDetail=java.lang.RuntimeException: Failed to deploy tooling artifact: [application(0feb8b7f-cd8c-46d9-aa0f-f1a746676a39)(C:\StudioWorkspace\.tooling\sftp-monitor8c572465-009e-48e7-9fdf-8cc690b44827)]. Cause: org.mule.runtime.deployment.model.api.DeploymentInitException: PropertyNotFoundException: Couldn't find configuration property value for key ${encryptionKey} from properties provider environment properties provider - within resolver Deployment properties trying to process key encryptionKey - within resolver global-properties configuration attributes trying to process key encryptionKey - within resolver environment properties provider trying to process key encryptionKey
    at com.mulesoft.agent.services.tooling.MuleAgentToolingService.deployToolingArtifact(MuleAgentToolingService.java:426)
    at com.mulesoft.agent.services.tooling.MuleAgentToolingService.deployToolingApplication(MuleAgentToolingService.java:260)
    at com.mulesoft.agent.external.handlers.tooling.ToolingRequestHandler.lambda$deployToolingApplication$4(ToolingRequestHandler.java:203)
    at com.mulesoft.agent.util.ResponseHelper.response(ResponseHelper.java:88)
    at com.mulesoft.agent.external.handlers.tooling.ToolingRequestHandler.deployToolingApplication(ToolingRequestHandler.java:202)
    at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:171)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:387)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:331)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:103)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:254)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:372)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:876)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1623)
    at com.mulesoft.agent.rest.RequestLoggingFilter.doFilter(RequestLoggingFilter.java:95)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:540)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1711)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1347)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:480)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1678)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1249)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.eclipse.jetty.server.Server.handle(Server.java:505)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
    at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:781)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:917)
    at java.lang.Thread.run(Thread.java:748)
  Caused by: com.google.common.util.concurrent.UncheckedExecutionException: org.mule.runtime.deployment.model.api.DeploymentInitException: PropertyNotFoundException: Couldn't find configuration property value for key ${encryptionKey} from properties provider environment properties provider - within resolver Deployment properties trying to process key encryptionKey - within resolver global-properties configuration attributes trying to process key encryptionKey - within resolver environment properties provider trying to process key encryptionKey
    at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2050)
    at com.google.common.cache.LocalCache.get(LocalCache.java:3951)
    at com.google.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4870)
    at com.mulesoft.agent.services.tooling.MuleAgentToolingService$ApplicationArtifactDeployer.deploy(MuleAgentToolingService.java:613)
    at com.mulesoft.agent.services.tooling.MuleAgentToolingService$ApplicationArtifactDeployer.deploy(MuleAgentToolingService.java:574)
    at com.mulesoft.agent.services.tooling.MuleAgentToolingService.deployToolingArtifact(MuleAgentToolingService.java:416)
    ... 56 more
  Caused by: org.mule.runtime.deployment.model.api.DeploymentInitException: PropertyNotFoundException: Couldn't find configuration property value for key ${encryptionKey} from properties provider environment properties provider - within resolver Deployment properties trying to process key encryptionKey - within resolver global-properties configuration attributes trying to process key encryptionKey - within resolver environment properties provider trying to process key encryptionKey
  Caused by: org.mule.runtime.core.api.config.ConfigurationException: Couldn't find configuration property value for key ${encryptionKey} from properties provider environment properties provider - within resolver Deployment properties trying to process key encryptionKey - within resolver global-properties configuration attributes trying to process key encryptionKey - within resolver environment properties provider trying to process key encryptionKey
  Caused by: org.mule.runtime.config.internal.dsl.model.config.PropertyNotFoundException: Couldn't find configuration property value for key ${encryptionKey} from properties provider environment properties provider - within resolver Deployment properties trying to process key encryptionKey - within resolver global-properties configuration attributes trying to process key encryptionKey - within resolver environment properties provider trying to process key encryptionKey
  ,additionalProperties={}]
    at org.mule.tooling.agent.rest.client.exceptions.ToolingServiceAPIException.newToolingServiceAPIException(ToolingServiceAPIException.java:82)
    at org.mule.tooling.agent.rest.client.exceptions.ToolingServiceAPIException.newToolingServiceAPIException(ToolingServiceAPIException.java:67)
    at org.mule.tooling.agent.rest.client.tooling.applications.Applications.put(Applications.java:101)
    at org.mule.tooling.agent.rest.client.RestAgentToolingService.lambda$deployApplication$5(RestAgentToolingService.java:211)
    at org.mule.tooling.agent.rest.client.service.ServiceFunction.serviceCallWrapper(ServiceFunction.java:28)
    at org.mule.tooling.agent.rest.client.RestAgentToolingService.deployApplication(RestAgentToolingService.java:210)
    at org.mule.tooling.agent.RuntimeToolingService.deployApplication(RuntimeToolingService.java:106)
    at org.mule.tooling.client.internal.metadata.AbstractRuntimeToolingServiceDecorator.deployApplication(AbstractRuntimeToolingServiceDecorator.java:75)
    at org.mule.tooling.client.internal.application.FileSystemArtifactDeployer.lambda$new$2(FileSystemArtifactDeployer.java:61)
    at org.mule.tooling.client.internal.application.FileSystemArtifactDeployer.doInternalDeploy(FileSystemArtifactDeployer.java:81)
    at org.mule.tooling.client.internal.application.AbstractArtifactDeployer.deploy(AbstractArtifactDeployer.java:59)
    at org.mule.tooling.client.internal.application.DefaultApplication.evaluateWithRemoteApplication(DefaultApplication.java:118)
    at org.mule.tooling.client.internal.ApplicationConnectivityTestingService.doTestConnection(ApplicationConnectivityTestingService.java:45)
    at org.mule.tooling.client.internal.AbstractConnectivityTestingService.testConnection(AbstractConnectivityTestingService.java:44)
    at org.mule.tooling.client.internal.AbstractConnectivityTestingService.invokeMethod(AbstractConnectivityTestingService.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mule.tooling.client.bootstrap.internal.reflection.Dispatcher$ToolingCallable.call(Dispatcher.java:241)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
  
    at org.mule.tooling.agent.rest.client.RestAgentToolingService.deployApplication(RestAgentToolingService.java:226)
    at org.mule.tooling.agent.RuntimeToolingService.deployApplication(RuntimeToolingService.java:106)
    at org.mule.tooling.client.internal.metadata.AbstractRuntimeToolingServiceDecorator.deployApplication(AbstractRuntimeToolingServiceDecorator.java:75)
    at org.mule.tooling.client.internal.application.FileSystemArtifactDeployer.lambda$new$2(FileSystemArtifactDeployer.java:61)
    at org.mule.tooling.client.internal.application.FileSystemArtifactDeployer.doInternalDeploy(FileSystemArtifactDeployer.java:81)
    at org.mule.tooling.client.internal.application.AbstractArtifactDeployer.deploy(AbstractArtifactDeployer.java:59)
    at org.mule.tooling.client.internal.application.DefaultApplication.evaluateWithRemoteApplication(DefaultApplication.java:118)
    at org.mule.tooling.client.internal.ApplicationConnectivityTestingService.doTestConnection(ApplicationConnectivityTestingService.java:45)
    at org.mule.tooling.client.internal.AbstractConnectivityTestingService.testConnection(AbstractConnectivityTestingService.java:44)
    at org.mule.tooling.client.internal.AbstractConnectivityTestingService.invokeMethod(AbstractConnectivityTestingService.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mule.tooling.client.bootstrap.internal.reflection.Dispatcher$ToolingCallable.call(Dispatcher.java:241)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

When I hard code the key in the Secure Properties Config everything works. Why can I not access the passed in variable as my key?

2

There are 2 answers

4
Thinker-101 On BEST ANSWER

Earlier we all believed that .properties files key-values are not supportive when passed as a property parameter during test connections. Same is thought for encrypted secure properties configurations.

I have recently observed that you don't have to deploy your app via Runtime to make the Test Connections work. You can test your connections and fetch the metadata without actually deploying the app.

To get this done, try adding the properties key and value in global-property in your global elements.

Search for global-property in your XML global elements section.

In your case, you need to add encryptionKey as key name, yourKey as the encryption key to the global-property. Same should be followed for any other key-value property.

Moreover, you do not have to pass encryptionkey in the global-property always. Just edit the anypointstudio.ini file in your studio exe folder and add -DencryptionKey=yourKey. You can also pass it in the Environment Properties tab in the run configurations. But this last method cannot be always guaranteed.

Cheers ! It's gonna work fine.

Note

Most mule studio versions, let it be Mule 3.x.x or 4.x.x, are not quite supportive with features like Test Connections, Auto Run, Data Sense etc.

2
Ryan Carter On

Unfortunately, there is no way to use Run Configurations with Test Connection.

Test Connection only really works with plain text as it is a simple design-time tool.

If you run the application as normal, it should work as designed.

The only workaround I know of is to launch Studio with the environmental variable of the property needed. But even then, when using 'Test Connection' the app itself is not started, so there is no way to access context such as secure properties etc.