Skip to content
  • Our Product
    • Namazu Elements
      • What is Elements?
      • Why open source?
      • Docs
        • Namazu Elements in Five Minutes or Less
        • RESTful APIs Library
        • Security Model
        • Accessing the Web UI (CMS)

    Our Product

    A logomark with three layered rhombuses adorning the lettermark that says Elements in bold all-caps sans-serif letters.
    • What is Namazu Elements? Discover our easy-to-use backend network solution built for online games. Rapidly enables full-scale multiplayer games or online solo adventures.
    • Why open source? Is there a truly open source server backend for connected games? There is now. Download and run a local copy of Namazu Elements and try it for yourself.
    Download Namazu Elements

    Get started

    • Quick start Read our Elements 5-minute quick start guide
    • Documentation Read our developer docs for learning more about Elements
    • RESTful APIs A full list of core API specs for working with the Elements framework
    • Security An overview of the server-authoritative security model of Elements
    • Accessing the CMS Manage your game with ease via the Namazu Elements CMS.

    Co-development Reimagined

    • Best real-time game backends in 2026 If you're researching an alternative to your current backend solution, we've prepared a report of all of the backend solutions on the market in 2026 and how Namazu Elements compares.
      Co-dev

    Recent Posts

    • The watercolor-styled Namazu Studios logo over a giant namazu lurking in the depth
      Namazu Studios Featured in San Diego Business Journal
      22 Sep 2025 Press
    • Namazu Elements 3.1 Released – Service Layer Fixes, Secure APIs, and Steam Bug Fix
      22 Apr 2025 Release Notes
  • Case Studies
  • About Us
  • News
  • Services
  • Book a call
namazu-studios-logo
Book a call

Getting Started

  • Namazu Elements in Five Minutes or Less
  • Accessing the Web UI (CMS)
  • CMS Feature Overview

Fundamentals

  • Why You Need a Server (and What “Authoritative” Means)
  • Elements as a Game Runtime
  • Where Your Authoritative Code Runs
  • Lifecycles and Flows

General Concepts

  • Overview
  • Custom Elements
  • Data Models
  • Security Model
  • N-Tier Architecture

Namazu Elements Core Features

  • User Authentication / Sign In
    • What is a User?
    • User Authentication in Elements
    • Email Verification
    • Auth Schemes
      • Auth Schemes
      • OAuth2
      • OIDC
  • Features
    • Applications
    • Sessions
    • Users and Profiles
    • Digital Goods
    • Progress and Missions
    • Progress and Missions (3.4+)
    • Leaderboards
    • Matchmaking – Comprehensive Guide
    • Followers
    • Friends
    • Product Bundles and SKUs
    • Receipts
    • Item Ledger
    • Reward Issuances
    • Save Data
    • Metadata
    • Metadata (3.4+)
    • Email Service
    • Queries
    • Web3
      • Wallets
      • Vaults
      • Omni Chain Support
      • Smart Contracts
        • Smart Contracts
  • Queries
    • Advanced Operators
    • Object Graph Navigation
    • Boolean Queries
    • Base Query Syntax
  • Advanced Operators
    • .name
    • .ref

Your Game Code - Adding Custom Elements

  • Custom Code Overview
  • Windows Setup
  • Mac OS Setup
  • Ubuntu Linux Setup
  • Element Anatomy: A Technical Deep Dive
  • Introduction to Guice and Jakarta in Elements
  • Structuring your Element
  • Events
  • Packaging an Element with Maven
  • Deploying an Element
  • Preparing for code generation
  • Properties
  • Websockets
  • RESTful APIs
  • Direct MongoDB Access (3.5+)

Configuration

  • Configuring External URLs for Deployment
  • Matchmaking – Comprehensive Guide
  • Direct Database Access and Batch Configuration
  • Connecting Namazu Elements to a TLS-Enabled MongoDB Replica Set
  • Batch Samples
    • Mission Upload Bash Script Sample
    • Item Upload Bash Script Sample

RESTful APIs

  • Importing into Postman
  • RESTful APIs Library
  • Swagger and Swagger UI

Add-Ons

  • Crossplay
    • Namazu Crossfire (Multiplayer)
    • Deploying Namazu Crossfire in your game
  • Roblox
    • Roblox Overview
    • Secure Player Authentication & Registration
    • Global Matchmaking
    • Roblox Security Best Practices

Game Engine & Client Support

  • Unity
    • Elements Unity Plugin
    • Unity Crossfire Plugin

Troubleshooting

  • Common Issues with Docker
  • Local SDK
    • Unable to deploy application : dev.getelements.elements.sdk.exception.SdkElementNotFoundException
    • Could not load class : java.lang.NoClassDefFoundError
  • Namazu Elements Community Edition
    • Common Issues with Docker
    • Unable to deploy application : dev.getelements.elements.sdk.exception.SdkElementNotFoundException
    • Running in the IDE
      • Exception in monitor thread while connecting to server localhost:27017
      • Could not deployAvailableApplications Jetty server Failed to bind to /0.0.0.0:8080 Address already in use

Releases

  • 3.7 Release Notes
  • 3.6 Release Notes
  • 3.5 Release Notes
  • 3.4 Release Notes
  • 3.3 Release Notes
  • 3.2 Release Notes
  • 3.1 Release Notes
View Categories
  • Home
  • Docs
  • Configuration
  • Connecting Namazu Elements to a TLS-Enabled MongoDB Replica Set

Connecting Namazu Elements to a TLS-Enabled MongoDB Replica Set

Est. read time: 3 min read

Overview #

Namazu Elements connects to MongoDB over TLS using mutual certificate authentication. The application side converts raw PEM certificates into PKCS12 (.p12) format for use by the Java client, while MongoDB itself consumes PEM files natively via OpenSSL. Ten environment variables drive the configuration, covering the connection URI, TLS certificate paths and passphrases, and the cryptographic algorithm selections.

Prerequisites #

The following tools must be available on the host running the Elements initialization script:

  • keytool (bundled with the JDK)
  • openssl

You will also need the following PEM files available at boot time, typically mounted as file secrets:

  • ca.pem – the certificate authority certificate
  • certificate.pem – the client private key concatenated with the client certificate (private key first)

MongoDB Node Configuration #

MongoDB natively understands PEM files via its built-in OpenSSL support. No special Java-side handling is needed on the database node. The relevant mongod.conf settings are:

📋
mongod.yaml
net:
  tls:
    mode: requireTLS
    CAFile: /etc/mongod.conf.d/ca.pem
    certificateKeyFile: /etc/mongod.conf.d/certificate.pem
  ipv6: true
  bindIpAll: true
replication:
  replSetName: <your-replica-set-name>

Replica Set is Mandatory

Namazu Elements uses MongoDB transactions which require a replica set, even if the set only has a single member. Without that some APIs will not work and we provide no guarantees which will and will not work with transactions disabled.

The certificateKeyFile must be a single PEM file containing the private key followed by the certificate, concatenated together:

📄
server.pem
-----BEGIN CERTIFICATE-----
<public key material>
-----END CERTIFICATE-----
-----BEGIN PRIVATE KEY-----
<private key material>
-----END PRIVATE KEY-----

On a Kubernetes-based deployment, these can be mounted as file secrets in the pod. On an AMI-based deployment, they should be placed at the equivalent paths on disk before mongod starts.

Application Node Configuration #

The Elements application node cannot consume PEM files directly from Java. The initialization script converts them to PKCS12 format using keytool and openssl before the application starts.

Certificate Conversion Script Snippet #

💻
mongo_init.sh
# Convert CA certificate to PKCS12 keystore
echo "yes" | keytool \
  -importcert \
  -alias "MongoDB Certificate Authority" \
  -file "${ELEMENTS_CONF}/mongo/ca.pem" \
  -keystore "${dev_getelements_elements_mongo_tls_ca}" \
  -storepass "${dev_getelements_elements_mongo_tls_ca_passphrase}"

# Convert client certificate + key to PKCS12
openssl pkcs12 \
  -export \
  -name "MongoDB Client Certificate" \
  -in "${ELEMENTS_CONF}/mongo/certificate.pem" \
  -out "${dev_getelements_elements_mongo_tls_client_certificate}" \
  -passout "pass:${dev_getelements_elements_mongo_tls_client_certificate_passphrase}"

The output .p12 files are then chowned to the elements user before the application process starts. The input PEM files at ${ELEMENTS_CONF}/mongo/ should be the same CA and concatenated client certificate/key described in the MongoDB node section above.

Default output paths (overridable via environment variables).

VariableDefault
dev_getelements_elements_mongo_tls_ca${ELEMENTS_CONF}/mongo_ca.p12
dev_getelements_elements_mongo_tls_client_certificate${ELEMENTS_CONF}/mongo_certificate.p12

Note

These variables are recommended as part of an initialization script as they overlap the variables understood by the Namazu Elements application code. The intent is that these are written to the container “just in time” as part of the server startup, but practically they need only be run at some time before application boot.

Environment Variables #

The following variables configure the Elements MongoDB connection. All are read by MongoConfigurationService at startup.

VariableDefaultSensitiveDescription
dev_getelements_elements_mongo_urimongodb://localhostNoMongoDB connection URI. Set tls=true in the query string to enable TLS.
dev_getelements_elements_mongo_database_nameelementsNoName of the MongoDB database used for Elements data storage.
dev_getelements_elements_mongo_tls_formatPKCS12NoKeyStore format for the CA and client certificate files.
dev_getelements_elements_mongo_tls_ca(blank)NoAbsolute path to the CA KeyStore file (.p12). May be blank if TLS is disabled.
dev_getelements_elements_mongo_tls_ca_passphrase(blank)YesPassphrase for the CA KeyStore. If blank, null is passed to KeyStore.load().
dev_getelements_elements_mongo_tls_client_certificate(blank)YesAbsolute path to the client certificate KeyStore file (.p12).
dev_getelements_elements_mongo_tls_client_certificate_passphrase(blank)YesPassphrase for the client certificate KeyStore. Used both to load the KeyStore and to initialize the KeyManagerFactory. An empty string and a null are not equivalent here.
dev_getelements_elements_mongo_tls_protocolTLSNoTLS/SSL protocol string passed to the SSL context.
dev_getelements_elements_mongo_tls_trust_algorithmSystem DefaultNoTrustManagerFactory algorithm. Defaults to TrustManagerFactory.getDefaultAlgorithm().
dev_getelements_elements_mongo_tls_key_algorithmSystem DefaultNoKeyManagerFactory algorithm. Defaults to KeyManagerFactory.getDefaultAlgorithm().

Connection URI Format #

When used in Kubernetes or with SRV records, this is the example format of the connection URI. The actual DNS record may vary depending on your specific setup (for example Route53).

mongodb+srv://<host>.<namespace>.svc.cluster.local/?replicaSet=<replica-set-name>&tls=true

Usage Notes

The tls=true parameter in the URI is what activates TLS in Elements. The Java code checks ConnectionString.getSslEnabled() and skips all certificate loading if it is not set. The host should resolve to all replica set members. When not using SRV for replica set resolution, use a standard mongodb:// URI with the appropriate hostnames.

Additionally, MongoDB has some idiosyncratic expectations with the format of the connection string and hostname. Specifically, the host is expected to be _mongodb._tcp. Pay careful attention to the hostname format and refer to the MongoDB Driver Documentation if you get stuck.

Source References #

For deeper implementation detail:

  • Certificate loading logic: sdk-mongo/src/main/java/dev/getelements/elements/sdk/mongo/StandardMongoConfigurationService.java
  • Integration tests: sdk-mongo-test/src/test/java/dev/getelements/elements/sdk/mongo/test/. These tests stand up a live replica set, configure it with test certificates, and exercise the full connection path. They serve as a working reference implementation.

Other References #

  • Java KeyStores – the gory details. Shoutout to Neil Maden for a great article on understanding the technical nuances of the Java KeyStore.
  • Reddit if you just need to vent. We get it.

What are your Feelings
Still stuck? How can we help?

How can we help?

Updated on May 13, 2026
Direct Database Access and Batch ConfigurationConfiguring External URLs for Deployment
Table of Contents
  • Overview
  • Prerequisites
  • MongoDB Node Configuration
  • Application Node Configuration
    • Certificate Conversion Script Snippet
  • Environment Variables
    • Connection URI Format
  • Source References
  • Other References
  • Documentation
  • Terms of Service
  • Privacy Policy
  • Contact us
  • Linkedin
  • Join our Discord

Namazu Studios LLC is powered by Namazu Elements, an open source modular backend framework for connected games.

Namazu Elements
  • Download
  • About Elements
  • Open source
  • Documentation
  • Support
Namazu Studios
  • Case Studies
  • About Us
  • News
Best realtime game backends 2026
Get in Touch
  • info@namazustudios.com
  • Book a call
  • (619) 862-2890
  • Linkedin
  • Discord

©2008-2026 Namazu Studios. All Rights Reserved.