Skip to content

Commit b7f32a7

Browse files
Fix wallet_location JSON Object handling (#184)
* Fix wallet_location JSON Object handling * Remove unused imports
1 parent 7e50671 commit b7f32a7

File tree

10 files changed

+202
-60
lines changed

10 files changed

+202
-60
lines changed

ojdbc-provider-aws/README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ The {S3-URI} can be obtained from the Amazon S3 console and follows this naming
6868

6969
### JSON Payload format
7070

71-
There are 3 fixed values that are looked at the root level.
71+
There are 4 fixed values that are looked at the root level.
7272

7373
- connect_descriptor (required)
7474
- user (optional)
7575
- password (optional)
76+
- wallet_location (optional)
7677

7778
The rest are dependent on the driver, in our case `/jdbc`. The key-value pairs that are with sub-prefix `/jdbc` will be applied to a DataSource. The key values are constant keys which are equivalent to the properties defined in the [OracleConnection](https://docs.oracle.com/en/database/oracle/oracle-database/23/jajdb/oracle/jdbc/OracleConnection.html) interface.
7879

@@ -93,6 +94,11 @@ And the JSON Payload for the file **payload_ojdbc_objectstorage.json** in **mybu
9394
"value": "test-secret",
9495
"field_name": "<field-name>" // Optional: Only needed when the secret is structured and contains multiple key-value pairs.
9596
},
97+
"wallet_location": {
98+
"type": "awssecretsmanager",
99+
"value": "wallet-secret",
100+
"field_name": "<field-name>" // Optional: Only needed when the secret is structured and contains multiple key-value pairs.
101+
},
96102
"jdbc": {
97103
"oracle.jdbc.ReadTimeout": 1000,
98104
"defaultRowPrefetch": 20,
@@ -117,32 +123,52 @@ The sample code below executes as expected with the previous configuration.
117123

118124
For the JSON type of provider (AWS S3, AWS Secrets Manager, HTTP/HTTPS, File) the password is an object itself with the following spec:
119125

120-
- type
126+
- `type`
121127
- Mandatory
122128
- Possible values
123-
- ocivault
124-
- azurevault
125-
- base64
126-
- awssecretsmanager
127-
- value
129+
- `ocivault` (OCI Vault)
130+
- `azurevault` (Azure Key Vault)
131+
- `base64` (Base64)
132+
- `awssecretsmanager` (AWS Secrets Manager)
133+
- `hcpvaultdedicated` (HCP Vault Dedicated)
134+
- `hcpvaultsecret` (HCP Vault Secrets)
135+
- `gcpsecretmanager` (GCP Secret Manager)
136+
- `value`
128137
- Mandatory
129138
- Possible values
130139
- OCID of the secret (if ocivault)
131140
- Azure Key Vault URI (if azurevault)
132141
- Base64 Encoded password (if base64)
133142
- AWS Secret name (if awssecretsmanager)
134-
- field_name
143+
- Secret path (if hcpvaultdedicated)
144+
- Secret name (if hcpvaultsecret)
145+
- Secret name (if gcpsecretmanager)
146+
- `field_name`
135147
- Optional
136148
- Description: Specifies the key within the secret JSON object from which to extract the password value.
137149
If the secret JSON contains multiple key-value pairs, field_name must be provided to unambiguously select the desired secret value.
138150
If the secret contains only a single key-value pair and field_name is not provided, that sole value will be used.
139151
If the secret is provided as plain text (i.e., not structured as a JSON object), no field_name is required.
140-
- authentication
152+
- `authentication`
141153
- Optional
142154
- Possible Values
143155
- method
144156
- optional parameters (depends on the cloud provider).
145157

158+
### Wallet_location JSON Object
159+
160+
The `oracle.net.wallet_location` connection property is not allowed in the `jdbc` object due to security reasons. Instead, users should use the `wallet_location` object to specify the wallet in the configuration.
161+
162+
For the JSON type of provider (AWS S3, HTTPS, File) the wallet_location is an object itself with the same spec as the [password JSON object](#password-json-object) mentioned above.
163+
164+
The value stored in the secret should be the Base64 representation of the bytes in `cwallet.sso`. This is equivalent to setting the `oracle.net.wallet_location` connection property in a regular JDBC application using the following format:
165+
166+
```
167+
data:;base64,<Base64 representation of the bytes in cwallet.sso>
168+
```
169+
170+
<i>*Note: When storing a wallet in AWS Secrets Manager, store the raw Base64-encoded wallet bytes directly. The provider will automatically detect and handle the encoding correctly.</i>
171+
146172
## AWS Secrets Manager Config Provider
147173
Apart from AWS S3, users can also store JSON Payload in the content of AWS Secrets Manager secret. Users need to indicate the secret name:
148174

ojdbc-provider-aws/src/main/java/oracle/jdbc/provider/aws/configuration/AwsJsonSecretsManagerProvider.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,11 @@
4242
import oracle.jdbc.provider.parameter.ParameterSet;
4343
import oracle.jdbc.spi.OracleConfigurationSecretProvider;
4444

45-
import java.nio.charset.StandardCharsets;
46-
import java.util.Base64;
4745
import java.util.Map;
4846

4947
import static oracle.jdbc.provider.aws.configuration.AwsConfigurationParameters.FIELD_NAME;
5048
import static oracle.jdbc.provider.aws.configuration.AwsSecretsManagerConfigurationProvider.PARAMETER_SET_PARSER;
49+
import static oracle.jdbc.provider.util.FileUtils.toBase64EncodedCharArray;
5150

5251
public class AwsJsonSecretsManagerProvider
5352
implements OracleConfigurationSecretProvider {
@@ -96,9 +95,7 @@ public char[] getSecret(Map<String, String> map) {
9695
String extractedSecret = AwsSecretExtractor.extractSecret(secretString,
9796
fieldName);
9897

99-
return Base64.getEncoder()
100-
.encodeToString(extractedSecret.getBytes(StandardCharsets.UTF_8))
101-
.toCharArray();
98+
return toBase64EncodedCharArray(extractedSecret);
10299
}
103100

104101
@Override

ojdbc-provider-azure/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,51 @@ The sample code below executes as expected with the previous configuration (and
103103
if (rs.next())
104104
System.out.println("select sysdate from dual: " + rs.getString(1));
105105
```
106+
### Password JSON Object
107+
108+
For the JSON type of provider (Azure App Configuration, Azure Key Vault, HTTP/HTTPS, File) the password is an object itself with the following spec:
109+
110+
- `type`
111+
- Mandatory
112+
- Possible values
113+
- `azurevault` (Azure Key Vault)
114+
- `ocivault` (OCI Vault)
115+
- `base64` (Base64)
116+
- `awssecretsmanager` (AWS Secrets Manager)
117+
- `hcpvaultdedicated` (HCP Vault Dedicated)
118+
- `hcpvaultsecret` (HCP Vault Secrets)
119+
- `gcpsecretmanager` (GCP Secret Manager)
120+
- `value`
121+
- Mandatory
122+
- Possible values
123+
- Azure Key Vault URI (if azurevault)
124+
- OCID of the secret (if ocivault)
125+
- Base64 Encoded password (if base64)
126+
- AWS Secret name (if awssecretsmanager)
127+
- Secret path (if hcpvaultdedicated)
128+
- Secret name (if hcpvaultsecret)
129+
- Secret name (if gcpsecretmanager)
130+
- `authentication`
131+
- Optional
132+
- Possible Values
133+
- method
134+
- optional parameters (depends on the cloud provider).
135+
136+
### Wallet_location JSON Object
137+
138+
The `oracle.net.wallet_location` connection property is not allowed in the `jdbc` object due to security reasons. Instead, users should use the `wallet_location` object to specify the wallet in the configuration.
139+
140+
For the JSON type of provider (Azure App Configuration, HTTPS, File) the `wallet_location` is an object itself with the same spec as the [password JSON object](#password-json-object) mentioned above.
141+
142+
The value stored in the secret should be the Base64 representation of the bytes in `cwallet.sso`. This is equivalent to setting the `oracle.net.wallet_location` connection property in a regular JDBC application using the following format:
143+
144+
```
145+
data:;base64,<Base64 representation of the bytes in cwallet.sso>
146+
```
147+
148+
<i>*Note: When storing a wallet in Azure Key Vault, store the raw Base64-encoded wallet bytes directly. The provider will automatically detect and handle the encoding correctly.</i>
149+
150+
106151
## Azure Vault Config Provider
107152
Similar to [OCI Vault Config Provider](../ojdbc-provider-oci/README.md#oci-vault-config-provider), JSON Payload can also be stored in the content of Azure Key Vault Secret.
108153
The Oracle Data Source uses a new prefix `jdbc:oracle:thin:@config-azurevault://`. Users only need to indicate the Vault Secret’s secret identifier using the following syntax, where option-value pairs separated by `&` are optional authentication parameters that vary by provider:

ojdbc-provider-azure/src/main/java/oracle/jdbc/provider/azure/configuration/AzureVaultSecretProvider.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@
4444
import oracle.jdbc.provider.parameter.ParameterSet;
4545
import oracle.jdbc.provider.parameter.ParameterSetParser;
4646

47-
import java.util.Base64;
4847
import java.util.Map;
4948

49+
import static oracle.jdbc.provider.util.FileUtils.toBase64EncodedCharArray;
50+
5051
/**
5152
* A provider of Secret values from Azure Key Vault.
5253
*/
@@ -97,9 +98,7 @@ public char[] getSecret(Map<String, String> secretProperties) {
9798
.getContent()
9899
.getValue();
99100

100-
return Base64.getEncoder()
101-
.encodeToString(secretString.getBytes())
102-
.toCharArray();
101+
return toBase64EncodedCharArray(secretString);
103102
}
104103

105104
/**

ojdbc-provider-common/src/main/java/oracle/jdbc/provider/util/FileUtils.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
package oracle.jdbc.provider.util;
4040

41+
import java.nio.charset.StandardCharsets;
4142
import java.util.Base64;
4243

4344
/**
@@ -67,4 +68,25 @@ public static byte[] decodeIfBase64(byte[] input) {
6768
return isBase64Encoded(input) ? Base64.getDecoder().decode(input)
6869
: input;
6970
}
71+
72+
/**
73+
* Converts a secret string to a Base64-encoded char array.
74+
* If the secret is already Base64-encoded, it is returned as a char array.
75+
* Otherwise, it is encoded to Base64.
76+
*
77+
* @param secretString The secret string to process
78+
* @return A char array containing the Base64-encoded secret,
79+
* or null if the input is null
80+
*/
81+
public static char[] toBase64EncodedCharArray(String secretString) {
82+
if (secretString == null) {
83+
return null;
84+
}
85+
byte[] secretBytes = secretString.getBytes(StandardCharsets.UTF_8);
86+
if (isBase64Encoded(secretBytes)) {
87+
return secretString.toCharArray();
88+
} else {
89+
return Base64.getEncoder().encodeToString(secretBytes).toCharArray();
90+
}
91+
}
7092
}

ojdbc-provider-gcp/README.md

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ And the JSON Payload for the file **payload_ojdbc_objectstorage.json** in the **
109109
"type": "gcpsecretmanager",
110110
"value": "projects/138028249883/secrets/test-secret/versions/1"
111111
},
112+
"wallet_location": {
113+
"type": "gcpsecretmanager",
114+
"value": "projects/myproject/secrets/wallet-secret/versions/1"
115+
},
112116
"jdbc": {
113117
"oracle.jdbc.ReadTimeout": 1000,
114118
"defaultRowPrefetch": 20,
@@ -133,27 +137,50 @@ The sample code below executes as expected with the previous configuration.
133137

134138
For the JSON type of provider (GCP Object Storage, HTTP/HTTPS, File) the password is an object itself with the following spec:
135139

136-
- type
140+
- `type`
137141
- Mandatory
138142
- Possible values
139-
- ocivault
140-
- azurevault
141-
- base64
142-
- gcpsecretmanager
143-
- value
143+
- `gcpsecretmanager` (GCP Secret Manager)
144+
- `ocivault` (OCI Vault)
145+
- `azurevault` (Azure Key Vault)
146+
- `base64` (Base64)
147+
- `awssecretsmanager` (AWS Secrets Manager)
148+
- `hcpvaultdedicated` (HCP Vault Dedicated)
149+
- `hcpvaultsecret` (HCP Vault Secrets)
150+
- `value`
144151
- Mandatory
145152
- Possible values
153+
- Secret name (if gcpsecretmanager)
146154
- OCID of the secret (if ocivault)
147155
- Azure Key Vault URI (if azurevault)
148156
- Base64 Encoded password (if base64)
149-
- GCP resource name (if gcpsecretmanager)
150-
- Text
151-
- authentication
157+
- AWS Secret name (if awssecretsmanager)
158+
- Secret path (if hcpvaultdedicated)
159+
- Secret name (if hcpvaultsecret)
160+
- `authentication`
152161
- Optional
153162
- Possible Values
154163
- method
155164
- optional parameters (depends on the cloud provider).
156165

166+
### Wallet_location JSON Object
167+
168+
The `oracle.net.wallet_location` connection property is not allowed in the "jdbc" object due to security reasons. Instead, users should use the `wallet_location object to specify the wallet in the configuration.
169+
170+
For the JSON type of provider (GCP Cloud Storage, HTTPS, File) the `wallet_location` is an object itself with the same spec as the [password JSON object](#password-json-object) mentioned above.
171+
172+
The value stored in the secret can be either:
173+
174+
- The Base64 representation of the bytes in cwallet.sso.
175+
- The raw bytes of the cwallet.sso file, stored as an imported file.
176+
177+
In both cases, the provider will automatically handle the content. If the secret contains raw bytes (e.g., an imported cwallet.sso file), the provider will perform Base64 encoding as needed. The resulting format is equivalent to setting the oracle.net.wallet_location connection property in a regular JDBC application using the following format:
178+
```
179+
data:;base64,<Base64 representation of the bytes in cwallet.sso>
180+
```
181+
182+
<i>*Note: When storing a wallet in GCP Secret Manager, you can either store the raw bytes of the cwallet.sso file directly or provide the Base64-encoded string. The provider will detect the format and handle the encoding appropriately.</i>
183+
157184
## GCP Secret Manager Config Provider
158185
Apart from GCP Cloud Storage, users can also store JSON Payload in the content of GCP Secret Manager secret. Users need to indicate the resource name:
159186

0 commit comments

Comments
 (0)