Skip to content
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

DOCSP-40811 Authentication Mechanisms #22

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/check-autobuilder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Check Autobuilder for Errors

on:
pull_request:
paths:
- "source/**"

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cbush/snooty-autobuilder-check@main
41 changes: 41 additions & 0 deletions .github/workflows/copy-compat-to-docs-shared.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Copy Files to docs-shared

on:
workflow_dispatch: {} # use to manually trigger workflow
push:
branches:
- "master"
paths:
- "source/includes/mongodb-compatibility-table-css.rst"
- "source/includes/language-compatibility-table-cxx.rst"

jobs:
copy-file:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Copy mongodb-compat table
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source_file: "source/includes/mongodb-compatibility-table-cxx.rst"
destination_repo: "10gen/docs-shared"
destination_folder: "dbx"
user_email: "[email protected]"
user_name: "docs-builder-bot"
commit_message: "Auto-import from docs-cpp"

- name: Copy language-compat table
uses: dmnemec/copy_file_to_another_repo_action@main
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source_file: "source/includes/language-compatibility-table-cxx.rst"
destination_repo: "10gen/docs-shared"
destination_folder: "dbx"
user_email: "[email protected]"
user_name: "docs-builder-bot"
commit_message: "Auto-import from docs-cpp"
39 changes: 39 additions & 0 deletions .github/workflows/vale-tdbx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: vale-checks
on:
pull_request:
paths:
- "source/**"

jobs:
vale:
name: TDBX Vale rules
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4

- id: files
uses: masesgroup/retrieve-changed-files@v2
with:
format: 'csv'

- name: checkout-latest-rules
uses: actions/checkout@v4
with:
repository: mongodb/mongodb-vale-action
path: './tdbx-vale-rules'
token: ${{secrets.GITHUB_TOKEN}}

- name: move-files-for-vale-action
run: |
cp tdbx-vale-rules/.vale.ini .vale.ini
mkdir -p .github/styles/
cp -rf tdbx-vale-rules/.github/styles/ .github/

- name: run-vale
uses: errata-ai/vale-action@reviewdog
with:
reporter: github-pr-check
files: ${{steps.files.outputs.added_modified}}
fail_on_error: true
token: ${{secrets.GITHUB_TOKEN}}
72 changes: 72 additions & 0 deletions source/includes/authentication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// start-scram-sha-256
#include <mongocxx/client.hpp>
#include <mongocxx/uri.hpp>

auto uri = mongocxx::uri("mongodb://<username>:<password>@<hostname>:<port>/?"
"authSource=admin&authMechanism=SCRAM-SHA-256");
mongocxx::client client(uri);
// end-scram-sha-256

// start-scram-sha-1
#include <mongocxx/client.hpp>
#include <mongocxx/uri.hpp>

auto uri = mongocxx::uri("mongodb://<username>:<password>@<hostname>:<port>/?"
"authSource=admin&authMechanism=SCRAM-SHA-1");
mongocxx::client client(uri);
// end-scram-sha-1

// start-x509
#include <mongocxx/client.hpp>
#include <mongocxx/uri.hpp>

auto uri = mongocxx::uri("mongodb://<hostname>:<port>/?"
"tls=true&tlsCertificateKeyFile=path/to/client.pem&authMechanism=MONGODB-X509");
mongocxx::client client(uri);
// end-x509

// start-aws-connection-uri
#include <mongocxx/client.hpp>
#include <mongocxx/uri.hpp>

auto uri = mongocxx::uri("mongodb://<AWS IAM access key ID>:<AWS IAM secret access key>@<hostname>:<port>/?"
"&authMechanism=MONGODB-AWS");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto uri = mongocxx::uri("mongodb://<AWS IAM access key ID>:<AWS IAM secret access key>@<hostname>:<port>/?"
"&authMechanism=MONGODB-AWS");
auto uri = mongocxx::uri("mongodb://<AWS IAM access key ID>:<AWS IAM secret access key>@<hostname>:<port>/?"
"authMechanism=MONGODB-AWS");

Remove extra & to prevent error: URI option "" contains no "=" sign: an invalid MongoDB URI was provided

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

mongocxx::client client(uri);
// end-aws-connection-uri

// start-aws-connection-uri-session
#include <mongocxx/client.hpp>
#include <mongocxx/uri.hpp>

auto uri = mongocxx::uri("mongodb://<AWS IAM access key ID>:<AWS IAM secret access key>@<hostname>:<port>/?"
"&authMechanism=MONGODB-AWSS&authMechanismProperties=AWS_SESSION_TOKEN:<token>");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"&authMechanism=MONGODB-AWSS&authMechanismProperties=AWS_SESSION_TOKEN:<token>");
"authMechanism=MONGODB-AWSS&authMechanismProperties=AWS_SESSION_TOKEN:<token>");

mongocxx::client client(uri);
// end-aws-connection-uri-session

// start-aws-environment
#include <mongocxx/client.hpp>
#include <mongocxx/uri.hpp>

auto uri = mongocxx::uri("mongodb://<hostname>:<port>/?"
"authMechanism=MONGODB-AWS");
mongocxx::client client(uri);
// end-aws-environment

// start-kerberos
#include <mongocxx/client.hpp>
#include <mongocxx/uri.hpp>

auto uri = mongocxx::uri("mongodb://mongodbuser%40EXAMPLE.COM@<hostname>:<port>/?"
"&authMechanism=GSSAPI"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"&authMechanism=GSSAPI"
"authMechanism=GSSAPI"

"&authMechanismProperties=SERVICE_NAME:<authentication service name>");
mongocxx::client client(uri);
// end-kerberos

// start-plain
#include <mongocxx/client.hpp>
#include <mongocxx/uri.hpp>

auto uri = mongocxx::uri("mongodb://<username>:<password>@<hostname>:<port>/?"
"&authMechanism=PLAIN&tls=true");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"&authMechanism=PLAIN&tls=true");
"authMechanism=PLAIN&tls=true");

mongocxx::client client(uri);
// end-plain
1 change: 1 addition & 0 deletions source/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MongoDB C++ Driver

/polyfill-selection
/installation
/security
/configuration
/client-side-encryption
/tutorial
Expand Down
25 changes: 25 additions & 0 deletions source/security.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. _cpp-security:

================
Secure Your Data
================

.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol

.. facet::
:name: genre
:values: reference

.. meta::
:description: Learn how to use {+driver-short+} to secure your data.

.. toctree::
:titlesonly:
:maxdepth: 1

/security/authentication
/security/enterprise-authentication
Loading
Loading