o Sb,@sdZddlmZmZmZmZmZzddlZdZWn e y#dZYnwddl m Z ddl m Z ddlmZer>dd lmZGd d d eZdS) z9Support for automatic client-side field level encryption.) TYPE_CHECKINGAnyListMappingOptionalNTF)validate_is_mapping)ConfigurationError)_parse_kms_tls_options) MongoClientc@seZdZdZ            ddeeefdeded d eeeefd ed ed ededee edeeeefdeedededeeddfddZ dS)AutoEncryptionOptszBOptions to configure automatic client-side field level encryption.NFmongodb://localhost:27020 mongocryptd kms_providerskey_vault_namespacekey_vault_clientr schema_mapbypass_auto_encryptionmongocryptd_urimongocryptd_bypass_spawnmongocryptd_spawn_pathmongocryptd_spawn_argskms_tls_optionscrypt_shared_lib_pathcrypt_shared_lib_requiredbypass_query_analysisencrypted_fields_mapreturncCststd|r td|||_| |_| |_| |_||_||_||_ ||_ ||_ ||_ ||_ ||_| dur8dg} | |_t|jtsEtdtdd|jDsU|jdt| |_| |_dS)aHOptions to configure automatic client-side field level encryption. Automatic client-side field level encryption requires MongoDB 4.2 enterprise or a MongoDB 4.2 Atlas cluster. Automatic encryption is not supported for operations on a database or view and will result in error. Although automatic encryption requires MongoDB 4.2 enterprise or a MongoDB 4.2 Atlas cluster, automatic *decryption* is supported for all users. To configure automatic *decryption* without automatic *encryption* set ``bypass_auto_encryption=True``. Explicit encryption and explicit decryption is also supported for all users with the :class:`~pymongo.encryption.ClientEncryption` class. See :ref:`automatic-client-side-encryption` for an example. :Parameters: - `kms_providers`: Map of KMS provider options. The `kms_providers` map values differ by provider: - `aws`: Map with "accessKeyId" and "secretAccessKey" as strings. These are the AWS access key ID and AWS secret access key used to generate KMS messages. An optional "sessionToken" may be included to support temporary AWS credentials. - `azure`: Map with "tenantId", "clientId", and "clientSecret" as strings. Additionally, "identityPlatformEndpoint" may also be specified as a string (defaults to 'login.microsoftonline.com'). These are the Azure Active Directory credentials used to generate Azure Key Vault messages. - `gcp`: Map with "email" as a string and "privateKey" as `bytes` or a base64 encoded string. Additionally, "endpoint" may also be specified as a string (defaults to 'oauth2.googleapis.com'). These are the credentials used to generate Google Cloud KMS messages. - `kmip`: Map with "endpoint" as a host with required port. For example: ``{"endpoint": "example.com:443"}``. - `local`: Map with "key" as `bytes` (96 bytes in length) or a base64 encoded string which decodes to 96 bytes. "key" is the master key used to encrypt/decrypt data keys. This key should be generated and stored as securely as possible. - `key_vault_namespace`: The namespace for the key vault collection. The key vault collection contains all data keys used for encryption and decryption. Data keys are stored as documents in this MongoDB collection. Data keys are protected with encryption by a KMS provider. - `key_vault_client` (optional): By default the key vault collection is assumed to reside in the same MongoDB cluster as the encrypted MongoClient. Use this option to route data key queries to a separate MongoDB cluster. - `schema_map` (optional): Map of collection namespace ("db.coll") to JSON Schema. By default, a collection's JSONSchema is periodically polled with the listCollections command. But a JSONSchema may be specified locally with the schemaMap option. **Supplying a `schema_map` provides more security than relying on JSON Schemas obtained from the server. It protects against a malicious server advertising a false JSON Schema, which could trick the client into sending unencrypted data that should be encrypted.** Schemas supplied in the schemaMap only apply to configuring automatic encryption for client side encryption. Other validation rules in the JSON schema will not be enforced by the driver and will result in an error. - `bypass_auto_encryption` (optional): If ``True``, automatic encryption will be disabled but automatic decryption will still be enabled. Defaults to ``False``. - `mongocryptd_uri` (optional): The MongoDB URI used to connect to the *local* mongocryptd process. Defaults to ``'mongodb://localhost:27020'``. - `mongocryptd_bypass_spawn` (optional): If ``True``, the encrypted MongoClient will not attempt to spawn the mongocryptd process. Defaults to ``False``. - `mongocryptd_spawn_path` (optional): Used for spawning the mongocryptd process. Defaults to ``'mongocryptd'`` and spawns mongocryptd from the system path. - `mongocryptd_spawn_args` (optional): A list of string arguments to use when spawning the mongocryptd process. Defaults to ``['--idleShutdownTimeoutSecs=60']``. If the list does not include the ``idleShutdownTimeoutSecs`` option then ``'--idleShutdownTimeoutSecs=60'`` will be added. - `kms_tls_options` (optional): A map of KMS provider names to TLS options to use when creating secure connections to KMS providers. Accepts the same TLS options as :class:`pymongo.mongo_client.MongoClient`. For example, to override the system default CA file:: kms_tls_options={'kmip': {'tlsCAFile': certifi.where()}} Or to supply a client certificate:: kms_tls_options={'kmip': {'tlsCertificateKeyFile': 'client.pem'}} - `crypt_shared_lib_path` (optional): Override the path to load the crypt_shared library. - `crypt_shared_lib_required` (optional): If True, raise an error if libmongocrypt is unable to load the crypt_shared library. - `bypass_query_analysis` (optional): **(BETA)** If ``True``, disable automatic analysis of outgoing commands. Set `bypass_query_analysis` to use explicit encryption on indexed fields without the MongoDB Enterprise Advanced licensed crypt_shared library. - `encrypted_fields_map`: **(BETA)** Map of collection namespace ("db.coll") to documents that described the encrypted fields for Queryable Encryption. For example:: { "db.encryptedCollection": { "escCollection": "enxcol_.encryptedCollection.esc", "eccCollection": "enxcol_.encryptedCollection.ecc", "ecocCollection": "enxcol_.encryptedCollection.ecoc", "fields": [ { "path": "firstName", "keyId": Binary.from_uuid(UUID('00000000-0000-0000-0000-000000000000')), "bsonType": "string", "queries": {"queryType": "equality"} }, { "path": "ssn", "keyId": Binary.from_uuid(UUID('04104104-1041-0410-4104-104104104104')), "bsonType": "string" } ] } } .. note:: `bypass_query_analysis` and `encrypted_fields_map` are part of the Queryable Encryption beta. Backwards-breaking changes may be made before the final release. .. versionchanged:: 4.2 Added `encrypted_fields_map` `crypt_shared_lib_path`, `crypt_shared_lib_required`, and `bypass_query_analysis` parameters. .. versionchanged:: 4.0 Added the `kms_tls_options` parameter and the "kmip" KMS provider. .. versionadded:: 3.9 zclient side encryption requires the pymongocrypt library: install a compatible version with: python -m pip install 'pymongo[encryption]'rNz--idleShutdownTimeoutSecs=60z%mongocryptd_spawn_args must be a listcss|]}d|vVqdS)ZidleShutdownTimeoutSecsN).0srrA/tmp/pip-target-onvjaxws/lib/python/pymongo/encryption_options.py sz.AutoEncryptionOpts.__init__..)_HAVE_PYMONGOCRYPTrrZ_encrypted_fields_mapZ_bypass_query_analysisZ_crypt_shared_lib_pathZ_crypt_shared_lib_requiredZ_kms_providersZ_key_vault_namespaceZ_key_vault_clientZ _schema_mapZ_bypass_auto_encryptionZ_mongocryptd_uriZ_mongocryptd_bypass_spawnZ_mongocryptd_spawn_pathZ_mongocryptd_spawn_args isinstancelist TypeErroranyappendr Z_kms_ssl_contexts)selfrrrrrrrrrrrrrrrrr __init__%s8     zAutoEncryptionOpts.__init__) NNFr Fr NNNFFN) __name__ __module__ __qualname____doc__rstrrrboolrr)rrrr r "sZ      r )r-typingrrrrrZ pymongocryptr" ImportErrorZpymongo.commonrZpymongo.errorsrZpymongo.uri_parserr Zpymongo.mongo_clientr objectr rrrr s