NATS TLS Certificates
JAMS secures NATS with mutual TLS. Both sides of every connection present a certificate. The NATS server proves its identity to the JAMS services, and each JAMS service proves its identity to the NATS server. A client that cannot present a certificate signed by the JAMS root CA is refused.
This replaces the protection MSMQ inherited from Windows through queue permissions. NATS is an ordinary executable with no such support, so JAMS supplies the equivalent itself.
What Is Created, and When
On a standard installation this is automatic. The installer:
- Creates the JAMS root CA if the JAMS database does not already have one.
- Issues a NATS certificate signed by that root CA and installs it in the machine's Local Computer, Personal certificate store.
- Writes the three
.pemfiles the NATS server needs. - Restricts permissions on the NATS folder so standard users cannot read the private key.
- Adds the
tlsblock to the NATS configuration and starts the service.
You do not run any command. The work is recorded in DBUpdate.log in the Scheduler folder.
A failover pair must share one root CA. Importing that root onto the secondary node, and issuing the secondary's NATS certificate from it, are manual steps. See NATS in a Failover Environment.
Two Places, One Certificate
The NATS certificate lives in two places that must agree:
| Where | Used by |
|---|---|
| The Local Computer, Personal certificate store | The JAMS services, which present it when they connect to NATS |
The three .pem files in the NATS folder | The NATS server, which is not a .NET program and cannot read the Windows store |
If the store and the folder hold different certificates, the JAMS services cannot authenticate to NATS. Create NATS Certificate writes both, so they agree unless the folder is later changed by hand or the certificate is created into a different folder.
JAMS checks for this in two places:
List NATS Certificatereports both halves side by side. For the folder it shows whether each file exists, and fornats-server-cert.pemandnats-ca.pemthe thumbprint, subject, issuer, and expiry. It states whether the folder certificate is also in the store, asIn Certificate Store: YesorNo. It never prints key material.Add NATS ConfigurationandUpdate NATS Configurationrefuse to write a configuration whose certificate is not in the store. See Configuring the NATS Server.
If the folder certificate is not in the store, either re-issue it as described under Re-issuing the Certificate, or, when the store already holds the certificate you want, rewrite the folder from the store with Export NATS Certificate /DIRECTORYNAME as described under Moving a Certificate between Machines.
The Certificates and Files
| Item | Detail |
|---|---|
| Root CA subject | CN=JAMS Local Self-Signed Root CA |
| NATS certificate subject | CN=JAMS NATS-<MachineName> |
| Key usage | TLS server and TLS client. One certificate serves both roles. |
| Subject Alternative Names | Always localhost, 127.0.0.1, and the machine name. Add more with /SAN. |
| Validity | About 10 years |
The files in the NATS folder, by default C:\Program Files\MVPSI\JAMS\Scheduler\NATS:
| File | Contents |
|---|---|
nats-server-cert.pem | The NATS certificate (public). |
nats-server-key.pem | The matching private key. Unencrypted. Readable by the NATS service and administrators only. |
nats-ca.pem | The JAMS root CA (public). The trust anchor NATS validates clients against. |
The JAMS services do not check host names when they validate the NATS server. They require a certificate with the TLS server purpose, a subject beginning with JAMS NATS-, and a chain ending in the root CA in nats-ca.pem. This is why each node keeps its own per-machine certificate and the two only have to share a root CA.
The NATS Admin CLI is an ordinary TLS client and does check names. If you connect to a node by a name other than localhost, 127.0.0.1, or its machine name, add that name with /SAN= when you create the certificate.
Confirming TLS Is On
Run JAMSRegister.exe as Administrator from the Scheduler folder:
List NATS Configuration
Look for Mutual TLS, Reachable From Other Machines, and the Server Certificate thumbprint. Or ask the running server:
Invoke-RestMethod http://127.0.0.1:8222/varz | Select-Object tls_required, tls_verify
Both should be True.
The Certificate Commands
Run these in JAMSRegister.exe as Administrator from the Scheduler folder.
| Command | What it does |
|---|---|
List NATS Certificate | Reports the JAMS NATS certificates in the Local Computer, Personal store and the certificate files in the NATS folder, and whether the two match. Read-only. A missing folder is reported, not treated as an error. |
Create NATS Certificate | Issues a certificate from the default root CA, installs it in the store, writes the three .pem files to the NATS folder, and locks the folder down. Fails if the folder cannot be written, rather than leaving only the store half done. |
Destroy NATS Certificate | Removes the JAMS NATS certificate from the store. The .pem files stay on disk. |
Export NATS Certificate | Writes the store certificate to a .pfx file, to the NATS folder, or both. See Moving a Certificate between Machines. |
Import NATS Certificate | Installs a JAMS NATS certificate from a .pfx file into the store, and optionally into the NATS folder. See Moving a Certificate between Machines. |
The commands default to the NATS folder alongside JAMSRegister, which is where setup installs it. To work with another installation, pass /DIRECTORYNAME=<folder> to any certificate command. The configuration commands take /DIRECTORY=<folder> instead. Run JAMSRegister Help Create NATS Certificate, or Help with any other command name, for the full syntax.
| Commands | Folder qualifier |
|---|---|
List, Create, Export, Import NATS Certificate | /DIRECTORYNAME=<folder> |
List, Add, Update, Remove NATS Configuration | /DIRECTORY=<folder> |
Create and Destroy only touch the certificate. The NATS server keeps using whatever it loaded at startup until the configuration is regenerated and the service restarted. After any certificate change, run:
Update NATS Configuration /RESTART
That regenerates the configuration with the tls block, and restarts the JAMS NATS service and the JAMS services that depend on it. Create prints a reminder to do this. See Configuring the NATS Server.
Re-issuing the Certificate
Re-issuing is always destroy, create, then update. Run these on the machine whose certificate you are replacing:
Destroy NATS Certificate
Create NATS Certificate
Update NATS Configuration /RESTART
Restarting the NATS service stops the JAMS Scheduler, Server, and Executor with it and starts them again. Expect about a minute of downtime. Do this in a maintenance window. There is no way to swap the certificate without a restart.
Notes on the commands:
Createrefuses to run if the machine already has a JAMS NATS certificate. It stops withNATS Certificate already exists in Certificate Store. RunDestroyfirst.- If
DestroyreportsUnique JAMS NATS Certificate not found.while a certificate is clearly present, the store holds more than one matching certificate. Name one withDestroy NATS Certificate /THUMBPRINT=<thumbprint>or/SUBJECT=<subject>. Find thumbprints withList NATS Certificate. /SAN=name1,name2adds extra DNS names or IP addresses to the certificate./LOGwrites the command's output to a log file. RunJAMSRegister Help Create NATS Certificatefor the full syntax.
In a failover pair, re-issue one node at a time and confirm messaging is healthy before moving to the other. The two nodes' certificates are independent. They only have to chain to the same root CA.
After Destroy alone, the .pem files and the tls block are still in place, so the NATS server keeps demanding a client certificate. The JAMS services look for theirs in the Windows store, where it no longer exists, and fail to connect with:
NATS is configured for TLS but no usable JAMS NATS client certificate was found in the Local Machine personal store.
Always follow Destroy with Create and Update NATS Configuration /RESTART.
Moving a Certificate between Machines
Create NATS Certificate needs the root CA's private key on the machine where it runs. When that key is elsewhere, or when you want to put an existing certificate on a machine without re-issuing it, use Export NATS Certificate and Import NATS Certificate. They follow the same pattern as the Scheduler, Executor, and Agent certificate commands, with one addition. Because the NATS certificate lives in the store and in the folder, both commands can write the NATS folder too.
| Command | What it does |
|---|---|
Export NATS Certificate /FILENAME=<file.pfx> /PROMPT | Writes the store certificate, with its private key, to a .pfx file protected by the password you enter. /PASSWORD=<password> supplies it on the command line instead. /PEM writes PEM rather than PFX, and /CHAIN includes the issuing CA. |
Export NATS Certificate /DIRECTORYNAME | Rewrites the three .pem files in the NATS folder from the certificate in the store, and locks the folder down. This is the repair when List NATS Certificate shows In Certificate Store: No and the store holds the certificate you want. |
Import NATS Certificate /FILENAME=<file.pfx> /PROMPT | Installs a certificate from a .pfx file into the store. Only a JAMS NATS certificate is accepted. Its subject must begin with JAMS NATS- and it must be valid for both TLS server and TLS client use. Anything else is rejected with a message saying why. |
Import NATS Certificate /FILENAME=<file.pfx> /PROMPT /DIRECTORYNAME | The same import, and also writes the three .pem files, so one command puts the certificate in both places. The .pfx must contain the private key. |
Notes on the commands:
/DIRECTORYNAMEon its own means the NATS folder alongside JAMSRegister. Give it a value to write a different folder. OnExport,/FILENAMEand/DIRECTORYNAMEcan be used together or separately.- When the store holds more than one JAMS NATS certificate,
Exportstops withMultiple JAMS NATS certificates found in the store. Choose one with/THUMBPRINT=<thumbprint>or/SUBJECT=<subject>. - Importing a certificate that is already in the store, matched by thumbprint, does nothing. Importing a different JAMS NATS certificate stores it alongside the existing one. See Rotating the Certificate.
nats-ca.pemis written from the machine's default root CA, so that root must be the CA that issued the certificate. If it is not, the command stops before writing anything and names both, because the TLS handshake would otherwise fail later with nothing pointing back at the cause.- Like
CreateandDestroy, these commands never change the NATS configuration or restart a service. After writing the folder, runUpdate NATS Configuration /RESTART. If you wrote a custom folder, pass the same folder to that command with/DIRECTORY=<folder>.
Issuing a Certificate for a Machine That Does Not Hold the Root CA
On a machine that has the root CA's private key, issue the certificate to a file instead of installing it. /NOSTORECERT keeps it out of that machine's own store, and /NATSNAME sets the subject to the target machine's name. The Subject Alternative Names always include the name of the machine you run the command on, so add the target machine's name with /SAN.
Create NATS Certificate /NOSTORECERT /FILENAME="C:\Temp\nats-NODE2.pfx" /PROMPT /NATSNAME=NODE2 /SAN=NODE2
Copy the .pfx to the target machine. That machine needs the issuing root CA configured as its default root CA, but not the root's private key. Then, in JAMSRegister on the target:
Import NATS Certificate /FILENAME="C:\Temp\nats-NODE2.pfx" /PROMPT /DIRECTORYNAME
Update NATS Configuration /RESTART
Delete the .pfx from both machines when you are done. It contains the private key.
Rotating the Certificate
The NATS certificate is valid for about ten years, so rotation is rare. When it is needed, the simplest route is the destroy, create, update sequence under Re-issuing the Certificate. This section describes the alternative, which keeps the old certificate available until you are satisfied with the new one.
How NATS and the JAMS Services Agree on a Certificate
The NATS server presents whatever is in nats-server-cert.pem. Each JAMS service reads the thumbprint of that same file and looks it up in the Local Computer, Personal store, and presents the matching store certificate as its client certificate. So the store can hold more than one JAMS NATS certificate. The one in the NATS folder is the active one, and the others are inactive until the folder is rewritten from them.
Which certificate is active is a configuration decision, so it is made with Update NATS Configuration /THUMBPRINT or /SUBJECT, not with the certificate commands. Create NATS Certificate refuses to run while a certificate exists because it cannot know whether you meant to replace the one in use. See Choosing the Certificate.
List NATS Certificate shows every JAMS NATS certificate in the store and marks which one is in the folder. List NATS Configuration shows the active certificate's thumbprint under Server Certificate.
Rotating with the Old Certificate Kept for Rollback
-
Import the new certificate and make it active. Import the certificate issued elsewhere into the store only, then select it. The Default Root CA configured on this machine must be the one that issued the new certificate, because the update writes
nats-ca.pemfrom it and stops if they differ. The update writes the NATS folder from it, regenerates the configuration, and restarts the JAMS NATS service and the JAMS services that depend on it:Import NATS Certificate /FILENAME="C:\Temp\nats-new.pfx" /PROMPTUpdate NATS Configuration /THUMBPRINT=<new thumbprint> /RESTART -
Verify.
List NATS Certificateshows both certificates in the store, with the new one in the folder.List NATS Configurationshows the new thumbprint underServer Certificate, and the JAMS services are connected. See Confirming TLS Is On. -
Roll back if needed. Select the old certificate again. Both are still in the store, so nothing has to be re-issued:
Update NATS Configuration /THUMBPRINT=<old thumbprint> /RESTART -
Retire the old certificate once you are satisfied:
Destroy NATS Certificate /THUMBPRINT=<old thumbprint>
The restart in step 1 is still a restart. It stops and starts the JAMS Scheduler, Server, and Executor, so do it in a maintenance window. What this procedure saves is not the restart but the risk: the old certificate stays available until you choose to remove it.
In a failover pair, rotate one node at a time and confirm messaging is healthy before moving to the other. Each node's certificate is its own. Only the root CA is shared.
Rotating the Root CA
A new root CA invalidates every NATS certificate issued from the old one, on every node. nats-ca.pem can hold more than one CA, so a transition is possible in which both roots are trusted while each node's certificate is re-issued from the new root, after which the old root is removed from the file. No JAMSRegister command writes that bundle today. Until one does, treat a root CA change as a re-issue on every node, in a single maintenance window.
If Certificates Are Missing
JAMS does not take messaging down over a certificate problem. If the root CA is unavailable, or issuing the certificate fails, setup still writes a working configuration and starts NATS, but without TLS and bound to 127.0.0.1 only. The reason is in DBUpdate.log:
| Log message | Meaning |
|---|---|
Creating NATS TLS certificate. then Created NATS TLS certificate. | Normal on a first install. |
An existing NATS TLS certificate was found. | Normal on an upgrade. The existing certificate was kept. |
The root CA changed. Re-issuing the NATS TLS certificate from the current default root CA. | Setup created a new root CA, so the old NATS certificate was replaced. |
The Root CA is not available. TLS will have to be set up manually. | The shared root CA is not in this machine's store. Expected on a failover secondary. See NATS in a Failover Environment. |
Unable to create the NATS TLS certificate. NATS will run without TLS: ... | Issuing failed. NATS is running on loopback only. |
A single-server installation keeps working in this state, because all its traffic is local. A failover pair does not: cross-node messaging stops until certificates exist on both nodes.
To recover, make sure the root CA is available, then:
Create NATS Certificate
Update NATS Configuration /RESTART
If Create reports that a certificate already exists, run Destroy NATS Certificate first.
Uninstall
Uninstalling JAMS removes the JAMSNATSServer service but leaves the .pem files, the certificate in the store, the NATS log, and the message store under C:\ProgramData\JAMS\NATS. To clean the machine fully:
Destroy NATS Certificate
Remove-Item "C:\Program Files\MVPSI\JAMS\Scheduler\NATS\*.pem"
Remove-Item "C:\ProgramData\JAMS\NATS" -Recurse