avioconsulting / mule-vault-properties-provider

Mule 4 Properties Provider for properties from HashiCorp Vault
BSD 2-Clause "Simplified" License
6 stars 7 forks source link

Vault connector is not working in Mule 4.4 #12

Closed Chaithanya-Matta closed 2 years ago

Chaithanya-Matta commented 2 years ago

The Vault properties provider is not working after upgrading mule runtime from 4.3 to 4.4 in Anypoint Studio.

Getting the following error

ERROR 2022-04-11 06:48:13,065 [WrapperListener_start_runner] org.mule.runtime.module.deployment.internal.DefaultArchiveDeployer: Failed to deploy artifact [<>] org.mule.runtime.deployment.model.api.DeploymentException: Failed to deploy artifact [<>] Caused by: org.mule.runtime.api.exception.MuleRuntimeException: org.mule.runtime.deployment.model.api.DeploymentInitException: PropertyNotFoundException:

aschneid75 commented 2 years ago

This is something we are running into as well. Are there any plans to get this working with Mule 4.4?

aschneid75 commented 2 years ago

Digging into the code a little bit to try to debug (and basing it off of the log outputs), it looks like the issue is actually in the com.avioconsulting.mule.vault.provider.api.VaultConfigurationPropertiesProviderFactory. There are some warnings that are being printed from there in the logging and from looking at the code, it actually never returns a Vault connection. The PropertyNotFoundException is being thrown because there isn't a valid Vault connection.

The code expects a single entry complex configuration parameters collection, but it's getting more than one when running on 4.4. I validated in our configuration that we only have one, so not sure what changed from 4.3 to 4.4.

aschneid75 commented 2 years ago

Another update for those following along, I did some debugging and did verify the issue is in com.avioconsulting.mule.vault.provider.api.VaultConfigurationPropertiesProviderFactory. I fixed it for us in our version deployed to our Exchange. I'll see about getting a pull request, but this seems like a dead project, so I don't have hopes of it being merged in. In case anybody wants to patch their own version, you can replace the getVault method in the factory with this version. It maintains behavior, so will be backward compatible:

private Vault getVault(ConfigurationParameters parameters) throws ConnectionException {

    if (parameters.getComplexConfigurationParameters().size() > 1) {
      LOGGER.warn("Multiple Vault Properties Provider configurations have been found");
    }

    ConnectionProvider<VaultConnection> connectionProvider = null;

    for (int i=0;i<parameters.getComplexConfigurationParameters().size();i++) {
        String firstConfigurationNamespace = parameters.getComplexConfigurationParameters().get(i).getFirst().getNamespace();

        if (firstConfigurationNamespace.equals(VaultPropertiesProviderExtension.VAULT_PROPERTIES_PROVIDER.getNamespace())) {
            String firstConfiguration = parameters.getComplexConfigurationParameters().get(i).getFirst().getName();
            ConfigurationParameters configurationParameters = parameters.getComplexConfigurationParameters().get(i).getSecond();
            if (TLS_PARAMETER_GROUP.equals(firstConfiguration)) {
              connectionProvider = new TlsConnectionProvider(configurationParameters);
            } else if (TOKEN_PARAMETER_GROUP.equals(firstConfiguration)) {
              connectionProvider = new TokenConnectionProvider(configurationParameters);
            } else if (IAM_PARAMETER_GROUP.equals(firstConfiguration)) {
              connectionProvider = new IamConnectionProvider(configurationParameters);
            } else if (EC2_PARAMETER_GROUP.equals(firstConfiguration)) {
              connectionProvider = new Ec2ConnectionProvider(configurationParameters);
            }
            break;
        }
    }

    if (connectionProvider != null) {
      return connectionProvider.connect().getVault();
    } else {
      LOGGER.warn("No Vault Properties Provider configurations found");
      return null;
    }

  }
adammead commented 2 years ago

We will take a look at this issue and the solution @aschneid75 is providing.