Using OIDC SSO Login¶
BastionXP SSH Certificate Manager with OIDC SSO Login¶
Follow the steps below to install and run BastionXP as SSH Certificate Manager that uses OIDC SSO Login providers such as Google G-Suite, Microsoft Azure 365, Okta and Keycloak, to authenticate admins and users before generating SSH certificates.
Prerequisites¶
You need to have the following to install and run BastionXP Certificate Manager:
- A Linux VM or server
- Open up TCP Port 443 (BastionXP web portal will be accessible on your server at this port )
- An app registration (OIDC client) with your company's SSO provider. Step 1.7 explains how to create it.
- Open up TCP port 4021 (Reverse proxy server port. Optional: BastionXP instance running in the host machines in "host" mode, will connect to this reverse proxy server port. Skip, if you plan to use bxp-cli client utility to download SSH host certificates and keys to your host machines.)
BastionXP PKI/CA VM Setup¶
Step 1.1 - Download and Install¶
On the Linux VM, follow the instructions here to download and install the appropriate BastionXP binary package for your Linux distro as RPM or Debian package.
BastionXP will be installed as a Linux Systemd service. It runs as root, and keeps its data in /var/lib/bastionxp.
Step 1.2 - The Server's Certificate¶
BastionXP serves its web portal and its API over HTTPS. For this, it needs a certificate and a private key, which you provide. BastionXP never creates its own HTTPS certificate.
Put the certificate and its private key in BastionXP's data directory, with these names:
In production, the certificate must be for BastionXP's domain name, for example ca.example.com. You can get it from your company's PKI or from a public CA. Or BastionXP can get one from Let's Encrypt by itself. See Configuration.
In this guide, BastionXP's domain name is ca.example.com. Your users' browsers and machines must trust the server's certificate. They already do if the certificate comes from a public CA, or from your company's PKI.
Step 1.3 - The Key-Encryption Key¶
BastionXP keeps the private keys of its CAs in its database, and it encrypts them there. The key that encrypts them is called the key-encryption key (KEK). The KEK is kept in a file outside the database.
Create the KEK once:
$ sudo mkdir -p /etc/bastionxp
$ sudo bastionxp kek create --out /etc/bastionxp/kek
KEK: /etc/bastionxp/kek
KEK id: 90e1fbc8cfcbe55a
Back it up now, separately from the database: in a password manager or a
safe, never next to the database backups. Losing the KEK means losing every
certificate authority. Every BastionXP server needs the same KEK.
See Key protection for more.
Step 1.4 - Configuration File¶
Create a configuration file named config.yaml in the /etc/bastionxp directory, with the following contents.
email: [email protected]
domain: ca.example.com
org_name: Example Corporation
kek_file: /etc/bastionxp/kek
emailis the email address of the web portal's first administrator.domainis the DNS name of your BastionXP server.org_nameis the name of your organization. BastionXP writes it into the certificates that it issues.kek_fileis the path of the KEK that you created in step 1.3.
See Configuration for all the settings.
Step 1.5 - Restart¶
The package starts BastionXP when you install it. At that time, there was no configuration file yet, so BastionXP could not start. Restart it now, so that it reads the configuration file.
BastionXP writes its log to the system journal. Read it with:
You will see log lines like these. This is a shortened example.
level=INFO msg="key-encryption key loaded" kek_id=90e1fbc8cfcbe55a
level=INFO msg="primary admin created" [email protected]
level=WARN msg="the primary admin has no password yet: open this link to set it, and a second factor" [email protected] link="https://ca.example.com/#/setup?token=0xKz30j3DjUeEUyEYOgWPzIzaztkhpCPh-02HfC2V0A" expires=2026-11-29T06:14:27Z
level=INFO msg="server started" address=:443 authorities=[]
The line with link= is important. It is the one-time link that you use in the next step to set up the administrator account.
If BastionXP does not start, the log tells you why. For example, the message may say that server.crt or the KEK is missing, or that a setting in config.yaml is misspelled.
Step 1.6 - Set up the Administrator Account¶
The first administrator has no default password. Instead, you use the one-time setup link from the log.
-
Open the setup link in your browser. The link works once, and it is valid for 24 hours.
If the link has expired, or if you cannot find it, make a new one with this command:
-
Choose a password. It must have at least 12 characters, and it must not be your email address or a password from a list of leaked passwords.
-
Set up a second factor. The portal asks every administrator for one. Scan the QR code with an authenticator app, such as Google Authenticator, Microsoft Authenticator or 1Password, and type the 6-digit code that the app shows. You can use a passkey instead.
-
Save the ten recovery codes that the portal shows, in your password manager. Each code works once, if you ever lose your authenticator app. The portal shows them only now.
You are now signed in to the web portal. See Sign in and set up your account for more about passwords, second factors and recovery codes.
Step 1.7 - Create the Root CA and an Authority¶
In the web portal:
-
In the sidebar, choose Authority Manager. Under Root CAs, on the ECDSA root CA card, choose Create ECDSA root CA, and confirm.
You create the root CA only once. It signs the intermediate CA of every authority that you add later.
The card now shows the root CA's SHA-256 fingerprint. Copy it with the button next to it. You need it in step 2.2.
-
Choose Add authority, and fill in:
- Name:
My CA. The Authority ID becomesmy-ca. - Select authority type: Certificate Authority.
- Issue SSH certificates (SSH CA): tick it. This creates the authority's SSH CA.
- Allow one-time tokens and SSO login: leave it ticked. It is ticked by default.
Leave the other options as they are. You can change them later on the authority's page.
- Name:
-
Choose Add authority.
The SSH CA is now ready. For all the options of an authority, see Certificate authorities.
Step 1.8 - Register BastionXP with your SSO Provider¶
Register BastionXP as an OIDC client app with your company's SSO provider. BastionXP supports Microsoft Entra ID (Azure 365), Google Workspace, Okta and Keycloak. Each provider has its own steps for this. Follow your provider's documentation.
Use this as the app's redirect (callback) URL:
The URL contains the authority's ID, my-ca. The users of this authority log in through this URL. Another authority has its own URL.
After you register the app, note these values. You need them in the next step:
- the app's Client ID and Client Secret;
- for Microsoft, also the Tenant ID;
- for Okta and Keycloak, also the Issuer URL.
Step 1.9 - Add the OIDC Verifier¶
In the web portal, open Authority Manager, then the authority my-ca. Under Verifiers, on the Single sign-on card, choose Set up, and fill in:
- OIDC provider: Microsoft, Google, Okta or Keycloak.
- Client ID and Client secret, from step 1.8.
- For Microsoft, the Tenant ID. For Okta and Keycloak, the Issuer.
Then save. From now on, the users of the authority my-ca log in with their SSO account when they get SSH certificates with bxp-cli.
SSO login for the web portal too
The OIDC verifier controls who gets certificates. It does not change how admins log in to the web portal. To let admins sign in to the portal with their SSO account too, see Single sign-on for the portal.
Get a Host Certificate¶
To get certificates from the CA, you use the BastionXP client, bxp-cli.
Step 2.1 - Download BastionXP client¶
Follow the instructions here to download and install BastionXP Client bxp-cli in your machine.
Step 2.2 - Establish Trust with the Certificate Manager¶
Before you can get SSH certificates from the CA, the bxp-cli client must trust the BastionXP certificate authority. bxp-cli trust sets this up.
bxp-cli trust needs two values:
- the authority's ID,
my-ca; - the root CA's SHA-256 fingerprint, which you copied in step 1.7, from the root CA's card in Authority Manager.
Give these two values to your users through a channel other than the BastionXP server itself. For example, send them in a message, or put them on a wiki page. Then, on every host and every client machine, run bxp-cli trust:
$ bxp-cli trust --ca-url https://ca.example.com --authority my-ca \
--fingerprint DE:E7:E7:C2:E2:64:AA:80:2A:5B:27:CA:A9:B0:F4:8D:60:2B:06:70:B8:CA:67:38:43:A1:52:B8:75:EC:8A:AC
Trusted: https://ca.example.com
Authority: my-ca
Root: BastionXP Root CA
SHA-256: dee7e7c2e264aa802a5b27caa9b0f48d602b0670b8ca673843a152b875ec8aac
Saved in: /home/bob/.bxp-cli
The bxp-cli commands use this from now on.
bxp-cli trust fetches the root CA's certificate from the server. It accepts the certificate only if its fingerprint matches the one you gave.
Then it saves two files in the .bxp-cli folder in your home directory. tls_root_ca.crt is the root certificate. config.json holds the server's address and the authority's ID.
bxp-cli trust makes only bxp-cli trust the CA. If you also want other programs on this machine to trust it, add the root CA's certificate to the system trust store. On Debian and Ubuntu, run:
sudo cp ~/.bxp-cli/tls_root_ca.crt /usr/local/share/ca-certificates/bastionxp-ca.crt
sudo update-ca-certificates
After this, programs on this machine trust every TLS certificate that the BastionXP CA issues. For other operating systems, see Trust the CA.
Step 2.3 - Get the Host Certificate¶
To get a host certificate, you need a one-time token. Create it in the web portal:
- Log in to the web portal at
https://ca.example.com. - Open Authority Manager, and then the authority
my-ca. - Under One-time tokens, choose Create token, and select the purpose
HOST-CERTIFICATE.
The token is valid for 10 minutes.
Next, open up a terminal window in your host/server and execute the below command with the token:
$ bxp-cli ssh --token [HOST-CERTIFICATE token] --principal host1.example.com
Certificate: /home/bob/.bxp-cli/ssh_host-cert.pub
Private key: /home/bob/.bxp-cli/ssh_host
Principals: host1.example.com
Valid until: 2027-02-17 14:37 UTC
User CA key: /home/bob/.bxp-cli/ssh_user_ca.pub
This command did not give --key, so bxp-cli ssh created a new RSA host key. bxp-cli saved three files in /home/bob/.bxp-cli/: the SSH host key, its certificate for the host host1.example.com, and the SSH user CA's public key:
Tip
You can also certify the host's existing SSH key, instead of a new one. Give the key with --key:
This writes the certificate to /etc/ssh/ssh_host_rsa_key-cert.pub. See SSH certificates.
Get a User Certificate¶
Step 3.1 - Get the SSH User Certificate¶
You also use bxp-cli to get an SSH user certificate. First, install bxp-cli on your client machine, and run bxp-cli trust there, as in step 2.2. Then run:
Without a token, bxp-cli ssh opens your web browser. There, you log in to your SSO provider, for example your Microsoft Azure 365 account. You log in with your company email address and password, and with two-factor authentication (2FA) if it is turned on.
Enable 2FA
For better security, we highly recommend you to enable Time-based One Time Password(TOTP) based 2FA authentication with your OIDC SSO provider.
The user certificate is issued only after a successful SSO+2FA login:
$ bxp-cli ssh
Log in in your browser. If it does not open, go to:
http://127.0.0.1:59023/login
Certificate: /home/bob/.bxp-cli/ssh_user-cert.pub
Private key: /home/bob/.bxp-cli/ssh_user
Principals: admin, ec2-user, [email protected]
Valid until: 2026-11-19 22:37 UTC
Roles: admins, ec2-users
Host CA key: /home/bob/.bxp-cli/ssh_host_ca-cert.pub
Tip
With the --no-browser flag, bxp-cli does not open your browser. It prints the login address instead. You can then open the address in any browser on the same machine.
You'll find the SSH user key, its certificate and the SSH host CA's certificate in the .bxp-cli folder in your home directory:
You can also certify your existing key, instead of a new one. Give the key with --key:
This writes the certificate to ~/.ssh/id_rsa-cert.pub. ssh finds it there by itself. Note that the CA signs only RSA keys. See SSH certificates.
Tip
You can visit your BastionXP web portal, define roles and logins for your organization and add the roles to each user.
View the Issued SSH Certificates:¶
We'll use the OpenSSH ssh-keygen tool to verify the certificates generated above.
SSH Root CA Certificate:¶
$ ssh-keygen -L -f /var/lib/bastionxp/ssh_host_ca-cert.pub
ssh_host_ca-cert.pub:
Type: [email protected] host certificate
Public key: RSA-CERT SHA256:cbGPaPpySLPPjL1DPRwLlGJ1HZoGYy9TN6ohIpSvulQ
Signing CA: RSA SHA256:cbGPaPpySLPPjL1DPRwLlGJ1HZoGYy9TN6ohIpSvulQ (using rsa-sha2-512)
Key ID: "ca.example.com-19a72e58-db9a-4c94-a149-0ee743bbd9b3"
Serial: 0
Valid: from 2023-09-16T09:52:35 to 2123-08-23T09:52:35
Principals:
ca.example.com
localhost
localhost
127.0.0.1
::1
Critical Options: (none)
Extensions: (none)
SSH Server Certificate:¶
$ ssh-keygen -L -f ~/.bxp-cli/ssh_host-cert.pub
ssh_host-cert.pub:
Type: [email protected] host certificate
Public key: RSA-CERT SHA256:i/JrxYvBvczFKNiaFYWWrSdPDLmGkz5xCzPvsuvc55U
Signing CA: RSA SHA256:cbGPaPpySLPPjL1DPRwLlGJ1HZoGYy9TN6ohIpSvulQ (using rsa-sha2-512)
Key ID: "host1.example.com-0f7795ee-c1fa-478e-af40-c2655ae71660"
Serial: 0
Valid: from 2023-09-16T09:56:40 to 2025-09-05T09:56:40
Principals:
host1.example.com
Critical Options: (none)
Extensions: (none)
host1.example.com in this case. This certificate cannot be used by any other host. BastionXP enforces identify based infrastructure access.
SSH User Certificate:¶
$ ssh-keygen -L -f ~/.bxp-cli/ssh_user-cert.pub
ssh_user-cert.pub:
Type: [email protected] user certificate
Public key: RSA-CERT SHA256:20vuGqOc8nFrdy4a8p/Rt2ui3H7g+XT/+wsxKed+Qhs
Signing CA: RSA SHA256:ydywz2m+Lc7iL3SpreSPAsr7/bfk77MZO6jeiGjsZ64 (using rsa-sha2-512)
Key ID: "[email protected]"
Serial: 0
Valid: from 2023-09-16T10:00:09 to 2023-09-16T18:00:09
Principals:
[email protected]
admin
ec2-user
Critical Options: (none)
Extensions:
permit-X11-forwarding
permit-agent-forwarding
permit-port-forwarding
permit-pty
permit-user-rc
[email protected]. Only user bob can use the above certificate to login via SSH into a host. Based on the roles and logins defined in the BastionXP certificate authority, the user certificate also has the principals set to admin and ec2-user.
Also, the SSH user certificates are valid only for a short-duration - 8 hours by default. Short-lived SSH user certificates provide fine-grained control over how long a user can have access to a previleged resource. It also avoids the SSH key sprawl problem.
Test using the SSH Certificates:¶
In the sections below, we'll use the SSH certificates generated above to configure an OpenSSH server to trust and permit logins using SSH user certificates issued by the SSH User Root CA.
SSH Server Configuration:¶
On the host host1.example.com, bxp-cli saved the SSH host key, its certificate and the SSH user CA's public key in /home/bob/.bxp-cli.
Copy these files to the /etc/ssh folder:
Configure the SSHd server to start using the SSH host certificate generated. Edit the /etc/ssh/sshd_config file as a sudo user and update the following configuration settings.
$ sudo nano /etc/ssh/sshd_config
...
HostKey /etc/ssh/ssh_host
HostCertificate /etc/ssh/ssh_host-cert.pub
TrustedUserCAKeys /etc/ssh/ssh_user_ca.pub
...
Finally, restart the SSHd service to make the configuration changes take effect. Verify if the SSHd is online, after the restart.
SSH Client Configuration¶
On the client machine, edit the SSH client's known_hosts file and add the Host CA's SSH certificate as the certificate authority for the host, using the @cert-authority directive. This config will ensure that the SSH client will accept any SSH host certificate signed by the SSH host CA. It will not display any Trust On First Use (TOFU) message when the SSH client connects to the host. Add the contents of the ssh_host_ca-cert.pub file to the known_hosts file as shown below.
$ echo "@cert-authority host1.example.com $(cat ~/.bxp-cli/ssh_host_ca-cert.pub)" >> ~/.ssh/known_hosts
Note
Your known_hosts file may already have old entries for this host. Remove them with ssh-keygen -R host1.example.com. Otherwise, ssh may warn that the host key changed.
Step 3.4 - SSH Login¶
Now SSH login to the host VM using the OpenSSH client as shown below
ssh -i ~/.bxp-cli/ssh_user [email protected]
The login name, here bob, must be one of the certificate's principals. The principals come from your roles.
bxp-cli does not open SSH connections itself. You use ssh to log in. ssh finds the certificate ~/.bxp-cli/ssh_user-cert.pub by itself, because it is next to the key.
Congratulations! You have successfully set up a private SSH CA with OIDC SSO based authentication configured. You generated host and user certificates. You used the SSH host certificate to configure an OpenSSH server in a host. You used the SSH user certificate to login to the OpenSSH server using an OpenSSH client.
Questions
If you have any questions or suggestions, please email us at: support@bastionxp.com