Skip to content

Commit 1d18e52

Browse files
Lauren Voswinkelmp911de
Lauren Voswinkel
authored andcommitted
Adding Transform Secrets Engine support
This feature is only available if your vault binary is an enterprise version 1.4 or higher. Original pull request: gh-570.
1 parent 06eb318 commit 1d18e52

13 files changed

+1363
-7
lines changed

spring-vault-core/src/main/java/org/springframework/vault/core/VaultOperations.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ public interface VaultOperations {
8484
*/
8585
VaultTokenOperations opsForToken();
8686

87+
/**
88+
* @return the operations interface to interact with the Vault transform backend.
89+
* @since 2.3
90+
*/
91+
VaultTransformOperations opsForTransform();
92+
93+
/**
94+
* Return {@link VaultTransformOperations} if the transit backend is mounted on a
95+
* different path than {@code transform}.
96+
* @param path the mount path
97+
* @return the operations interface to interact with the Vault transform backend.
98+
* @since 2.3
99+
*/
100+
VaultTransformOperations opsForTransform(String path);
101+
87102
/**
88103
* @return the operations interface to interact with the Vault transit backend.
89104
*/

spring-vault-core/src/main/java/org/springframework/vault/core/VaultTemplate.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,16 @@ public VaultTokenOperations opsForToken() {
320320
return new VaultTokenTemplate(this);
321321
}
322322

323+
@Override
324+
public VaultTransformOperations opsForTransform() {
325+
return opsForTransform("transform");
326+
}
327+
328+
@Override
329+
public VaultTransformOperations opsForTransform(String path) {
330+
return new VaultTransformTemplate(this, path);
331+
}
332+
323333
@Override
324334
public VaultTransitOperations opsForTransit() {
325335
return opsForTransit("transit");
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.vault.core;
17+
18+
import org.springframework.vault.support.*;
19+
20+
import java.util.List;
21+
22+
/**
23+
* Interface that specifies operations using the {@code transform} backend.
24+
*
25+
* @author Lauren Voswinkel
26+
* @see <a href="https://www.vaultproject.io/docs/secrets/transform/index.html">Transform
27+
* Secrets Engine</a>
28+
* @since 2.3
29+
*/
30+
public interface VaultTransformOperations {
31+
/**
32+
* Encodes the provided plaintext using the named role.
33+
* @param roleName must not be empty or {@literal null}.
34+
* @param plaintext must not be empty or {@literal null}.
35+
* @return cipher text.
36+
*/
37+
String encode(String roleName, String plaintext);
38+
39+
/**
40+
* Encodes the provided plaintext using the named role.
41+
* @param roleName must not be empty or {@literal null}.
42+
* @param plaintext must not be {@literal null}.
43+
* @return cipher text.
44+
*/
45+
TransformCiphertext encode(String roleName, TransformPlaintext plaintext);
46+
47+
/**
48+
* Encodes the provided plaintext using the named role.
49+
* @param roleName must not be empty or {@literal null}.
50+
* @param plaintext must not be empty or {@literal null}.
51+
* @param transformRequest must not be {@literal null}. Use
52+
* {@link VaultTransformContext#empty()} if no request options provided.
53+
* @return cipher text.
54+
*/
55+
String encode(String roleName, byte[] plaintext, VaultTransformContext transformRequest);
56+
57+
/**
58+
* Encode the provided batch of plaintext using the role given and transformation in
59+
* each list item. The encryption is done using transformation secret backend's batch
60+
* operation.
61+
* @param roleName must not be empty or {@literal null}.
62+
* @param batchRequest a list of {@link Plaintext} which includes plaintext and an
63+
* optional context.
64+
* @return the encrypted result in the order of {@code batchRequest} plaintexts.
65+
*/
66+
List<VaultTransformEncodeResult> encode(String roleName, List<TransformPlaintext> batchRequest);
67+
68+
/**
69+
* Decode the provided ciphertext using the named role.
70+
* @param roleName must not be empty or {@literal null}.
71+
* @param ciphertext must not be empty or {@literal null}.
72+
* @return plain text.
73+
*/
74+
String decode(String roleName, String ciphertext);
75+
76+
/**
77+
* Decode the provided ciphertext using the named role.
78+
* @param roleName must not be empty or {@literal null}.
79+
* @param ciphertext must not be {@literal null}.
80+
* @return plain text.
81+
*/
82+
TransformPlaintext decode(String roleName, TransformCiphertext ciphertext);
83+
84+
/**
85+
* Decode the provided ciphertext using the named role.
86+
* @param roleName must not be empty or {@literal null}.
87+
* @param ciphertext must not be empty or {@literal null}.
88+
* @param transformContext must not be {@literal null}. Use
89+
* {@link VaultTransformContext#empty()} if no request options provided.
90+
* @return plain text.
91+
*/
92+
String decode(String roleName, String ciphertext, VaultTransformContext transformContext);
93+
94+
/**
95+
* Decode the provided batch of ciphertext using the role given and transformation in
96+
* each list item. The decryption is done using transformation secret backend's batch
97+
* operation.
98+
* @param roleName must not be empty or {@literal null}.
99+
* @param batchRequest a list of {@link Ciphertext} which includes plaintext and an
100+
* optional context.
101+
* @return the decrypted result in the order of {@code batchRequest} ciphertexts.
102+
*/
103+
List<VaultTransformDecodeResult> decode(String roleName, List<TransformCiphertext> batchRequest);
104+
}

0 commit comments

Comments
 (0)