Skip to content

Commit c726579

Browse files
docs: add decision record for HashiCorp vault authentication refactoring (#4802)
Co-authored-by: Sascha Isele <[email protected]>
1 parent a17d4ab commit c726579

File tree

2 files changed

+81
-0
lines changed
  • docs/developer/decision-records

2 files changed

+81
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# HashiCorp Vault authentication refactor
2+
3+
## Decision
4+
5+
We will refactor the HashiCorp Vault implementation to support the usage of different methods of authentication.
6+
7+
## Rationale
8+
9+
The HashiCorp Vault supports multiple different authentication methods, but the current implementation supports
10+
only one and provides no way to customize or exchange authentication methods. The full list of supported
11+
methods can be found in the [HashiCorp Vault Documentation](https://developer.hashicorp.com/vault/docs/auth). Some examples are:
12+
13+
* [Token auth method](https://developer.hashicorp.com/vault/docs/auth/token) (already supported)
14+
* [Kubernetes auth method](https://developer.hashicorp.com/vault/docs/auth/kubernetes)
15+
* [AppRole auth method](https://developer.hashicorp.com/vault/docs/auth/approle)
16+
17+
## Approach
18+
19+
The refactoring will be limited to the `vault-hashicorp` module.
20+
21+
The common denominator among all authentication methods is the ability to provide a `client_token` for
22+
authentication against the vault. Therefore, obtaining this token will be moved to an interface.
23+
24+
```java
25+
@ExtensionPoint
26+
public interface HashicorpVaultTokenProvider {
27+
String vaultToken();
28+
}
29+
```
30+
31+
This interface will be the extension point for downstream projects to introduce different authentication methods by
32+
providing a respective implementation of this interface to the runtime context.
33+
The [token auth method](https://developer.hashicorp.com/vault/docs/auth/token) is already supported by the current implementation and will remain the default
34+
implementation provided through the `HashicorpVaultExtension`.
35+
The respective code will therefore be moved to a class implementing `HashicorpVaultTokenProvider`.
36+
37+
### Services accessing the vault
38+
39+
Any service that needs to access the vault will be refactored to use the `HashicorpVaultTokenProvider` for obtaining
40+
the token. Namely, affected services are:
41+
42+
* `HashicorpVault` (secure key-value store)
43+
* `HashicorpVaultSignatureService` (signing service)
44+
* `HashicorpVaultHealthService` (health check service)
45+
46+
All of these services currently get the token from the `HashicorpVaultSettings`, which will be replaced by a call to
47+
the `HashicorpVaultTokenProvider`.
48+
49+
### HashicorpVaultHealthService
50+
51+
In addition, the `HashicorpVaultHealthService` currently stores the headers for all requests to the vault in a
52+
class variable, which is populated once upon service instantiation. As the token, and thus the headers,
53+
may not be static for all authentication methods, the variable will be removed. Instead, the token will be fetched from
54+
the `HashicorpVaultTokenProvider` and the headers will be generated for every request. The token will therefore be
55+
added as a parameter to the `getHeaders` method.
56+
57+
```java
58+
@NotNull
59+
private Headers getHeaders(String token) {
60+
var headersBuilder = new Headers.Builder().add(VAULT_REQUEST_HEADER, Boolean.toString(true));
61+
headersBuilder.add(VAULT_TOKEN_HEADER, token);
62+
return headersBuilder.build();
63+
}
64+
```
65+
66+
The `HashicorpVaultHealthService` also provides methods for checking whether a token can be renewed as well as for
67+
renewing the token. As these features are not available for all authentication methods, this functionality should be
68+
moved to a different class. This part of the refactoring is already planned anyway for better separation of concerns.
69+
70+
### HashicorpVaultHealthCheck
71+
72+
The `get()` method of `HashicorpVaultHealthCheck` currently returns a merged result, using the response from the
73+
health API and the response to whether the current token can be renewed. After the refactor, it is no longer
74+
guaranteed that token renewal is supported. The second check will therefore be removed from the method, which
75+
then simply returns the result of the health check.
76+
77+
## Further Considerations
78+
79+
This decision record only paves the way to add additional authentication methods in the future. The actual support and
80+
implementation of any additional authentication methods is therefore out of scope of this decision record.

docs/developer/decision-records/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,4 @@
7373
- [2025-01-28 Async Protocol Message Process](./2025-01-28-async-protocol-message-processing)
7474
- [2025-02-05 State Machine Retry Processor refactor](./2025-02-05-state-machine-retry-processor-refactor)
7575
- [2025-02-06 Object mutability and copying](./2025-02-06-object_mutability_and_copying)
76+
- [2025-02-06 HashiCorp Vault Authentication Refactor](./2025-02-06-hashicorp-vault-authentication-refactor)

0 commit comments

Comments
 (0)