Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: adds decision record for HashiCorp Vault auth refactor #4720

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

SaschaIsele
Copy link
Contributor

What this PR changes/adds

This PR adds a decision record that outlines a refactor of the authentication inside the vault-hashicorp extension.

Why it does that

Currently, the only possible authentication method for HashiCorp Vault is token authentication which is hardcoded into the extension.
To pave the way for additonal authentication methods, the authentication of vault-hashicorp extension needs to be extensible.
This PR outlines the changes needed to achieve interchangeable authentication.

Further notes

This version of the decision record removes the registry and spi in favor of a default implementation that can be overwritten.

Linked Issue(s)

Closes #4672
Related discussion: #4374
Previous closed PR: #4673

@ndr-brt ndr-brt requested a review from a team January 14, 2025 08:07
Copy link
Contributor

@jimmarino jimmarino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments, but otherwise I'm fine with this.

The sole common point between the authentication methods is the ability to provide a `client_token` that can be used to authenticate with HashiCorp Vault.

```java
public interface HashicorpVaultAuth {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is not intuitive. It should reflect what role it provides.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which name would be more intuitive?
Only other fitting name that comes to mind for me would be HashicorpVaultTokenProvider.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That name is better IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name has been adjusted.


```java
@NotNull
private Headers getHeaders() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first look, I would prefer the token to be passed into this function (also valueAuth to be renamed because it is not intuitive) rather than computed from a member at this point

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing the token into this function instead of retrieving it inside would lead to duplicate code in four places.
While it would only be one line, the call to retrieve the token has to be made either way inside the public methods of the HashicorpVaultClient.
Doing it during header generation in a central place seems the most sensible to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm talking about the vaultAuth.vaultToken() call. That value can be passed to the method instead of having the method rely on a class member. I generally don't like getXXX methods that rely on members since it is not apparent what the inputs of the method are.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the token to the parameters of getHeaders.

@SaschaIsele SaschaIsele added the documentation Improvements or additions to documentation label Jan 14, 2025
Copy link
Contributor

@jimmarino jimmarino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please distinguish class names better before I proceed with a further review? Specifically, HashicorpVaultAuthTokenProvider and HashicorpVaultTokenAuth are extremely confusing.

@SaschaIsele
Copy link
Contributor Author

SaschaIsele commented Jan 22, 2025

@jimmarino did a pass for the class names.
HashicorpVaultAuthTokenProvider was renamed to HashicorpVaultAuthClientTokenProvider to make it readily apparent, what it provides.
HashicorpVaultTokenAuth was renamed to HashicorpVaultAuthTokenImpl to signify it as the implementation for the token authentication method of HashiCorp Vault.

Also saw the PR #4749 from @paullatzelsperger which already takes care of the refactoring part for the current token authentication and would reroute the changes specified for the HashicorpVaultClientto the HashicorpVault.java and HashicorpVaultHealthService, depending on which PR gets merged first.

@jimmarino
Copy link
Contributor

jimmarino commented Jan 22, 2025

@jimmarino did a pass for the class names. HashicorpVaultAuthTokenProvider was renamed to HashicorpVaultAuthClientTokenProvider to make it readily apparent, what it provides. HashicorpVaultTokenAuth was renamed to HashicorpVaultAuthTokenImpl to signify it as the implementation for the token authentication method of HashiCorp Vault.

Also saw the PR #4749 from @paullatzelsperger which already takes care of the refactoring part for the current token authentication and would reroute the changes specified for the HashicorpVaultClientto the HashicorpVault.java and HashicorpVaultHealthService, depending on which PR gets merged first.

Sorry, but these names are completely confusing and do not align. For example:

@Provider(isDefault = true)
public HashicorpVaultAuthClientTokenProvider HashicorpVaultAuthClientTokenProvider() {
    return new HashicorpVaultAuthTokenImpl();
}

This makes what should be simple code difficult to follow and is a sign that the concepts underpinning this PR are not fully thought through. I think you should go back and clarify this PR before asking the committers to review it again.

@paullatzelsperger
Copy link
Member

paullatzelsperger commented Jan 22, 2025

@SaschaIsele

Also saw the PR #4749 from @paullatzelsperger which already takes care of the refactoring part for the current token authentication and would reroute the changes specified for the HashicorpVaultClientto the HashicorpVault.java and HashicorpVaultHealthService, depending on which PR gets merged first.

that PR just cleans up a - frankly speaking - poor implementation of the HashicorpVault, and it adds a facility to do remote signing/verifying and key rotation.

Copy link
Member

@paullatzelsperger paullatzelsperger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two major gripes with this PR:

  1. succinctness: a lot of stuff is explained, that is already covered by documentation. This would make the DR much shorter and more concise.
  2. design: a few services seem to emerge from the Hashicorp Vault area (again, PR feat: implement Hashicorp Vault signing service #4749):
  • a secure key-value store (the "vault") -> HashicorpVault
  • a signing service HashicorpSignatureService
  • a health check service HashicorpHealthService
    all of these services share the same auth method. I think this DR should mention that.


## Decision

Refactor the HashiCorp Vault extension and make it extensible with different methods of authentication.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Refactor the HashiCorp Vault extension and make it extensible with different methods of authentication.
We will refactor the HashiCorp Vault extension and make it extensible with different methods of authentication.


## Rationale

The current implementation of the authentication in the HashiCorp Vault extension has no way to add new authentication methods.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're not adding (As in: there could be several at runtime), but replacing

Suggested change
The current implementation of the authentication in the HashiCorp Vault extension has no way to add new authentication methods.
The current implementation of the authentication in the HashiCorp Vault extension has no way to customize/exchange authentication methods.


## Approach

The refactor will affect only the `vault-hashicorp` extension.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The refactor will affect only the `vault-hashicorp` extension.
The refactor will affect only the `vault-hashicorp` module.

}
```

`HashicorpVaultAuthClientTokenProvider` implementations will be used by the `HashicorpVaultClient` to receive the `client_token` for the request authentication.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

careful, the hashicorp vault stuff is in the process (#4749) of being refactored. in essence, the HashicorpVaultClient is demoted to being "just" a health service.

`HashicorpVaultAuthClientTokenProvider` implementations will be used by the `HashicorpVaultClient` to receive the `client_token` for the request authentication.
More on that in the sections [Hashicorp Vault Auth Provision](#Hashicorp-Vault-Auth-Provision) and [HashiCorp Vault Client](#HashiCorp-Vault-Client)

### Haschicorp Vault Auth Extensions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo


For every authentication method, an implementation of the [Hashicorp Vault Auth interface](#hashicorp-vault-auth-interface) is needed.
Each `HashicorpVaultAuthClientTokenProvider` implementation represents a different authentication method and is packaged inside its own service extension.
In this way, it can easily be added/removed from the runtime and maintained in one place.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spurious. no need to explain.

Each `HashicorpVaultAuthClientTokenProvider` implementation represents a different authentication method and is packaged inside its own service extension.
In this way, it can easily be added/removed from the runtime and maintained in one place.
Due to the possible differences in the needed configuration of different authentication methods, each Service Extension will need its own configuration values specific to the authentication method.
The exception will be the token authentication, which is already packaged inside the `HashicorpVaultExtension` and used as the default authentication method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the token auth is no exception. it also has its own set of config values (token renewal etc.)


```java
@Provider(isDefault = true)
public HashicorpVaultAuthClientTokenProvider HashicorpVaultAuthClientTokenProvider() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

methods are lowercase

}
```

`isDefault = true` signifies, that `HashicorpVaultAuthTokenImpl` will be used unless another extension overwrites it by providing its own implementation without the parameter.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to explain. that is covered extensively in documentation.


`isDefault = true` signifies, that `HashicorpVaultAuthTokenImpl` will be used unless another extension overwrites it by providing its own implementation without the parameter.

The provided implementation of `HashicorpVaultAuthClientTokenProvider` is then injected into the `HashicorpVaultExtension` to be used in the `HashicorpVaultClient` later on.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs: HashiCorp Vault authentication refactor decision record
3 participants