BetterCloud / vault-java-driver

Zero-dependency Java client for HashiCorp's Vault
https://bettercloud.github.io/vault-java-driver/
334 stars 224 forks source link

Authentication using certificate: curl working, but java driver is having issues #237

Open patpatpat123 opened 3 years ago

patpatpat123 commented 3 years ago

Hello BetterCloud Team,

A big thanks for this cool project.

I am facing a small issue, hence reporting this as a bug.

I am trying to connect to our Vault back end, using certificate, not using tokens.

Hence, as a verification, we use a curl command first.

curl -vv -s -k -X $'PUT' --cacert ./mycert.crt --cert ./mycert.crt --key ./mykey.key https://x509.my-vault.com/v1/auth/cert/login | jq -r .auth.client_token

And this will yield the good token! Very happy.

Hence, just wanting to perform the same with this library:

public static void main( String[] args ) throws Exception {
      final VaultConfig config = new VaultConfig()
              .address("https://my-vault.com:443") //nox509 prefix
              .sslConfig(new SslConfig()
                      .clientPemUTF8("/mycert.crt")
                      .clientKeyPemUTF8("/mykey.key")
                      .build()).build();

      final Vault               vault   = new Vault(config, 1);
      System.out.println("checkpoint1" + vault.debug().health().getInitialized() + vault.debug().health().getRestResponse().getStatus() + new String(vault.debug().health().getRestResponse().getBody()));;

      final Map<String, Object> secrets = new HashMap<>();
      secrets.put("value", "hello world");

      final LogicalResponse writeResponse = vault.logical().write("cubbyhole/test", secrets);
      System.out.println("checkpoint2 " + writeResponse.getLeaseId() + writeResponse.getData() + writeResponse.getDataObject());

      final String value = vault.logical().read("cubbyhole/test").getData().get("value");

      System.out.println("checkpoint3 " + value);
  }

Sadly, this is not working (not able to write or read the secret.

Would it be possible those API have issues?

Please let me know if you believe I am the issue, i.e. I am not using things correctly.

Thank you!

MiraHml commented 3 years ago

Any updates on this?