|
12 | 12 | */ |
13 | 13 | package org.openmetadata.service.secrets; |
14 | 14 |
|
| 15 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
15 | 16 | import static org.mockito.ArgumentMatchers.any; |
16 | 17 | import static org.mockito.Mockito.lenient; |
| 18 | +import static org.mockito.Mockito.never; |
17 | 19 | import static org.mockito.Mockito.reset; |
| 20 | +import static org.mockito.Mockito.verify; |
| 21 | +import static org.openmetadata.schema.api.services.CreateDatabaseService.DatabaseServiceType.Mysql; |
18 | 22 |
|
19 | 23 | import java.util.HashMap; |
20 | 24 | import java.util.List; |
21 | 25 | import java.util.Map; |
22 | 26 | import org.junit.jupiter.api.AfterAll; |
23 | 27 | import org.junit.jupiter.api.BeforeAll; |
| 28 | +import org.junit.jupiter.api.Test; |
24 | 29 | import org.mockito.Mock; |
| 30 | +import org.openmetadata.schema.entity.services.ServiceType; |
25 | 31 | import org.openmetadata.schema.security.secrets.SecretsManagerConfiguration; |
26 | 32 | import org.openmetadata.schema.security.secrets.SecretsManagerProvider; |
| 33 | +import org.openmetadata.schema.services.connections.database.MysqlConnection; |
| 34 | +import org.openmetadata.schema.services.connections.database.common.basicAuth; |
| 35 | +import org.openmetadata.schema.utils.JsonUtils; |
27 | 36 | import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient; |
28 | 37 | import software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest; |
29 | 38 | import software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse; |
30 | 39 | import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest; |
31 | 40 | import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse; |
| 41 | +import software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException; |
32 | 42 | import software.amazon.awssdk.services.secretsmanager.model.UpdateSecretRequest; |
33 | 43 | import software.amazon.awssdk.services.secretsmanager.model.UpdateSecretResponse; |
34 | 44 |
|
@@ -98,4 +108,62 @@ void setUpSpecific(SecretsManagerConfiguration config) { |
98 | 108 | protected SecretsManagerProvider expectedSecretManagerProvider() { |
99 | 109 | return SecretsManagerProvider.MANAGED_AWS; |
100 | 110 | } |
| 111 | + |
| 112 | + /** |
| 113 | + * Tests the Hybrid SaaS scenario where customers provide external secret references. |
| 114 | + * |
| 115 | + * <p>In Hybrid SaaS deployments: |
| 116 | + * |
| 117 | + * <ul> |
| 118 | + * <li>Customers provide secret references like "secret:/customer/path/to/secret" |
| 119 | + * <li>These references point to secrets in the CUSTOMER's AWS account, not Collate's |
| 120 | + * <li>The ingestion runs on the customer's cloud and resolves secrets there |
| 121 | + * <li>OpenMetadata server should NOT try to fetch these secrets during decrypt |
| 122 | + * </ul> |
| 123 | + * |
| 124 | + * <p>This test verifies that when a user provides a "secret:" prefixed value: |
| 125 | + * |
| 126 | + * <ol> |
| 127 | + * <li>Encryption: keeps the reference (Fernet-wrapped for DB storage), no new secret created |
| 128 | + * <li>Decryption: returns the reference as-is WITHOUT trying to fetch from SM |
| 129 | + * </ol> |
| 130 | + * |
| 131 | + * <p>REGRESSION: PR #25236 (Query Runner integration) changed decryptPasswordFields() to always |
| 132 | + * call getSecretValue() for "secret:" prefixed values, breaking this scenario. |
| 133 | + */ |
| 134 | + @Test |
| 135 | + void testHybridSaasExternalSecretReferenceShouldNotBeFetchedDuringDecrypt() { |
| 136 | + String externalSecretReference = "secret:/customer/aws/account/database/password"; |
| 137 | + |
| 138 | + Map<String, Map<String, String>> mysqlConnection = |
| 139 | + Map.of("authType", Map.of("password", externalSecretReference)); |
| 140 | + |
| 141 | + MysqlConnection encryptedConnection = |
| 142 | + (MysqlConnection) |
| 143 | + secretsManager.encryptServiceConnectionConfig( |
| 144 | + mysqlConnection, Mysql.value(), "hybrid-customer-service", ServiceType.DATABASE); |
| 145 | + |
| 146 | + verify(secretsManagerClient, never()).createSecret(any(CreateSecretRequest.class)); |
| 147 | + |
| 148 | + reset(secretsManagerClient); |
| 149 | + lenient() |
| 150 | + .when(secretsManagerClient.getSecretValue(any(GetSecretValueRequest.class))) |
| 151 | + .thenThrow( |
| 152 | + ResourceNotFoundException.builder() |
| 153 | + .message("Secrets Manager can't find the specified secret.") |
| 154 | + .build()); |
| 155 | + |
| 156 | + MysqlConnection decryptedConnection = |
| 157 | + (MysqlConnection) |
| 158 | + secretsManager.decryptServiceConnectionConfig( |
| 159 | + encryptedConnection, Mysql.value(), ServiceType.DATABASE); |
| 160 | + |
| 161 | + String decryptedPassword = |
| 162 | + JsonUtils.convertValue(decryptedConnection.getAuthType(), basicAuth.class).getPassword(); |
| 163 | + assertEquals( |
| 164 | + externalSecretReference, |
| 165 | + decryptedPassword, |
| 166 | + "External secret reference should be returned as-is during decryption, " |
| 167 | + + "not fetched from the server's secrets manager"); |
| 168 | + } |
101 | 169 | } |
0 commit comments