@depup/mongodb 7.1.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +201 -0
- package/README.md +33 -0
- package/etc/prepare.js +12 -0
- package/lib/admin.js +136 -0
- package/lib/admin.js.map +1 -0
- package/lib/bson.js +85 -0
- package/lib/bson.js.map +1 -0
- package/lib/bulk/common.js +835 -0
- package/lib/bulk/common.js.map +1 -0
- package/lib/bulk/ordered.js +67 -0
- package/lib/bulk/ordered.js.map +1 -0
- package/lib/bulk/unordered.js +92 -0
- package/lib/bulk/unordered.js.map +1 -0
- package/lib/change_stream.js +513 -0
- package/lib/change_stream.js.map +1 -0
- package/lib/client-side-encryption/auto_encrypter.js +272 -0
- package/lib/client-side-encryption/auto_encrypter.js.map +1 -0
- package/lib/client-side-encryption/client_encryption.js +609 -0
- package/lib/client-side-encryption/client_encryption.js.map +1 -0
- package/lib/client-side-encryption/errors.js +138 -0
- package/lib/client-side-encryption/errors.js.map +1 -0
- package/lib/client-side-encryption/mongocryptd_manager.js +85 -0
- package/lib/client-side-encryption/mongocryptd_manager.js.map +1 -0
- package/lib/client-side-encryption/providers/aws.js +23 -0
- package/lib/client-side-encryption/providers/aws.js.map +1 -0
- package/lib/client-side-encryption/providers/azure.js +132 -0
- package/lib/client-side-encryption/providers/azure.js.map +1 -0
- package/lib/client-side-encryption/providers/gcp.js +16 -0
- package/lib/client-side-encryption/providers/gcp.js.map +1 -0
- package/lib/client-side-encryption/providers/index.js +43 -0
- package/lib/client-side-encryption/providers/index.js.map +1 -0
- package/lib/client-side-encryption/state_machine.js +427 -0
- package/lib/client-side-encryption/state_machine.js.map +1 -0
- package/lib/cmap/auth/auth_provider.js +51 -0
- package/lib/cmap/auth/auth_provider.js.map +1 -0
- package/lib/cmap/auth/aws4.js +161 -0
- package/lib/cmap/auth/aws4.js.map +1 -0
- package/lib/cmap/auth/aws_temporary_credentials.js +103 -0
- package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
- package/lib/cmap/auth/gssapi.js +155 -0
- package/lib/cmap/auth/gssapi.js.map +1 -0
- package/lib/cmap/auth/mongo_credentials.js +169 -0
- package/lib/cmap/auth/mongo_credentials.js.map +1 -0
- package/lib/cmap/auth/mongodb_aws.js +128 -0
- package/lib/cmap/auth/mongodb_aws.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js +84 -0
- package/lib/cmap/auth/mongodb_oidc/automated_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js +62 -0
- package/lib/cmap/auth/mongodb_oidc/azure_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +141 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js +44 -0
- package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js +39 -0
- package/lib/cmap/auth/mongodb_oidc/gcp_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +122 -0
- package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js +32 -0
- package/lib/cmap/auth/mongodb_oidc/k8s_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_cache.js +52 -0
- package/lib/cmap/auth/mongodb_oidc/token_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js +23 -0
- package/lib/cmap/auth/mongodb_oidc/token_machine_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +73 -0
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -0
- package/lib/cmap/auth/plain.js +26 -0
- package/lib/cmap/auth/plain.js.map +1 -0
- package/lib/cmap/auth/providers.js +22 -0
- package/lib/cmap/auth/providers.js.map +1 -0
- package/lib/cmap/auth/scram.js +254 -0
- package/lib/cmap/auth/scram.js.map +1 -0
- package/lib/cmap/auth/x509.js +36 -0
- package/lib/cmap/auth/x509.js.map +1 -0
- package/lib/cmap/command_monitoring_events.js +223 -0
- package/lib/cmap/command_monitoring_events.js.map +1 -0
- package/lib/cmap/commands.js +535 -0
- package/lib/cmap/commands.js.map +1 -0
- package/lib/cmap/connect.js +381 -0
- package/lib/cmap/connect.js.map +1 -0
- package/lib/cmap/connection.js +571 -0
- package/lib/cmap/connection.js.map +1 -0
- package/lib/cmap/connection_pool.js +558 -0
- package/lib/cmap/connection_pool.js.map +1 -0
- package/lib/cmap/connection_pool_events.js +190 -0
- package/lib/cmap/connection_pool_events.js.map +1 -0
- package/lib/cmap/errors.js +108 -0
- package/lib/cmap/errors.js.map +1 -0
- package/lib/cmap/handshake/client_metadata.js +242 -0
- package/lib/cmap/handshake/client_metadata.js.map +1 -0
- package/lib/cmap/metrics.js +62 -0
- package/lib/cmap/metrics.js.map +1 -0
- package/lib/cmap/stream_description.js +70 -0
- package/lib/cmap/stream_description.js.map +1 -0
- package/lib/cmap/wire_protocol/compression.js +178 -0
- package/lib/cmap/wire_protocol/compression.js.map +1 -0
- package/lib/cmap/wire_protocol/constants.js +21 -0
- package/lib/cmap/wire_protocol/constants.js.map +1 -0
- package/lib/cmap/wire_protocol/on_data.js +111 -0
- package/lib/cmap/wire_protocol/on_data.js.map +1 -0
- package/lib/cmap/wire_protocol/on_demand/document.js +222 -0
- package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
- package/lib/cmap/wire_protocol/responses.js +315 -0
- package/lib/cmap/wire_protocol/responses.js.map +1 -0
- package/lib/cmap/wire_protocol/shared.js +35 -0
- package/lib/cmap/wire_protocol/shared.js.map +1 -0
- package/lib/collection.js +751 -0
- package/lib/collection.js.map +1 -0
- package/lib/connection_string.js +1090 -0
- package/lib/connection_string.js.map +1 -0
- package/lib/constants.js +170 -0
- package/lib/constants.js.map +1 -0
- package/lib/cursor/abstract_cursor.js +924 -0
- package/lib/cursor/abstract_cursor.js.map +1 -0
- package/lib/cursor/aggregation_cursor.js +164 -0
- package/lib/cursor/aggregation_cursor.js.map +1 -0
- package/lib/cursor/change_stream_cursor.js +104 -0
- package/lib/cursor/change_stream_cursor.js.map +1 -0
- package/lib/cursor/client_bulk_write_cursor.js +52 -0
- package/lib/cursor/client_bulk_write_cursor.js.map +1 -0
- package/lib/cursor/explainable_cursor.js +36 -0
- package/lib/cursor/explainable_cursor.js.map +1 -0
- package/lib/cursor/find_cursor.js +399 -0
- package/lib/cursor/find_cursor.js.map +1 -0
- package/lib/cursor/list_collections_cursor.js +34 -0
- package/lib/cursor/list_collections_cursor.js.map +1 -0
- package/lib/cursor/list_indexes_cursor.js +32 -0
- package/lib/cursor/list_indexes_cursor.js.map +1 -0
- package/lib/cursor/list_search_indexes_cursor.js +14 -0
- package/lib/cursor/list_search_indexes_cursor.js.map +1 -0
- package/lib/cursor/run_command_cursor.js +94 -0
- package/lib/cursor/run_command_cursor.js.map +1 -0
- package/lib/db.js +419 -0
- package/lib/db.js.map +1 -0
- package/lib/deps.js +112 -0
- package/lib/deps.js.map +1 -0
- package/lib/encrypter.js +106 -0
- package/lib/encrypter.js.map +1 -0
- package/lib/error.js +1380 -0
- package/lib/error.js.map +1 -0
- package/lib/explain.js +59 -0
- package/lib/explain.js.map +1 -0
- package/lib/gridfs/download.js +305 -0
- package/lib/gridfs/download.js.map +1 -0
- package/lib/gridfs/index.js +164 -0
- package/lib/gridfs/index.js.map +1 -0
- package/lib/gridfs/upload.js +358 -0
- package/lib/gridfs/upload.js.map +1 -0
- package/lib/index.js +193 -0
- package/lib/index.js.map +1 -0
- package/lib/mongo_client.js +557 -0
- package/lib/mongo_client.js.map +1 -0
- package/lib/mongo_client_auth_providers.js +80 -0
- package/lib/mongo_client_auth_providers.js.map +1 -0
- package/lib/mongo_logger.js +655 -0
- package/lib/mongo_logger.js.map +1 -0
- package/lib/mongo_types.js +56 -0
- package/lib/mongo_types.js.map +1 -0
- package/lib/operations/aggregate.js +90 -0
- package/lib/operations/aggregate.js.map +1 -0
- package/lib/operations/client_bulk_write/client_bulk_write.js +51 -0
- package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -0
- package/lib/operations/client_bulk_write/command_builder.js +340 -0
- package/lib/operations/client_bulk_write/command_builder.js.map +1 -0
- package/lib/operations/client_bulk_write/common.js +3 -0
- package/lib/operations/client_bulk_write/common.js.map +1 -0
- package/lib/operations/client_bulk_write/executor.js +120 -0
- package/lib/operations/client_bulk_write/executor.js.map +1 -0
- package/lib/operations/client_bulk_write/results_merger.js +204 -0
- package/lib/operations/client_bulk_write/results_merger.js.map +1 -0
- package/lib/operations/command.js +83 -0
- package/lib/operations/command.js.map +1 -0
- package/lib/operations/count.js +45 -0
- package/lib/operations/count.js.map +1 -0
- package/lib/operations/create_collection.js +109 -0
- package/lib/operations/create_collection.js.map +1 -0
- package/lib/operations/delete.js +125 -0
- package/lib/operations/delete.js.map +1 -0
- package/lib/operations/distinct.js +61 -0
- package/lib/operations/distinct.js.map +1 -0
- package/lib/operations/drop.js +93 -0
- package/lib/operations/drop.js.map +1 -0
- package/lib/operations/end_sessions.js +34 -0
- package/lib/operations/end_sessions.js.map +1 -0
- package/lib/operations/estimated_document_count.js +41 -0
- package/lib/operations/estimated_document_count.js.map +1 -0
- package/lib/operations/execute_operation.js +239 -0
- package/lib/operations/execute_operation.js.map +1 -0
- package/lib/operations/find.js +148 -0
- package/lib/operations/find.js.map +1 -0
- package/lib/operations/find_and_modify.js +158 -0
- package/lib/operations/find_and_modify.js.map +1 -0
- package/lib/operations/get_more.js +62 -0
- package/lib/operations/get_more.js.map +1 -0
- package/lib/operations/indexes.js +186 -0
- package/lib/operations/indexes.js.map +1 -0
- package/lib/operations/insert.js +70 -0
- package/lib/operations/insert.js.map +1 -0
- package/lib/operations/kill_cursors.js +43 -0
- package/lib/operations/kill_cursors.js.map +1 -0
- package/lib/operations/list_collections.js +53 -0
- package/lib/operations/list_collections.js.map +1 -0
- package/lib/operations/list_databases.js +40 -0
- package/lib/operations/list_databases.js.map +1 -0
- package/lib/operations/operation.js +102 -0
- package/lib/operations/operation.js.map +1 -0
- package/lib/operations/profiling_level.js +43 -0
- package/lib/operations/profiling_level.js.map +1 -0
- package/lib/operations/remove_user.js +27 -0
- package/lib/operations/remove_user.js.map +1 -0
- package/lib/operations/rename.js +38 -0
- package/lib/operations/rename.js.map +1 -0
- package/lib/operations/run_command.js +47 -0
- package/lib/operations/run_command.js.map +1 -0
- package/lib/operations/search_indexes/create.js +33 -0
- package/lib/operations/search_indexes/create.js.map +1 -0
- package/lib/operations/search_indexes/drop.js +43 -0
- package/lib/operations/search_indexes/drop.js.map +1 -0
- package/lib/operations/search_indexes/update.js +35 -0
- package/lib/operations/search_indexes/update.js.map +1 -0
- package/lib/operations/set_profiling_level.js +53 -0
- package/lib/operations/set_profiling_level.js.map +1 -0
- package/lib/operations/stats.js +27 -0
- package/lib/operations/stats.js.map +1 -0
- package/lib/operations/update.js +188 -0
- package/lib/operations/update.js.map +1 -0
- package/lib/operations/validate_collection.js +37 -0
- package/lib/operations/validate_collection.js.map +1 -0
- package/lib/read_concern.js +73 -0
- package/lib/read_concern.js.map +1 -0
- package/lib/read_preference.js +191 -0
- package/lib/read_preference.js.map +1 -0
- package/lib/sdam/common.js +49 -0
- package/lib/sdam/common.js.map +1 -0
- package/lib/sdam/events.js +146 -0
- package/lib/sdam/events.js.map +1 -0
- package/lib/sdam/monitor.js +544 -0
- package/lib/sdam/monitor.js.map +1 -0
- package/lib/sdam/server.js +404 -0
- package/lib/sdam/server.js.map +1 -0
- package/lib/sdam/server_description.js +204 -0
- package/lib/sdam/server_description.js.map +1 -0
- package/lib/sdam/server_selection.js +294 -0
- package/lib/sdam/server_selection.js.map +1 -0
- package/lib/sdam/server_selection_events.js +85 -0
- package/lib/sdam/server_selection_events.js.map +1 -0
- package/lib/sdam/srv_polling.js +108 -0
- package/lib/sdam/srv_polling.js.map +1 -0
- package/lib/sdam/topology.js +652 -0
- package/lib/sdam/topology.js.map +1 -0
- package/lib/sdam/topology_description.js +383 -0
- package/lib/sdam/topology_description.js.map +1 -0
- package/lib/sessions.js +892 -0
- package/lib/sessions.js.map +1 -0
- package/lib/sort.js +103 -0
- package/lib/sort.js.map +1 -0
- package/lib/timeout.js +296 -0
- package/lib/timeout.js.map +1 -0
- package/lib/transactions.js +135 -0
- package/lib/transactions.js.map +1 -0
- package/lib/utils.js +1163 -0
- package/lib/utils.js.map +1 -0
- package/lib/write_concern.js +100 -0
- package/lib/write_concern.js.map +1 -0
- package/mongodb.d.ts +9018 -0
- package/package.json +197 -0
- package/src/admin.ts +173 -0
- package/src/bson.ts +149 -0
- package/src/bulk/common.ts +1251 -0
- package/src/bulk/ordered.ts +83 -0
- package/src/bulk/unordered.ts +115 -0
- package/src/change_stream.ts +1160 -0
- package/src/client-side-encryption/auto_encrypter.ts +469 -0
- package/src/client-side-encryption/client_encryption.ts +1150 -0
- package/src/client-side-encryption/errors.ts +144 -0
- package/src/client-side-encryption/mongocryptd_manager.ts +100 -0
- package/src/client-side-encryption/providers/aws.ts +33 -0
- package/src/client-side-encryption/providers/azure.ts +181 -0
- package/src/client-side-encryption/providers/gcp.ts +16 -0
- package/src/client-side-encryption/providers/index.ts +207 -0
- package/src/client-side-encryption/state_machine.ts +651 -0
- package/src/cmap/auth/auth_provider.ts +77 -0
- package/src/cmap/auth/aws4.ts +207 -0
- package/src/cmap/auth/aws_temporary_credentials.ts +129 -0
- package/src/cmap/auth/gssapi.ts +203 -0
- package/src/cmap/auth/mongo_credentials.ts +292 -0
- package/src/cmap/auth/mongodb_aws.ts +179 -0
- package/src/cmap/auth/mongodb_oidc/automated_callback_workflow.ts +88 -0
- package/src/cmap/auth/mongodb_oidc/azure_machine_workflow.ts +73 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +188 -0
- package/src/cmap/auth/mongodb_oidc/command_builders.ts +53 -0
- package/src/cmap/auth/mongodb_oidc/gcp_machine_workflow.ts +46 -0
- package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +141 -0
- package/src/cmap/auth/mongodb_oidc/k8s_machine_workflow.ts +31 -0
- package/src/cmap/auth/mongodb_oidc/token_cache.ts +62 -0
- package/src/cmap/auth/mongodb_oidc/token_machine_workflow.ts +22 -0
- package/src/cmap/auth/mongodb_oidc.ts +185 -0
- package/src/cmap/auth/plain.ts +25 -0
- package/src/cmap/auth/providers.ts +22 -0
- package/src/cmap/auth/scram.ts +344 -0
- package/src/cmap/auth/x509.ts +43 -0
- package/src/cmap/command_monitoring_events.ts +316 -0
- package/src/cmap/commands.ts +788 -0
- package/src/cmap/connect.ts +518 -0
- package/src/cmap/connection.ts +931 -0
- package/src/cmap/connection_pool.ts +831 -0
- package/src/cmap/connection_pool_events.ts +300 -0
- package/src/cmap/errors.ts +119 -0
- package/src/cmap/handshake/client_metadata.ts +353 -0
- package/src/cmap/metrics.ts +58 -0
- package/src/cmap/stream_description.ts +96 -0
- package/src/cmap/wire_protocol/compression.ts +211 -0
- package/src/cmap/wire_protocol/constants.ts +17 -0
- package/src/cmap/wire_protocol/on_data.ts +139 -0
- package/src/cmap/wire_protocol/on_demand/document.ts +358 -0
- package/src/cmap/wire_protocol/responses.ts +393 -0
- package/src/cmap/wire_protocol/shared.ts +48 -0
- package/src/collection.ts +1314 -0
- package/src/connection_string.ts +1297 -0
- package/src/constants.ts +176 -0
- package/src/cursor/abstract_cursor.ts +1247 -0
- package/src/cursor/aggregation_cursor.ts +245 -0
- package/src/cursor/change_stream_cursor.ts +171 -0
- package/src/cursor/client_bulk_write_cursor.ts +83 -0
- package/src/cursor/explainable_cursor.ts +51 -0
- package/src/cursor/find_cursor.ts +497 -0
- package/src/cursor/list_collections_cursor.ts +50 -0
- package/src/cursor/list_indexes_cursor.ts +37 -0
- package/src/cursor/list_search_indexes_cursor.ts +20 -0
- package/src/cursor/run_command_cursor.ts +178 -0
- package/src/db.ts +621 -0
- package/src/deps.ts +227 -0
- package/src/encrypter.ts +127 -0
- package/src/error.ts +1567 -0
- package/src/explain.ts +124 -0
- package/src/gridfs/download.ts +483 -0
- package/src/gridfs/index.ts +264 -0
- package/src/gridfs/upload.ts +537 -0
- package/src/index.ts +633 -0
- package/src/mongo_client.ts +1155 -0
- package/src/mongo_client_auth_providers.ts +87 -0
- package/src/mongo_logger.ts +1081 -0
- package/src/mongo_types.ts +678 -0
- package/src/operations/aggregate.ts +153 -0
- package/src/operations/client_bulk_write/client_bulk_write.ts +72 -0
- package/src/operations/client_bulk_write/command_builder.ts +487 -0
- package/src/operations/client_bulk_write/common.ts +276 -0
- package/src/operations/client_bulk_write/executor.ts +149 -0
- package/src/operations/client_bulk_write/results_merger.ts +260 -0
- package/src/operations/command.ts +171 -0
- package/src/operations/count.ts +74 -0
- package/src/operations/create_collection.ts +218 -0
- package/src/operations/delete.ts +183 -0
- package/src/operations/distinct.ts +92 -0
- package/src/operations/drop.ts +130 -0
- package/src/operations/end_sessions.ts +44 -0
- package/src/operations/estimated_document_count.ts +61 -0
- package/src/operations/execute_operation.ts +319 -0
- package/src/operations/find.ts +254 -0
- package/src/operations/find_and_modify.ts +319 -0
- package/src/operations/get_more.ts +108 -0
- package/src/operations/indexes.ts +418 -0
- package/src/operations/insert.ts +108 -0
- package/src/operations/kill_cursors.ts +64 -0
- package/src/operations/list_collections.ts +108 -0
- package/src/operations/list_databases.ts +68 -0
- package/src/operations/operation.ts +181 -0
- package/src/operations/profiling_level.ts +46 -0
- package/src/operations/remove_user.ts +36 -0
- package/src/operations/rename.ts +60 -0
- package/src/operations/run_command.ts +79 -0
- package/src/operations/search_indexes/create.ts +56 -0
- package/src/operations/search_indexes/drop.ts +58 -0
- package/src/operations/search_indexes/update.ts +45 -0
- package/src/operations/set_profiling_level.ts +74 -0
- package/src/operations/stats.ts +37 -0
- package/src/operations/update.ts +318 -0
- package/src/operations/validate_collection.ts +50 -0
- package/src/read_concern.ts +88 -0
- package/src/read_preference.ts +256 -0
- package/src/sdam/common.ts +74 -0
- package/src/sdam/events.ts +219 -0
- package/src/sdam/monitor.ts +771 -0
- package/src/sdam/server.ts +595 -0
- package/src/sdam/server_description.ts +297 -0
- package/src/sdam/server_selection.ts +415 -0
- package/src/sdam/server_selection_events.ts +142 -0
- package/src/sdam/srv_polling.ts +146 -0
- package/src/sdam/topology.ts +1100 -0
- package/src/sdam/topology_description.ts +548 -0
- package/src/sessions.ts +1244 -0
- package/src/sort.ts +141 -0
- package/src/timeout.ts +405 -0
- package/src/transactions.ts +181 -0
- package/src/utils.ts +1434 -0
- package/src/write_concern.ts +183 -0
- package/tsconfig.json +46 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { type Document } from '../bson';
|
|
2
|
+
import { MongoError } from '../error';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
* An error indicating that something went wrong specifically with MongoDB Client Encryption
|
|
7
|
+
*/
|
|
8
|
+
export class MongoCryptError extends MongoError {
|
|
9
|
+
/**
|
|
10
|
+
* **Do not use this constructor!**
|
|
11
|
+
*
|
|
12
|
+
* Meant for internal use only.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* This class is only meant to be constructed within the driver. This constructor is
|
|
16
|
+
* not subject to semantic versioning compatibility guarantees and may change at any time.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
**/
|
|
20
|
+
constructor(message: string, options: { cause?: Error } = {}) {
|
|
21
|
+
super(message, options);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
override get name() {
|
|
25
|
+
return 'MongoCryptError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const defaultErrorWrapper = (error: Error) =>
|
|
30
|
+
new MongoCryptError(error.message, { cause: error });
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @public
|
|
34
|
+
*
|
|
35
|
+
* An error indicating an invalid argument was provided to an encryption API.
|
|
36
|
+
*/
|
|
37
|
+
export class MongoCryptInvalidArgumentError extends MongoCryptError {
|
|
38
|
+
/**
|
|
39
|
+
* **Do not use this constructor!**
|
|
40
|
+
*
|
|
41
|
+
* Meant for internal use only.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* This class is only meant to be constructed within the driver. This constructor is
|
|
45
|
+
* not subject to semantic versioning compatibility guarantees and may change at any time.
|
|
46
|
+
*
|
|
47
|
+
* @public
|
|
48
|
+
**/
|
|
49
|
+
constructor(message: string) {
|
|
50
|
+
super(message);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override get name() {
|
|
54
|
+
return 'MongoCryptInvalidArgumentError';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @public
|
|
59
|
+
* An error indicating that `ClientEncryption.createEncryptedCollection()` failed to create data keys
|
|
60
|
+
*/
|
|
61
|
+
export class MongoCryptCreateDataKeyError extends MongoCryptError {
|
|
62
|
+
encryptedFields: Document;
|
|
63
|
+
/**
|
|
64
|
+
* **Do not use this constructor!**
|
|
65
|
+
*
|
|
66
|
+
* Meant for internal use only.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* This class is only meant to be constructed within the driver. This constructor is
|
|
70
|
+
* not subject to semantic versioning compatibility guarantees and may change at any time.
|
|
71
|
+
*
|
|
72
|
+
* @public
|
|
73
|
+
**/
|
|
74
|
+
constructor(encryptedFields: Document, { cause }: { cause: Error }) {
|
|
75
|
+
super(`Unable to complete creating data keys: ${cause.message}`, { cause });
|
|
76
|
+
this.encryptedFields = encryptedFields;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
override get name() {
|
|
80
|
+
return 'MongoCryptCreateDataKeyError';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @public
|
|
86
|
+
* An error indicating that `ClientEncryption.createEncryptedCollection()` failed to create a collection
|
|
87
|
+
*/
|
|
88
|
+
export class MongoCryptCreateEncryptedCollectionError extends MongoCryptError {
|
|
89
|
+
encryptedFields: Document;
|
|
90
|
+
/**
|
|
91
|
+
* **Do not use this constructor!**
|
|
92
|
+
*
|
|
93
|
+
* Meant for internal use only.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* This class is only meant to be constructed within the driver. This constructor is
|
|
97
|
+
* not subject to semantic versioning compatibility guarantees and may change at any time.
|
|
98
|
+
*
|
|
99
|
+
* @public
|
|
100
|
+
**/
|
|
101
|
+
constructor(encryptedFields: Document, { cause }: { cause: Error }) {
|
|
102
|
+
super(`Unable to create collection: ${cause.message}`, { cause });
|
|
103
|
+
this.encryptedFields = encryptedFields;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
override get name() {
|
|
107
|
+
return 'MongoCryptCreateEncryptedCollectionError';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @public
|
|
113
|
+
* An error indicating that mongodb-client-encryption failed to auto-refresh Azure KMS credentials.
|
|
114
|
+
*/
|
|
115
|
+
export class MongoCryptAzureKMSRequestError extends MongoCryptError {
|
|
116
|
+
/** The body of the http response that failed, if present. */
|
|
117
|
+
body?: Document;
|
|
118
|
+
/**
|
|
119
|
+
* **Do not use this constructor!**
|
|
120
|
+
*
|
|
121
|
+
* Meant for internal use only.
|
|
122
|
+
*
|
|
123
|
+
* @remarks
|
|
124
|
+
* This class is only meant to be constructed within the driver. This constructor is
|
|
125
|
+
* not subject to semantic versioning compatibility guarantees and may change at any time.
|
|
126
|
+
*
|
|
127
|
+
* @public
|
|
128
|
+
**/
|
|
129
|
+
constructor(message: string, body?: Document) {
|
|
130
|
+
super(message);
|
|
131
|
+
this.body = body;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
override get name(): string {
|
|
135
|
+
return 'MongoCryptAzureKMSRequestError';
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** @public */
|
|
140
|
+
export class MongoCryptKMSRequestNetworkTimeoutError extends MongoCryptError {
|
|
141
|
+
override get name(): string {
|
|
142
|
+
return 'MongoCryptKMSRequestNetworkTimeoutError';
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ChildProcess } from 'child_process';
|
|
2
|
+
|
|
3
|
+
import { MongoNetworkTimeoutError } from '../error';
|
|
4
|
+
import { type AutoEncryptionExtraOptions } from './auto_encrypter';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
* An internal class that handles spawning a mongocryptd.
|
|
9
|
+
*/
|
|
10
|
+
export class MongocryptdManager {
|
|
11
|
+
static DEFAULT_MONGOCRYPTD_URI = 'mongodb://localhost:27020';
|
|
12
|
+
|
|
13
|
+
uri: string;
|
|
14
|
+
bypassSpawn: boolean;
|
|
15
|
+
spawnPath = '';
|
|
16
|
+
spawnArgs: Array<string> = [];
|
|
17
|
+
_child?: ChildProcess;
|
|
18
|
+
|
|
19
|
+
constructor(extraOptions: AutoEncryptionExtraOptions = {}) {
|
|
20
|
+
this.uri =
|
|
21
|
+
typeof extraOptions.mongocryptdURI === 'string' && extraOptions.mongocryptdURI.length > 0
|
|
22
|
+
? extraOptions.mongocryptdURI
|
|
23
|
+
: MongocryptdManager.DEFAULT_MONGOCRYPTD_URI;
|
|
24
|
+
|
|
25
|
+
this.bypassSpawn = !!extraOptions.mongocryptdBypassSpawn;
|
|
26
|
+
|
|
27
|
+
if (Object.hasOwn(extraOptions, 'mongocryptdSpawnPath') && extraOptions.mongocryptdSpawnPath) {
|
|
28
|
+
this.spawnPath = extraOptions.mongocryptdSpawnPath;
|
|
29
|
+
}
|
|
30
|
+
if (
|
|
31
|
+
Object.hasOwn(extraOptions, 'mongocryptdSpawnArgs') &&
|
|
32
|
+
Array.isArray(extraOptions.mongocryptdSpawnArgs)
|
|
33
|
+
) {
|
|
34
|
+
this.spawnArgs = this.spawnArgs.concat(extraOptions.mongocryptdSpawnArgs);
|
|
35
|
+
}
|
|
36
|
+
if (
|
|
37
|
+
this.spawnArgs
|
|
38
|
+
.filter(arg => typeof arg === 'string')
|
|
39
|
+
.every(arg => arg.indexOf('--idleShutdownTimeoutSecs') < 0)
|
|
40
|
+
) {
|
|
41
|
+
this.spawnArgs.push('--idleShutdownTimeoutSecs', '60');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Will check to see if a mongocryptd is up. If it is not up, it will attempt
|
|
47
|
+
* to spawn a mongocryptd in a detached process, and then wait for it to be up.
|
|
48
|
+
*/
|
|
49
|
+
async spawn(): Promise<void> {
|
|
50
|
+
const cmdName = this.spawnPath || 'mongocryptd';
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
53
|
+
const { spawn } = require('child_process') as typeof import('child_process');
|
|
54
|
+
|
|
55
|
+
// Spawned with stdio: ignore and detached: true
|
|
56
|
+
// to ensure child can outlive parent.
|
|
57
|
+
this._child = spawn(cmdName, this.spawnArgs, {
|
|
58
|
+
stdio: 'ignore',
|
|
59
|
+
detached: true
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
this._child.on('error', () => {
|
|
63
|
+
// From the FLE spec:
|
|
64
|
+
// "The stdout and stderr of the spawned process MUST not be exposed in the driver
|
|
65
|
+
// (e.g. redirect to /dev/null). Users can pass the argument --logpath to
|
|
66
|
+
// extraOptions.mongocryptdSpawnArgs if they need to inspect mongocryptd logs.
|
|
67
|
+
// If spawning is necessary, the driver MUST spawn mongocryptd whenever server
|
|
68
|
+
// selection on the MongoClient to mongocryptd fails. If the MongoClient fails to
|
|
69
|
+
// connect after spawning, the server selection error is propagated to the user."
|
|
70
|
+
// The AutoEncrypter and MongoCryptdManager should work together to spawn
|
|
71
|
+
// mongocryptd whenever necessary. Additionally, the `mongocryptd` intentionally
|
|
72
|
+
// shuts down after 60s and gets respawned when necessary. We rely on server
|
|
73
|
+
// selection timeouts when connecting to the `mongocryptd` to inform users that something
|
|
74
|
+
// has been configured incorrectly. For those reasons, we suppress stderr from
|
|
75
|
+
// the `mongocryptd` process and immediately unref the process.
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// unref child to remove handle from event loop
|
|
79
|
+
this._child.unref();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @returns the result of `fn` or rejects with an error.
|
|
84
|
+
*/
|
|
85
|
+
async withRespawn<T>(fn: () => Promise<T>): ReturnType<typeof fn> {
|
|
86
|
+
try {
|
|
87
|
+
const result = await fn();
|
|
88
|
+
return result;
|
|
89
|
+
} catch (err) {
|
|
90
|
+
// If we are not bypassing spawning, then we should retry once on a MongoTimeoutError (server selection error)
|
|
91
|
+
const shouldSpawn = err instanceof MongoNetworkTimeoutError && !this.bypassSpawn;
|
|
92
|
+
if (!shouldSpawn) {
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
await this.spawn();
|
|
97
|
+
const result = await fn();
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AWSCredentialProvider,
|
|
3
|
+
AWSSDKCredentialProvider
|
|
4
|
+
} from '../../cmap/auth/aws_temporary_credentials';
|
|
5
|
+
import { type KMSProviders } from '.';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export async function loadAWSCredentials(
|
|
11
|
+
kmsProviders: KMSProviders,
|
|
12
|
+
provider?: AWSCredentialProvider
|
|
13
|
+
): Promise<KMSProviders> {
|
|
14
|
+
const credentialProvider = new AWSSDKCredentialProvider(provider);
|
|
15
|
+
|
|
16
|
+
// We shouldn't ever receive a response from the AWS SDK that doesn't have a `SecretAccessKey`
|
|
17
|
+
// or `AccessKeyId`. However, TS says these fields are optional. We provide empty strings
|
|
18
|
+
// and let libmongocrypt error if we're unable to fetch the required keys.
|
|
19
|
+
const {
|
|
20
|
+
SecretAccessKey = '',
|
|
21
|
+
AccessKeyId = '',
|
|
22
|
+
Token
|
|
23
|
+
} = await credentialProvider.getCredentials();
|
|
24
|
+
const aws: NonNullable<KMSProviders['aws']> = {
|
|
25
|
+
secretAccessKey: SecretAccessKey,
|
|
26
|
+
accessKeyId: AccessKeyId
|
|
27
|
+
};
|
|
28
|
+
// the AWS session token is only required for temporary credentials so only attach it to the
|
|
29
|
+
// result if it's present in the response from the aws sdk
|
|
30
|
+
Token != null && (aws.sessionToken = Token);
|
|
31
|
+
|
|
32
|
+
return { ...kmsProviders, aws };
|
|
33
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { type Document } from '../../bson';
|
|
2
|
+
import { MongoNetworkTimeoutError } from '../../error';
|
|
3
|
+
import { get } from '../../utils';
|
|
4
|
+
import { MongoCryptAzureKMSRequestError } from '../errors';
|
|
5
|
+
import { type KMSProviders } from './index';
|
|
6
|
+
|
|
7
|
+
const MINIMUM_TOKEN_REFRESH_IN_MILLISECONDS = 6000;
|
|
8
|
+
/** Base URL for getting Azure tokens. */
|
|
9
|
+
export const AZURE_BASE_URL = 'http://169.254.169.254/metadata/identity/oauth2/token?';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The access token that libmongocrypt expects for Azure kms.
|
|
13
|
+
*/
|
|
14
|
+
interface AccessToken {
|
|
15
|
+
accessToken: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The response from the azure idms endpoint, including the `expiresOnTimestamp`.
|
|
20
|
+
* `expiresOnTimestamp` is needed for caching.
|
|
21
|
+
*/
|
|
22
|
+
interface AzureTokenCacheEntry extends AccessToken {
|
|
23
|
+
accessToken: string;
|
|
24
|
+
expiresOnTimestamp: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export class AzureCredentialCache {
|
|
31
|
+
cachedToken: AzureTokenCacheEntry | null = null;
|
|
32
|
+
|
|
33
|
+
async getToken(): Promise<AccessToken> {
|
|
34
|
+
if (this.cachedToken == null || this.needsRefresh(this.cachedToken)) {
|
|
35
|
+
this.cachedToken = await this._getToken();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { accessToken: this.cachedToken.accessToken };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
needsRefresh(token: AzureTokenCacheEntry): boolean {
|
|
42
|
+
const timeUntilExpirationMS = token.expiresOnTimestamp - Date.now();
|
|
43
|
+
return timeUntilExpirationMS <= MINIMUM_TOKEN_REFRESH_IN_MILLISECONDS;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* exposed for testing
|
|
48
|
+
*/
|
|
49
|
+
resetCache() {
|
|
50
|
+
this.cachedToken = null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* exposed for testing
|
|
55
|
+
*/
|
|
56
|
+
_getToken(): Promise<AzureTokenCacheEntry> {
|
|
57
|
+
return fetchAzureKMSToken();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @internal */
|
|
62
|
+
export const tokenCache = new AzureCredentialCache();
|
|
63
|
+
|
|
64
|
+
/** @internal */
|
|
65
|
+
async function parseResponse(response: {
|
|
66
|
+
body: string;
|
|
67
|
+
status?: number;
|
|
68
|
+
}): Promise<AzureTokenCacheEntry> {
|
|
69
|
+
const { status, body: rawBody } = response;
|
|
70
|
+
|
|
71
|
+
const body: { expires_in?: number; access_token?: string } = (() => {
|
|
72
|
+
try {
|
|
73
|
+
return JSON.parse(rawBody);
|
|
74
|
+
} catch {
|
|
75
|
+
throw new MongoCryptAzureKMSRequestError('Malformed JSON body in GET request.');
|
|
76
|
+
}
|
|
77
|
+
})();
|
|
78
|
+
|
|
79
|
+
if (status !== 200) {
|
|
80
|
+
throw new MongoCryptAzureKMSRequestError('Unable to complete request.', body);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!body.access_token) {
|
|
84
|
+
throw new MongoCryptAzureKMSRequestError(
|
|
85
|
+
'Malformed response body - missing field `access_token`.'
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!body.expires_in) {
|
|
90
|
+
throw new MongoCryptAzureKMSRequestError(
|
|
91
|
+
'Malformed response body - missing field `expires_in`.'
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const expiresInMS = Number(body.expires_in) * 1000;
|
|
96
|
+
if (Number.isNaN(expiresInMS)) {
|
|
97
|
+
throw new MongoCryptAzureKMSRequestError(
|
|
98
|
+
'Malformed response body - unable to parse int from `expires_in` field.'
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
accessToken: body.access_token,
|
|
104
|
+
expiresOnTimestamp: Date.now() + expiresInMS
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @internal
|
|
110
|
+
*
|
|
111
|
+
* exposed for CSFLE
|
|
112
|
+
* [prose test 18](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#azure-imds-credentials)
|
|
113
|
+
*/
|
|
114
|
+
export interface AzureKMSRequestOptions {
|
|
115
|
+
headers?: Document;
|
|
116
|
+
url?: URL | string;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @internal
|
|
121
|
+
* Get the Azure endpoint URL.
|
|
122
|
+
*/
|
|
123
|
+
export function addAzureParams(url: URL, resource: string, username?: string): URL {
|
|
124
|
+
url.searchParams.append('api-version', '2018-02-01');
|
|
125
|
+
url.searchParams.append('resource', resource);
|
|
126
|
+
if (username) {
|
|
127
|
+
url.searchParams.append('client_id', username);
|
|
128
|
+
}
|
|
129
|
+
return url;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @internal
|
|
134
|
+
*
|
|
135
|
+
* parses any options provided by prose tests to `fetchAzureKMSToken` and merges them with
|
|
136
|
+
* the default values for headers and the request url.
|
|
137
|
+
*/
|
|
138
|
+
export function prepareRequest(options: AzureKMSRequestOptions): {
|
|
139
|
+
headers: Document;
|
|
140
|
+
url: URL;
|
|
141
|
+
} {
|
|
142
|
+
const url = new URL(options.url?.toString() ?? AZURE_BASE_URL);
|
|
143
|
+
addAzureParams(url, 'https://vault.azure.net');
|
|
144
|
+
const headers = { ...options.headers, 'Content-Type': 'application/json', Metadata: true };
|
|
145
|
+
return { headers, url };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @internal
|
|
150
|
+
*
|
|
151
|
+
* `AzureKMSRequestOptions` allows prose tests to modify the http request sent to the idms
|
|
152
|
+
* servers. This is required to simulate different server conditions. No options are expected to
|
|
153
|
+
* be set outside of tests.
|
|
154
|
+
*
|
|
155
|
+
* exposed for CSFLE
|
|
156
|
+
* [prose test 18](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#azure-imds-credentials)
|
|
157
|
+
*/
|
|
158
|
+
export async function fetchAzureKMSToken(
|
|
159
|
+
options: AzureKMSRequestOptions = {}
|
|
160
|
+
): Promise<AzureTokenCacheEntry> {
|
|
161
|
+
const { headers, url } = prepareRequest(options);
|
|
162
|
+
try {
|
|
163
|
+
const response = await get(url, { headers });
|
|
164
|
+
return await parseResponse(response);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error instanceof MongoNetworkTimeoutError) {
|
|
167
|
+
throw new MongoCryptAzureKMSRequestError(`[Azure KMS] ${error.message}`);
|
|
168
|
+
}
|
|
169
|
+
throw error;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @internal
|
|
175
|
+
*
|
|
176
|
+
* @throws Will reject with a `MongoCryptError` if the http request fails or the http response is malformed.
|
|
177
|
+
*/
|
|
178
|
+
export async function loadAzureCredentials(kmsProviders: KMSProviders): Promise<KMSProviders> {
|
|
179
|
+
const azure = await tokenCache.getToken();
|
|
180
|
+
return { ...kmsProviders, azure };
|
|
181
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getGcpMetadata } from '../../deps';
|
|
2
|
+
import { type KMSProviders } from '.';
|
|
3
|
+
|
|
4
|
+
/** @internal */
|
|
5
|
+
export async function loadGCPCredentials(kmsProviders: KMSProviders): Promise<KMSProviders> {
|
|
6
|
+
const gcpMetadata = getGcpMetadata();
|
|
7
|
+
|
|
8
|
+
if ('kModuleError' in gcpMetadata) {
|
|
9
|
+
return kmsProviders;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { access_token: accessToken } = await gcpMetadata.instance<{ access_token: string }>({
|
|
13
|
+
property: 'service-accounts/default/token'
|
|
14
|
+
});
|
|
15
|
+
return { ...kmsProviders, gcp: { accessToken } };
|
|
16
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { Binary } from '../../bson';
|
|
2
|
+
import { type AWSCredentialProvider } from '../../cmap/auth/aws_temporary_credentials';
|
|
3
|
+
import { loadAWSCredentials } from './aws';
|
|
4
|
+
import { loadAzureCredentials } from './azure';
|
|
5
|
+
import { loadGCPCredentials } from './gcp';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*
|
|
10
|
+
* A data key provider. Allowed values:
|
|
11
|
+
*
|
|
12
|
+
* - aws, gcp, local, kmip or azure
|
|
13
|
+
* - (`mongodb-client-encryption>=6.0.1` only) a named key, in the form of:
|
|
14
|
+
* `aws:<name>`, `gcp:<name>`, `local:<name>`, `kmip:<name>`, `azure:<name>`
|
|
15
|
+
* where `name` is an alphanumeric string, underscores allowed.
|
|
16
|
+
*/
|
|
17
|
+
export type ClientEncryptionDataKeyProvider = keyof KMSProviders;
|
|
18
|
+
|
|
19
|
+
/** @public */
|
|
20
|
+
export interface AWSKMSProviderConfiguration {
|
|
21
|
+
/**
|
|
22
|
+
* The access key used for the AWS KMS provider
|
|
23
|
+
*/
|
|
24
|
+
accessKeyId: string;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The secret access key used for the AWS KMS provider
|
|
28
|
+
*/
|
|
29
|
+
secretAccessKey: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* An optional AWS session token that will be used as the
|
|
33
|
+
* X-Amz-Security-Token header for AWS requests.
|
|
34
|
+
*/
|
|
35
|
+
sessionToken?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @public */
|
|
39
|
+
export interface LocalKMSProviderConfiguration {
|
|
40
|
+
/**
|
|
41
|
+
* The master key used to encrypt/decrypt data keys.
|
|
42
|
+
* A 96-byte long Buffer or base64 encoded string.
|
|
43
|
+
*/
|
|
44
|
+
key: Binary | Uint8Array | string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @public */
|
|
48
|
+
export interface KMIPKMSProviderConfiguration {
|
|
49
|
+
/**
|
|
50
|
+
* The output endpoint string.
|
|
51
|
+
* The endpoint consists of a hostname and port separated by a colon.
|
|
52
|
+
* E.g. "example.com:123". A port is always present.
|
|
53
|
+
*/
|
|
54
|
+
endpoint?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** @public */
|
|
58
|
+
export type AzureKMSProviderConfiguration =
|
|
59
|
+
| {
|
|
60
|
+
/**
|
|
61
|
+
* The tenant ID identifies the organization for the account
|
|
62
|
+
*/
|
|
63
|
+
tenantId: string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The client ID to authenticate a registered application
|
|
67
|
+
*/
|
|
68
|
+
clientId: string;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The client secret to authenticate a registered application
|
|
72
|
+
*/
|
|
73
|
+
clientSecret: string;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* If present, a host with optional port. E.g. "example.com" or "example.com:443".
|
|
77
|
+
* This is optional, and only needed if customer is using a non-commercial Azure instance
|
|
78
|
+
* (e.g. a government or China account, which use different URLs).
|
|
79
|
+
* Defaults to "login.microsoftonline.com"
|
|
80
|
+
*/
|
|
81
|
+
identityPlatformEndpoint?: string | undefined;
|
|
82
|
+
}
|
|
83
|
+
| {
|
|
84
|
+
/**
|
|
85
|
+
* If present, an access token to authenticate with Azure.
|
|
86
|
+
*/
|
|
87
|
+
accessToken: string;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** @public */
|
|
91
|
+
export type GCPKMSProviderConfiguration =
|
|
92
|
+
| {
|
|
93
|
+
/**
|
|
94
|
+
* The service account email to authenticate
|
|
95
|
+
*/
|
|
96
|
+
email: string;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A PKCS#8 encrypted key. This can either be a base64 string or a binary representation
|
|
100
|
+
*/
|
|
101
|
+
privateKey: string | Buffer;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* If present, a host with optional port. E.g. "example.com" or "example.com:443".
|
|
105
|
+
* Defaults to "oauth2.googleapis.com"
|
|
106
|
+
*/
|
|
107
|
+
endpoint?: string | undefined;
|
|
108
|
+
}
|
|
109
|
+
| {
|
|
110
|
+
/**
|
|
111
|
+
* If present, an access token to authenticate with GCP.
|
|
112
|
+
*/
|
|
113
|
+
accessToken: string;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @public
|
|
118
|
+
* Configuration options for custom credential providers for KMS requests.
|
|
119
|
+
*/
|
|
120
|
+
export interface CredentialProviders {
|
|
121
|
+
/* A custom AWS credential provider */
|
|
122
|
+
aws?: AWSCredentialProvider;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @public
|
|
127
|
+
* Configuration options that are used by specific KMS providers during key generation, encryption, and decryption.
|
|
128
|
+
*
|
|
129
|
+
* Named KMS providers _are not supported_ for automatic KMS credential fetching.
|
|
130
|
+
*/
|
|
131
|
+
export interface KMSProviders {
|
|
132
|
+
/**
|
|
133
|
+
* Configuration options for using 'aws' as your KMS provider
|
|
134
|
+
*/
|
|
135
|
+
aws?: AWSKMSProviderConfiguration | Record<string, never>;
|
|
136
|
+
[key: `aws:${string}`]: AWSKMSProviderConfiguration;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Configuration options for using 'local' as your KMS provider
|
|
140
|
+
*/
|
|
141
|
+
local?: LocalKMSProviderConfiguration;
|
|
142
|
+
[key: `local:${string}`]: LocalKMSProviderConfiguration;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Configuration options for using 'kmip' as your KMS provider
|
|
146
|
+
*/
|
|
147
|
+
kmip?: KMIPKMSProviderConfiguration;
|
|
148
|
+
[key: `kmip:${string}`]: KMIPKMSProviderConfiguration;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Configuration options for using 'azure' as your KMS provider
|
|
152
|
+
*/
|
|
153
|
+
azure?: AzureKMSProviderConfiguration | Record<string, never>;
|
|
154
|
+
[key: `azure:${string}`]: AzureKMSProviderConfiguration;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Configuration options for using 'gcp' as your KMS provider
|
|
158
|
+
*/
|
|
159
|
+
gcp?: GCPKMSProviderConfiguration | Record<string, never>;
|
|
160
|
+
[key: `gcp:${string}`]: GCPKMSProviderConfiguration;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Auto credential fetching should only occur when the provider is defined on the kmsProviders map
|
|
165
|
+
* and the settings are an empty object.
|
|
166
|
+
*
|
|
167
|
+
* This is distinct from a nullish provider key.
|
|
168
|
+
*
|
|
169
|
+
* @internal - exposed for testing purposes only
|
|
170
|
+
*/
|
|
171
|
+
export function isEmptyCredentials(
|
|
172
|
+
providerName: ClientEncryptionDataKeyProvider,
|
|
173
|
+
kmsProviders: KMSProviders
|
|
174
|
+
): boolean {
|
|
175
|
+
const provider = kmsProviders[providerName];
|
|
176
|
+
if (provider == null) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
return typeof provider === 'object' && Object.keys(provider).length === 0;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Load cloud provider credentials for the user provided KMS providers.
|
|
184
|
+
* Credentials will only attempt to get loaded if they do not exist
|
|
185
|
+
* and no existing credentials will get overwritten.
|
|
186
|
+
*
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
export async function refreshKMSCredentials(
|
|
190
|
+
kmsProviders: KMSProviders,
|
|
191
|
+
credentialProviders?: CredentialProviders
|
|
192
|
+
): Promise<KMSProviders> {
|
|
193
|
+
let finalKMSProviders = kmsProviders;
|
|
194
|
+
|
|
195
|
+
if (isEmptyCredentials('aws', kmsProviders)) {
|
|
196
|
+
finalKMSProviders = await loadAWSCredentials(finalKMSProviders, credentialProviders?.aws);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (isEmptyCredentials('gcp', kmsProviders)) {
|
|
200
|
+
finalKMSProviders = await loadGCPCredentials(finalKMSProviders);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (isEmptyCredentials('azure', kmsProviders)) {
|
|
204
|
+
finalKMSProviders = await loadAzureCredentials(finalKMSProviders);
|
|
205
|
+
}
|
|
206
|
+
return finalKMSProviders;
|
|
207
|
+
}
|