Create a wrapped Token to access Hashicorp Vault | Spring Boot

126 views Asked by At

I want to create a wrapped token programmatically from my Spring Boot application in order to read/write key-value pairs to/from Hashicorp vault. I have gone through the documentation.

Currently I am able to create a token having a TTL, use limit and a policy, but I did not find any option to wrap the token. I am using the following code to create the token:

    private VaultTokenResponse getDefaultToken() {
        List<String> policies = Arrays.asList("default");
        VaultTokenRequest tokenRequest = VaultTokenRequest.builder()
                .ttl(10, TimeUnit.MINUTES)
                .numUses(10)
                .policies(policies)
                .renewable(true)
                .build();
        return VaultConfig.vaultTemplate.opsForToken().create(tokenRequest);
    }
1

There are 1 answers

0
Arpit On BEST ANSWER

You can try to use VaultWrappingOperations on the token once you have created it. Something like

VaultWrappingOperations operations = vaultOperations.opsForWrapping();
WrappedMetadata metadata = operations.wrap(map, Duration.ofMinutes(10));
metadata.getToken();