confluentinc / csid-secrets-providers

Enables use of external third-party systems for storing/retrieving key/value pairs with Confluent clusters.
https://confluentinc.github.io/csid-secrets-providers/
Other
6 stars 19 forks source link

184 : fix use of AppRole with custom mount #185

Closed ahmedtoumi closed 10 months ago

ahmedtoumi commented 10 months ago

Description

When we use vaultProvider with AppRole and custom mount, the authentication use UserPass instead of AppRole

Motivation and Context

Vault Provider

When using Vault provider, we need some configs like :

vault.address = https://vault.xxxx.com vault.auth.method = AppRole vault.auth.mount = approle-xxx vault.auth.role = xxxxx vault.auth.secret = [hidden] vault.namespace = vault.prefixpath = vault.secrets.version = 2

but unfortunately, when we specify a custome vault.auth.mount, the java code force the use of UserPass login instead of AppRole in this line

this code

 public AuthResult execute(VaultConfigProviderConfig config, Vault vault) throws VaultException {
  AuthResponse response;
  if (isNullOrEmpty(config.mount)) {
    log.trace("execute() - calling loginByAppRole('{}', '*****')", config.role);
    response = vault.auth().loginByAppRole(config.role, config.secret);
  } else {
    log.trace("execute() - calling loginByUserPass('{}', ****, '{}')", config.username, config.mount);
    response = vault.auth().loginByUserPass(config.username, config.password, config.mount);
  }
  return result(response);
}

should be replaced by this one

  public AuthResult execute(VaultConfigProviderConfig config, Vault vault) throws VaultException {
  AuthResponse response;

  if (isNullOrEmpty(config.mount)) {
    log.trace("execute() - calling loginByAppRole('{}', '*****')", config.role);
    response = vault.auth().loginByAppRole(config.role, config.secret);
  } else {
    log.trace("execute() - calling loginByAppRole('{}', '{}', ****)", config.mount, config.role);
    response = vault.auth().loginByAppRole( config.mount, config.role, config.secret);
  }
  return result(response);
}

Issue : 184

How Has This Been Tested?

Test in Progress

Screenshots (if appropriate):

Before image

After image

Types of changes

Checklist:

cla-assistant[bot] commented 10 months ago

CLA assistant check
All committers have signed the CLA.

cla-assistant[bot] commented 10 months ago

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


ahmed.toumi-ext seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

ahmedtoumi commented 10 months ago

Tested with deploying manually the generated ZIP confluent-hub install --no-prompt /tmp/confluentinc-csid-secrets-provider-vault-1.0.11-SNAPSHOT.zip and it's working