|
| 1 | +.. _kafka-custom-auth: |
| 2 | + |
| 3 | +============================== |
| 4 | +Custom Authentication Provider |
| 5 | +============================== |
| 6 | + |
| 7 | +.. facet:: |
| 8 | + :name: genre |
| 9 | + :values: reference |
| 10 | + |
| 11 | +.. meta:: |
| 12 | + :keywords: credentials, implementation class, custom class |
| 13 | + |
| 14 | +.. contents:: On this page |
| 15 | + :local: |
| 16 | + :backlinks: none |
| 17 | + :depth: 2 |
| 18 | + :class: singlecol |
| 19 | + |
| 20 | +Overview |
| 21 | +-------- |
| 22 | + |
| 23 | +You can add a custom authentication provider by implementing the |
| 24 | +``com.mongodb.kafka.connect.util.custom.credentials.CustomCredentialProvider`` |
| 25 | +interface. You must place your custom class JAR file in the ``lib`` folder |
| 26 | +in your {+kafka-connect+} deployment. |
| 27 | + |
| 28 | +Set following authentication properties to configure the authentication |
| 29 | +provider: |
| 30 | + |
| 31 | +- ``mongo.custom.auth.mechanism.enable``: set to ``true`` |
| 32 | +- ``mongo.custom.auth.mechanism.providerClass``: set to the qualified |
| 33 | + class name of the implementation class |
| 34 | +- *(Optional)* ``mongodbaws.auth.mechanism.roleArn``: set to an Amazon Resource Name (ARN) |
| 35 | + |
| 36 | +AWS IAM Authentication Example |
| 37 | +------------------------------ |
| 38 | + |
| 39 | +This example provides a custom authentication provider that supports AWS |
| 40 | +IAM. The following code shows the custom authentication |
| 41 | +provider JAR file: |
| 42 | + |
| 43 | +.. literalinclude:: /includes/security/AwsAssumeRoleCredentialProvider.java |
| 44 | + :language: java |
| 45 | + |
| 46 | +Compile the JAR file and place it in the ``lib`` folder in your |
| 47 | +deployment. |
| 48 | + |
| 49 | +.. note:: |
| 50 | + |
| 51 | + To view an example of a ``pom.xml`` file that can build the complete JAR containing |
| 52 | + the implementation class, see the `Kafka Connector GitHub repository |
| 53 | + README file |
| 54 | + <https://github.com/mongodb/mongo-kafka/blob/master/README.md#pom-file-to-build-the-sample-customroleprovider-into-a-jar>`__. |
| 55 | + |
| 56 | +Next, configure your source or sink connector to include the custom |
| 57 | +authentication method. The following configuration properties define a |
| 58 | +sink connector that connects the {+connector-short+} to MongoDB Atlas |
| 59 | +by using AWS IAM authentication: |
| 60 | + |
| 61 | +.. code-block:: json |
| 62 | + :emphasize-lines: 12-14 |
| 63 | + |
| 64 | + { |
| 65 | + "name": "mongo-tutorial-sink", |
| 66 | + "config": { |
| 67 | + "connector.class": "com.mongodb.kafka.connect.MongoSinkConnector", |
| 68 | + "topics": "<topic>", |
| 69 | + "connection.uri": "<connection string>?authSource=%24external&authMechanism=MONGODB-AWS&retryWrites=true&w=majority", |
| 70 | + "key.converter": "org.apache.kafka.connect.storage.StringConverter", |
| 71 | + "value.converter": "org.apache.kafka.connect.json.JsonConverter", |
| 72 | + "value.converter.schemas.enable": false, |
| 73 | + "database": "<db>", |
| 74 | + "collection": "<collection>", |
| 75 | + "mongo.custom.auth.mechanism.enable": "true", |
| 76 | + "mongo.custom.auth.mechanism.providerClass": "com.mongodb.SampleAssumeRoleCredential", |
| 77 | + "mongodbaws.auth.mechanism.roleArn": "<AWS IAM ARN>" |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | +In this example, the ``roleArn`` value is the IAM Role of the user group that has |
| 82 | +access to MongoDB Atlas. In the AWS IAM console, the IAM account that is |
| 83 | +running {+kafka-connect+} has ``AssumeRole`` permissions to the Atlas User Group. |
0 commit comments