Deployment
Regardless of whether you created your own distribution or used a standard one, the deployment process is pretty much the same, unless there are plugin-specific steps. In this section we will take an AuthGuard distribution from a dev server to a production setup.
#
TLSPerhaps the first and most important step is to enable TLS and enforce HTTPS traffic. In production, your authentication server should never use HTTP.
#
CertificatesYou must have a certificate for TLS, you can easily obtain one from Let's Encrypt, or through another provider. Another option which can be useful for testing production setup is to use a self-signed certificate. You may also use a self-signed one in production, although that is not recommended.
To generate a self-signed certificate using Java keytool, you can run the following command (adjust the parameters if you needed to)
If you already have a certificate and you want to package it as jks file to be to use it (this will create a new store)
#
ConfigurationThe server configuration options are explained in Configuration#Server , however here is the same example which is presented there
#
JWTBefore using JWTs, you need to generate
#
One-Time AdminThe One-Time Admin (OTA) is an admin that will be created automatically if no other admins exists. Its sole purpose to create at least one more admin and then it should be deleted. That admin only has access to the endpoints which are relavant to that task. The OTA will have the username and password specified by environment variables set in the configuration, for example
You have two options here:
- Run AuthGuard in a non-prod environment connected to the prod database where those variables are defined, create the other admin and generate an API key for it, then move the server to prod.
- Just keep them defined in the prod environment and proceed as usual.
#
Deploying the ServerThere are two options for deploying AuthGuard: as a container, as a normal process. In this example we will explain the latter since deploying it as a container is just like any other container. However, you will still need the environment variables. The pre-requisites for this example are:
- You are deploying to a Linux machine
- You have JRE or JDK installed (11+)
- You have systemd running
Environment Variables
Make sure the OTA variables, as well as any other variables required by the plugins are defined.
#
Build the DistributionUse AuthGuard CLI
If you used AuthGuard CLI to create the distribution then you can just
run ag build
and that will build it.
If you are using your own distribution, you can build it by running one of the following commands for Maven
Or, if you are using Gradle
#
Copy the FilesTo copy the JAR to your machine you can use the scp command
Then you can copy your configuration files there as well
And your secrets (JWT keys, certificates..etc)
In addition to that, we will also create a small script to run it
#
Systemd ServiceCreate the systemd serviceas follows
This is just the bare minimum
Add more as you need
Copy the service to /etc/systemd/system
, and then run the following commands