-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathSecretsManager.java
More file actions
640 lines (600 loc) · 25.9 KB
/
SecretsManager.java
File metadata and controls
640 lines (600 loc) · 25.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/*
* Copyright 2021 Collate
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openmetadata.service.secrets;
import static java.util.Objects.isNull;
import com.google.common.annotations.VisibleForTesting;
import jakarta.ws.rs.core.Response;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.openmetadata.annotations.PasswordField;
import org.openmetadata.common.utils.CommonUtil;
import org.openmetadata.schema.auth.BasicAuthMechanism;
import org.openmetadata.schema.auth.JWTAuthMechanism;
import org.openmetadata.schema.entity.automations.Workflow;
import org.openmetadata.schema.entity.services.ServiceType;
import org.openmetadata.schema.entity.services.ingestionPipelines.IngestionPipeline;
import org.openmetadata.schema.entity.teams.AuthenticationMechanism;
import org.openmetadata.schema.security.client.OpenMetadataJWTClientConfig;
import org.openmetadata.schema.security.secrets.Parameters;
import org.openmetadata.schema.security.secrets.SecretsManagerProvider;
import org.openmetadata.schema.services.connections.metadata.OpenMetadataConnection;
import org.openmetadata.service.exception.InvalidServiceConnectionException;
import org.openmetadata.service.exception.SecretsManagerException;
import org.openmetadata.service.fernet.Fernet;
import org.openmetadata.service.secrets.converter.ClassConverterFactory;
import org.openmetadata.service.util.AuthenticationMechanismBuilder;
import org.openmetadata.service.util.IngestionPipelineBuilder;
import org.openmetadata.service.util.ReflectionUtil;
@Slf4j
public abstract class SecretsManager {
public static final String SECRET_FIELD_PREFIX = "secret:";
public record SecretsConfig(
String clusterName, String prefix, List<String> tags, Parameters parameters) {}
protected record SecretsIdConfig(
String separator,
Boolean needsStartingSeparator,
String cleanSecretReplacer,
Pattern secretIdPattern) {}
@Getter private final SecretsConfig secretsConfig;
@Getter private final SecretsManagerProvider secretsManagerProvider;
@Getter private final SecretsIdConfig secretsIdConfig;
private Fernet fernet;
private static final Set<Class<?>> DO_NOT_ENCRYPT_CLASSES =
Set.of(OpenMetadataJWTClientConfig.class, BasicAuthMechanism.class);
protected SecretsManager(
SecretsManagerProvider secretsManagerProvider, SecretsConfig secretsConfig) {
this.secretsManagerProvider = secretsManagerProvider;
this.secretsConfig = secretsConfig;
this.fernet = Fernet.getInstance();
this.secretsIdConfig = builSecretsIdConfig();
}
public Boolean isSecret(String string) {
return string.startsWith(SECRET_FIELD_PREFIX);
}
public String getSecretValue(String secretWithPrefix) {
String secretName = secretWithPrefix.split(SECRET_FIELD_PREFIX, 2)[1];
return getSecret(secretName);
}
/**
* GET a secret using the SM implementation if the string starts with `secret:/`
*/
abstract String getSecret(String secretName);
/**
* Override this method in any Secrets Manager implementation
* that has other requirements
*/
protected SecretsIdConfig builSecretsIdConfig() {
return new SecretsIdConfig("/", Boolean.TRUE, "_", Pattern.compile("[^A-Za-z0-9/_\\-]"));
}
public Object encryptServiceConnectionConfig(
Object connectionConfig,
String connectionType,
String connectionName,
ServiceType serviceType) {
try {
Object newConnectionConfig =
SecretsUtil.convert(connectionConfig, connectionType, connectionName, serviceType);
return encryptPasswordFields(
newConnectionConfig, buildSecretId(true, serviceType.value(), connectionName), true);
} catch (Exception e) {
String message =
SecretsUtil.buildExceptionMessageConnection(e.getMessage(), connectionType, true);
if (message != null) {
throw new InvalidServiceConnectionException(message);
}
throw InvalidServiceConnectionException.byMessage(
connectionType,
String.format(
"Failed to encrypt connection instance of %s. Did the Fernet Key change?",
connectionType));
}
}
public Object decryptServiceConnectionConfig(
Object connectionConfig, String connectionType, ServiceType serviceType) {
try {
Object newConnectionConfig =
SecretsUtil.convert(connectionConfig, connectionType, null, serviceType);
return decryptPasswordFields(newConnectionConfig);
} catch (Exception e) {
String message =
SecretsUtil.buildExceptionMessageConnection(e.getMessage(), connectionType, false);
if (message != null) {
throw new InvalidServiceConnectionException(message);
}
throw InvalidServiceConnectionException.byMessage(
connectionType,
String.format(
"Failed to decrypt connection instance of %s. Did the Fernet Key change?",
connectionType));
}
}
public Object encryptAuthenticationMechanism(
String name, AuthenticationMechanism authenticationMechanism) {
if (authenticationMechanism != null) {
AuthenticationMechanismBuilder.addDefinedConfig(authenticationMechanism);
try {
return encryptPasswordFields(
authenticationMechanism, buildSecretId(true, "bot", name), true);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST,
String.format("Failed to encrypt user bot instance [%s]", name));
}
}
return null;
}
/**
* Encrypts QueryRunner config secrets using a path structure that groups secrets under the
* database service: /{cluster}/DatabaseService/{serviceName}/queryrunner/{configType}/{field}
*
* @param authConfig The auth config object containing password fields to encrypt
* @param serviceName The database service name (e.g., "my-snowflake-prod")
* @param configType The config type (ADMIN or USER)
* @return The auth config with password fields replaced by secret references
*/
public Object encryptQueryRunnerConfig(Object authConfig, String serviceName, String configType) {
if (authConfig == null) {
return null;
}
try {
// Path: /argo/DatabaseService/my-snowflake-prod/queryrunner/admin/clientsecret
return encryptPasswordFields(
authConfig,
buildSecretId(true, "DatabaseService", serviceName, "queryrunner", configType),
true);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST,
String.format(
"Failed to encrypt query runner config for service [%s], type [%s]",
serviceName, configType));
}
}
public Object decryptQueryRunnerConfig(Object authConfig) {
if (authConfig == null) {
return null;
}
try {
return decryptPasswordFields(authConfig);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST, "Failed to decrypt query runner config");
}
}
/**
* Deletes QueryRunner config secrets from the secrets manager.
* Uses the same path structure as encryptQueryRunnerConfig:
* /{cluster}/DatabaseService/{serviceName}/queryrunner/{configType}/{field}
*
* @param authConfig The auth config object to identify which fields to delete
* @param serviceName The database service name
* @param configType The config type: "admin" or "user"
*/
public void deleteQueryRunnerConfigSecrets(
Object authConfig, String serviceName, String configType) {
if (authConfig != null) {
try {
deleteSecrets(
authConfig,
buildSecretId(true, "DatabaseService", serviceName, "queryrunner", configType));
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST,
String.format(
"Failed to delete secrets for query runner config, service [%s], type [%s]",
serviceName, configType));
}
}
}
/**
* This is used to handle the JWT Token internally, in the JWTFilter, when
* calling for the auth-mechanism in the UI, etc.
* If using SM, we need to decrypt and GET the secret to ensure we are comparing
* the right values.
*/
public AuthenticationMechanism decryptAuthenticationMechanism(
String name, AuthenticationMechanism authenticationMechanism) {
if (authenticationMechanism != null) {
AuthenticationMechanismBuilder.addDefinedConfig(authenticationMechanism);
try {
AuthenticationMechanism fernetDecrypted =
(AuthenticationMechanism) decryptPasswordFields(authenticationMechanism);
return (AuthenticationMechanism) getSecretFields(fernetDecrypted);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST,
String.format(
"Failed to decrypt user bot instance [%s] due to [%s]", name, e.getMessage()));
}
}
return null;
}
public OpenMetadataJWTClientConfig decryptJWTConfig(OpenMetadataJWTClientConfig jwtConfig) {
if (jwtConfig != null) {
try {
OpenMetadataJWTClientConfig decrypted =
(OpenMetadataJWTClientConfig) decryptPasswordFields(jwtConfig);
return (OpenMetadataJWTClientConfig) getSecretFields(decrypted);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST, "Failed to decrypt JWT Client Config instance.");
}
}
return null;
}
public void encryptIngestionPipeline(IngestionPipeline ingestionPipeline) {
OpenMetadataConnection openMetadataConnection =
encryptOpenMetadataConnection(ingestionPipeline.getOpenMetadataServerConnection(), true);
ingestionPipeline.setOpenMetadataServerConnection(null);
// we don't store OM conn sensitive data
IngestionPipelineBuilder.addDefinedConfig(ingestionPipeline);
try {
encryptPasswordFields(
ingestionPipeline, buildSecretId(true, "pipeline", ingestionPipeline.getName()), true);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST,
String.format(
"Failed to encrypt ingestion pipeline instance [%s]", ingestionPipeline.getName()));
}
ingestionPipeline.setOpenMetadataServerConnection(openMetadataConnection);
}
public void decryptIngestionPipeline(IngestionPipeline ingestionPipeline) {
OpenMetadataConnection openMetadataConnection =
decryptOpenMetadataConnection(ingestionPipeline.getOpenMetadataServerConnection());
ingestionPipeline.setOpenMetadataServerConnection(null);
// we don't store OM conn sensitive data
IngestionPipelineBuilder.addDefinedConfig(ingestionPipeline);
try {
decryptPasswordFields(ingestionPipeline);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST,
String.format(
"Failed to decrypt ingestion pipeline instance [%s]", ingestionPipeline.getName()));
}
ingestionPipeline.setOpenMetadataServerConnection(openMetadataConnection);
}
public Workflow encryptWorkflow(Workflow workflow) {
OpenMetadataConnection openMetadataConnection =
encryptOpenMetadataConnection(workflow.getOpenMetadataServerConnection(), true);
Workflow workflowConverted =
(Workflow) ClassConverterFactory.getConverter(Workflow.class).convert(workflow);
// we don't store OM conn sensitive data
workflowConverted.setOpenMetadataServerConnection(null);
try {
encryptPasswordFields(
workflowConverted, buildSecretId(true, "workflow", workflow.getName()), true);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST,
String.format("Failed to encrypt workflow instance [%s]", workflow.getName()));
}
workflowConverted.setOpenMetadataServerConnection(openMetadataConnection);
return workflowConverted;
}
public Workflow decryptWorkflow(Workflow workflow) {
OpenMetadataConnection openMetadataConnection =
decryptOpenMetadataConnection(workflow.getOpenMetadataServerConnection());
Workflow workflowConverted =
(Workflow) ClassConverterFactory.getConverter(Workflow.class).convert(workflow);
// we don't store OM conn sensitive data
workflowConverted.setOpenMetadataServerConnection(null);
try {
decryptPasswordFields(workflowConverted);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST,
String.format("Failed to decrypt workflow instance [%s]", workflow.getName()));
}
workflowConverted.setOpenMetadataServerConnection(openMetadataConnection);
return workflowConverted;
}
public OpenMetadataConnection encryptOpenMetadataConnection(
OpenMetadataConnection openMetadataConnection, boolean store) {
if (openMetadataConnection != null) {
OpenMetadataConnection openMetadataConnectionConverted =
(OpenMetadataConnection)
ClassConverterFactory.getConverter(OpenMetadataConnection.class)
.convert(openMetadataConnection);
try {
encryptPasswordFields(
openMetadataConnectionConverted, buildSecretId(true, "serverconnection"), store);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST, "Failed to encrypt OpenMetadataConnection instance.");
}
return openMetadataConnectionConverted;
}
return null;
}
public OpenMetadataConnection decryptOpenMetadataConnection(
OpenMetadataConnection openMetadataConnection) {
if (openMetadataConnection != null) {
OpenMetadataConnection openMetadataConnectionConverted =
(OpenMetadataConnection)
ClassConverterFactory.getConverter(OpenMetadataConnection.class)
.convert(openMetadataConnection);
try {
decryptPasswordFields(openMetadataConnectionConverted);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST, "Failed to decrypt OpenMetadataConnection instance.");
}
return openMetadataConnectionConverted;
}
return null;
}
/**
* Used only in the OM Connection Builder, which sends the credentials to Ingestion Workflows
*/
public JWTAuthMechanism decryptJWTAuthMechanism(JWTAuthMechanism authMechanism) {
if (authMechanism != null) {
try {
decryptPasswordFields(authMechanism);
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST, "Failed to decrypt OpenMetadataConnection instance.");
}
return authMechanism;
}
return null;
}
private Object encryptPasswordFields(Object toEncryptObject, String secretId, boolean store) {
try {
if (!DO_NOT_ENCRYPT_CLASSES.contains(toEncryptObject.getClass())) {
// for each get method
Arrays.stream(toEncryptObject.getClass().getMethods())
.filter(ReflectionUtil::isGetMethodOfObject)
.forEach(
method -> {
Object obj = ReflectionUtil.getObjectFromMethod(method, toEncryptObject);
String fieldName = method.getName().replaceFirst("get", "");
// if the object matches the package of openmetadata
if (CommonUtil.isOpenMetadataObject(obj)) {
// encryptPasswordFields
encryptPasswordFields(
obj,
buildSecretId(false, secretId, fieldName.toLowerCase(Locale.ROOT)),
store);
// check if it has annotation
} else if (obj != null && method.getAnnotation(PasswordField.class) != null) {
// store value if proceed
String newFieldValue =
storeValue(
fieldName, fernet.decryptIfApplies((String) obj), secretId, store);
// get setMethod
Method toSet = ReflectionUtil.getToSetMethod(toEncryptObject, obj, fieldName);
// Issue #21259: storeValue returns null when the user clears the
// password field. Propagate that null through instead of attempting
// to fernet-encrypt it.
String finalValue;
if (newFieldValue == null) {
finalValue = null;
} else if (Fernet.isTokenized(newFieldValue)) {
finalValue = newFieldValue;
} else {
finalValue = store ? fernet.encrypt(newFieldValue) : newFieldValue;
}
ReflectionUtil.setValueInMethod(toEncryptObject, finalValue, toSet);
}
});
}
return toEncryptObject;
} catch (Exception e) {
String msg =
String.format(
"Error trying to encrypt object with secret ID [%s] due to [%s]",
secretId, e.getMessage());
LOG.error(msg);
throw new SecretsManagerException(msg);
}
}
private Object decryptPasswordFields(Object toDecryptObject) {
try {
// for each get method
Arrays.stream(toDecryptObject.getClass().getMethods())
.filter(ReflectionUtil::isGetMethodOfObject)
.forEach(
method -> {
Object obj = ReflectionUtil.getObjectFromMethod(method, toDecryptObject);
String fieldName = method.getName().replaceFirst("get", "");
// if the object matches the package of openmetadata
if (CommonUtil.isOpenMetadataObject(obj)) {
// encryptPasswordFields
decryptPasswordFields(obj);
// check if it has annotation
} else if (obj != null && method.getAnnotation(PasswordField.class) != null) {
String fieldValue = (String) obj;
// get setMethod
Method toSet = ReflectionUtil.getToSetMethod(toDecryptObject, obj, fieldName);
// Only Fernet-decrypt. Secret references (secret:/path) are returned as-is
// for the ingestion client to resolve. The server does not fetch secrets.
ReflectionUtil.setValueInMethod(
toDecryptObject,
Fernet.isTokenized(fieldValue) ? fernet.decrypt(fieldValue) : fieldValue,
toSet);
}
});
return toDecryptObject;
} catch (Exception e) {
LOG.error("Error trying to decrypt object due to [{}]", e.getMessage());
throw new SecretsManagerException(
String.format(
"Error trying to decrypt object [%s] due to [%s]",
toDecryptObject.toString(), e.getMessage()));
}
}
/**
* Get the object and use the secrets manager to get the right value to show
*/
private Object getSecretFields(Object toDecryptObject) {
try {
// for each get method
Arrays.stream(toDecryptObject.getClass().getMethods())
.filter(ReflectionUtil::isGetMethodOfObject)
.forEach(
method -> {
Object obj = ReflectionUtil.getObjectFromMethod(method, toDecryptObject);
String fieldName = method.getName().replaceFirst("get", "");
// if the object matches the package of openmetadata
if (CommonUtil.isOpenMetadataObject(obj)) {
// encryptPasswordFields
getSecretFields(obj);
// check if it has annotation
} else if (obj != null && method.getAnnotation(PasswordField.class) != null) {
String fieldValue = (String) obj;
// get setMethod
Method toSet = ReflectionUtil.getToSetMethod(toDecryptObject, obj, fieldName);
// Fetch from SM if it's a secret reference
ReflectionUtil.setValueInMethod(
toDecryptObject,
Boolean.TRUE.equals(isSecret(fieldValue))
? getSecretValue(fieldValue)
: fieldValue,
toSet);
}
});
return toDecryptObject;
} catch (Exception e) {
throw new SecretsManagerException(
String.format(
"Error trying to GET secret [%s] due to [%s]",
toDecryptObject.toString(), e.getMessage()));
}
}
protected abstract String storeValue(
String fieldName, String value, String secretId, boolean store);
protected String buildSecretId(boolean addClusterPrefix, String... secretIdValues) {
StringBuilder format = new StringBuilder();
if (addClusterPrefix) {
if (secretsConfig.prefix != null && !secretsConfig.prefix.isEmpty()) {
if (Boolean.TRUE.equals(secretsIdConfig.needsStartingSeparator())) {
format.append(secretsIdConfig.separator());
}
format.append(secretsConfig.prefix);
}
if (Boolean.TRUE.equals(secretsIdConfig.needsStartingSeparator)) {
format.append(secretsIdConfig.separator());
}
format.append(secretsConfig.clusterName);
} else {
format.append("%s");
}
Object[] cleanIdValues =
Arrays.stream(secretIdValues)
.map(
str ->
secretsIdConfig
.secretIdPattern
.matcher(str)
.replaceAll(secretsIdConfig.cleanSecretReplacer))
.toArray();
// skip first one in case of addClusterPrefix is false to avoid adding extra separator at the
// beginning
Arrays.stream(cleanIdValues)
.skip(addClusterPrefix ? 0 : 1)
.forEach(
secretIdValue -> {
if (isNull(secretIdValue)) {
throw new SecretsManagerException("Cannot build a secret id with null values.");
}
format.append(secretsIdConfig.separator);
format.append("%s");
});
return String.format(format.toString(), cleanIdValues).toLowerCase();
}
@VisibleForTesting
void setFernet(Fernet fernet) {
this.fernet = fernet;
}
protected abstract void deleteSecretInternal(String secretName);
public void deleteSecretsFromServiceConnectionConfig(
Object connectionConfig,
String connectionType,
String connectionName,
ServiceType serviceType) {
try {
Object newConnectionConfig =
SecretsUtil.convert(connectionConfig, connectionType, connectionName, serviceType);
deleteSecrets(newConnectionConfig, buildSecretId(true, serviceType.value(), connectionName));
} catch (Exception e) {
String message =
SecretsUtil.buildExceptionMessageConnection(e.getMessage(), connectionType, true);
if (message != null) {
throw new InvalidServiceConnectionException(message);
}
throw InvalidServiceConnectionException.byMessage(
connectionType,
String.format("Failed to delete secrets from connection instance of %s", connectionType));
}
}
public void deleteSecretsFromWorkflow(Workflow workflow) {
Workflow workflowConverted =
(Workflow) ClassConverterFactory.getConverter(Workflow.class).convert(workflow);
// we don't store OM conn sensitive data
workflowConverted.setOpenMetadataServerConnection(null);
try {
deleteSecrets(workflowConverted, buildSecretId(true, "workflow", workflow.getName()));
} catch (Exception e) {
throw new SecretsManagerException(
Response.Status.BAD_REQUEST,
String.format(
"Failed to delete secrets from workflow instance [%s]", workflow.getName()));
}
}
private void deleteSecrets(Object toDeleteSecretsFrom, String secretId) {
if (!DO_NOT_ENCRYPT_CLASSES.contains(toDeleteSecretsFrom.getClass())) {
Arrays.stream(toDeleteSecretsFrom.getClass().getMethods())
.filter(ReflectionUtil::isGetMethodOfObject)
.forEach(
method -> {
Object obj = ReflectionUtil.getObjectFromMethod(method, toDeleteSecretsFrom);
String fieldName = method.getName().replaceFirst("get", "");
// check if it has annotation:
// We are replicating the logic that we use for storing the fields we need to
// encrypt at encryptPasswordFields
if (CommonUtil.isOpenMetadataObject(obj)) {
deleteSecrets(
obj, buildSecretId(false, secretId, fieldName.toLowerCase(Locale.ROOT)));
} else if (obj != null && method.getAnnotation(PasswordField.class) != null) {
deleteSecretInternal(
buildSecretId(false, secretId, fieldName.toLowerCase(Locale.ROOT)));
}
});
}
}
public static Map<String, String> getTags(SecretsConfig secretsConfig) {
Map<String, String> tags = new HashMap<>();
secretsConfig.tags.forEach(
keyValue -> {
try {
tags.put(keyValue.split(":")[0], keyValue.split(":")[1]);
} catch (Exception e) {
LOG.error(
"The SecretsConfig could not extract tag from [{}] due to [{}]",
keyValue,
e.getMessage());
}
});
return tags;
}
}