-
Notifications
You must be signed in to change notification settings - Fork 51
DOCSP-48377 Authentication Reorg #1040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cdc7f32
DOCSP-48377 Authentication Reorg
lindseymoore 1929cce
start building TOC
lindseymoore 146a47c
full draft
lindseymoore d210b9c
edits
lindseymoore e4eaf4e
edits
lindseymoore ba2463e
SA comments
lindseymoore 285742f
SA update redirect
lindseymoore 0617763
Edit table
lindseymoore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
.. _node-authentication-aws: | ||
|
||
================================== | ||
AWS Identity and Access Management | ||
================================== | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 3 | ||
:class: singlecol | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: atlas, amazon web services, code example | ||
|
||
Overview | ||
-------- | ||
|
||
The ``MONGODB-AWS`` authentication mechanism uses Amazon Web Services | ||
Identity and Access Management (AWS IAM) credentials to authenticate a user to MongoDB. | ||
You can use this mechanism only when authenticating to MongoDB Atlas. | ||
|
||
.. tip:: Configure Atlas for AWS IAM Authentication | ||
|
||
To learn more about configuring MongoDB Atlas for AWS IAM authentication, see | ||
:atlas:`Set Up Authentication with AWS IAM </security/aws-iam-authentication/>` in | ||
the Atlas documentation. | ||
|
||
Specify MONGODB-AWS Authentication | ||
---------------------------------- | ||
|
||
The ``MONGODB-AWS`` authentication mechanism uses your Amazon Web Services | ||
Identity and Access Management (AWS IAM) credentials to authenticate your | ||
user. If you do not already have the `AWS signature library | ||
<https://www.npmjs.com/package/aws4>`__, use the following | ||
``npm`` command to install it: | ||
|
||
.. code-block:: bash | ||
|
||
npm install aws4 | ||
|
||
To connect to a MongoDB instance with ``MONGODB-AWS`` authentication | ||
enabled, specify the ``MONGODB-AWS`` authentication mechanism. | ||
|
||
The driver checks for your credentials in the following sources in order: | ||
|
||
1. Connection string | ||
#. Environment variables | ||
#. Web identity token file | ||
#. AWS ECS endpoint specified in ``AWS_CONTAINER_CREDENTIALS_RELATIVE_URI`` | ||
#. AWS EC2 endpoint. For more information, see `IAM Roles for Tasks | ||
<https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html>`_. | ||
|
||
.. important:: | ||
|
||
The driver only reads the credentials from the first method that it detects | ||
in the order as given by the preceding list. For example, if you specify | ||
your AWS credentials in the connection string, the driver ignores any | ||
credentials that you specified in environment variables. | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Connection String | ||
:tabid: connection string | ||
|
||
To connect to your MongoDB instance with a connection string, pass | ||
your ``AWS_ACCESS_KEY_ID`` and ``AWS_SECRET_ACCESS_KEY`` | ||
credentials to the driver when you attempt to connect. If your AWS | ||
login requires a session token, include your ``AWS_SESSION_TOKEN`` as well. | ||
|
||
The following code shows an example of specifying the ``MONGODB-AWS`` | ||
authentication mechanism and credentials with a connection string: | ||
|
||
.. important:: | ||
|
||
Always **URI encode** the username and certificate file path using the | ||
``encodeURIComponent`` method to ensure they are correctly parsed. | ||
|
||
.. literalinclude:: /code-snippets/authentication/aws.js | ||
lindseymoore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:language: javascript | ||
|
||
.. tab:: Environment Variables | ||
:tabid: environment variables | ||
|
||
To authenticate to your MongoDB instance using AWS credentials stored in | ||
environment variables, set the following variables by using | ||
a shell: | ||
|
||
.. code-block:: bash | ||
|
||
export AWS_ACCESS_KEY_ID=<awsKeyId> | ||
export AWS_SECRET_ACCESS_KEY=<awsSecretKey> | ||
export AWS_SESSION_TOKEN=<awsSessionToken> | ||
|
||
.. note:: | ||
|
||
Omit the line containing ``AWS_SESSION_TOKEN`` if you don't need an AWS | ||
session token for that role. | ||
|
||
After you've set the preceding environment variables, specify the ``MONGODB-AWS`` | ||
authentication mechanism in your connection string as shown in the following example: | ||
|
||
.. literalinclude:: /code-snippets/authentication/aws-env-variable.js | ||
lindseymoore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:language: javascript | ||
|
||
.. tab:: Web Identity Token File | ||
:tabid: web-identity-token-file | ||
|
||
You can use the OpenID Connect (OIDC) token obtained from a web identity | ||
provider to authenticate to Amazon Elastic Kubernetes Service (EKS) or | ||
other services. | ||
|
||
To authenticate with your OIDC token you must first install | ||
`@aws-sdk/credential-providers | ||
<https://www.npmjs.com/package/@aws-sdk/credential-providers>`__. You can | ||
install this dependency using the following ``npm`` command: | ||
|
||
.. code-block:: bash | ||
|
||
npm install @aws-sdk/credential-providers | ||
|
||
Next, create a file that contains your OIDC token. Then | ||
set the absolute path to this file in an environment variable by using | ||
a shell as shown in the following example: | ||
|
||
.. code-block:: bash | ||
|
||
export AWS_WEB_IDENTITY_TOKEN_FILE=<absolute path to file containing your OIDC token> | ||
|
||
AWS recommends using regional AWS STS endpoints instead of global | ||
endpoints to reduce latency, build-in redundancy, and increase session token validity. | ||
To set the AWS region, set `AWS_REGION <https://docs.aws.amazon.com/sdkref/latest/guide/feature-region.html>`__ | ||
and `AWS_STS_REGIONAL_ENDPOINTS <https://docs.aws.amazon.com/sdkref/latest/guide/feature-sts-regionalized-endpoints.html>`__ | ||
as environment variables, as shown in the following example: | ||
|
||
.. code-block:: bash | ||
|
||
export AWS_STS_REGIONAL_ENDPOINTS=regional // Enables regional endpoints | ||
export AWS_REGION=us-east-1 // Sets your AWS region | ||
|
||
If both these environment variables aren't set, the default region is | ||
``us-east-1``. For a list of available AWS regions, see the | ||
`Regional Endpoints <https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints>`__ | ||
section of the AWS Service Endpoints reference in the AWS documentation. | ||
|
||
.. warning:: Consult your SDK's Documentation for Setting an AWS Region | ||
|
||
You cannot set your AWS region with environment variables for all SDKs, | ||
as in the above example. See your SDK's specific documentation for | ||
configuring an AWS region. | ||
|
||
After you've set the preceding environment variables, specify the ``MONGODB-AWS`` | ||
authentication mechanism in your connection string as shown in the following example: | ||
|
||
.. literalinclude:: /code-snippets/authentication/aws-env-variable.js | ||
lindseymoore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:language: javascript | ||
|
||
.. important:: Retrieval of AWS Credentials | ||
|
||
Starting in MongoDB version 4.11, when you install the optional | ||
``aws-sdk/credential-providers`` dependency, the driver uses the AWS SDK | ||
to retrieve credentials from the environment. As a result, if you | ||
have a shared AWS credentials file or config file, the driver will | ||
use those credentials by default. | ||
|
||
You can override this behavior by performing one of the following | ||
actions: | ||
|
||
- Set ``AWS_SHARED_CREDENTIALS_FILE`` variable in your shell to point | ||
to your credentials file. | ||
- Set the equivalent environment variable in your application to point | ||
to your credentials file. | ||
- Create an AWS profile for your MongoDB credentials and set the | ||
``AWS_PROFILE`` environment variable to that profile name. | ||
|
||
API Documentation | ||
----------------- | ||
|
||
To learn more about any of the methods or types discussed on this | ||
page, see the following API documentation: | ||
|
||
- `MongoClient <{+api+}/classes/MongoClient.html>`__ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.