OpenClaw - Part 03: Vault and NGINX
- HashiCorp Vault: a centralized secrets manager, installed with a PKI and AppRole authentication.
- NGINX as a TLS reverse proxy with htpasswd authentication.
- Considering SELinux for both components.
- The agent's access dependencies are covered in part 4.
Introduction
After defining the target and preparing the VM's OS with the prerequisites, it's time to move on to installing the first components that will be used by future agents.
Vault
Introduction
Vault is a software product developed since 2015 by the American company HashiCorp, which now belongs to IBM.
It is a centralized secrets manager and encryption system. It acts as a highly secure repository from which human or software operators can request storage and/or access to sensitive data (passwords, API keys, private keys, certificates, etc., in general, secrets).
Click the image to enlarge.
How it works
The operation of Vault relies on several important concepts:
- Authentication (proving who you are): When an application (or a human) wants a password, it requests it from Vault after first proving its identity. Vault can verify this identity in many different ways (corporate directory, token, certificate, etc.).
- Access Policies (the "least privilege" rule): Once the identity is confirmed, Vault consults its rules. Thanks to this feature, it will be able to accurately determine which secrets an identity can access and with what rights (read/write).
- Dynamic Secrets (Vault's power): This is the most advanced feature. Instead of storing a fixed password (which could be stolen and reused), Vault can generate passwords on demand and for single use. This password has a lifespan, and once it expires, even if it were intercepted, it is no longer valid.
- Encryption as a Service (Transit): Vault can encrypt data. An application can send sensitive data to it, Vault encrypts it and returns the unreadable version without ever saving the data itself. The application stores the encrypted version.
- Sealing (The principle of a bank vault): To protect itself, Vault uses a mathematical technique (Shamir's Secret Sharing). When the Vault server starts, it is "sealed" and cannot read its own encrypted data. To unlock it, you need to enter a minimum number of tokens from several available tokens (for example, three out of five). If the quorum is reached, then Vault enters "unseal" mode and can be used.
Vault therefore replaces scattered secrets with a single, ultra-secure gateway that distributes temporary access only to those who can prove they need it.
In the case of our OpenClaw agents, this will benefit us because, instead of storing sensitive data directly in the agent configuration, we can organize them within Vault, and each agent can only consult those associated with it.
Installation
We will therefore install Vault in a standard way, outside the context of the openclaw user created during the previous step.
The certificate
Before working on the binaries, we will first prepare the certificate that will be used to present the Vault interface.
As I usually do, I will use my internal PKI based on my AD domain. I will not detail the operation specifically. Everyone can use the method of their choice; the goal is to end up with a private key and an associated certificate.
Since my PKI is private and unknown to the Rocky Linux OS, I start by declaring my CA within the system's trusted certificates.
I place the CA certificate, retrieved from one of the machines on my network, in the directory /etc/pki/ca-trust/source/anchors/
Click the image to enlarge.
Click the image to enlarge.
sudo cp /tmp/ca.crt /etc/pki/ca-trust/source/anchors/
I grant the correct permissions
sudo chown root:root /etc/pki/ca-trust/source/anchors/ca.crt
sudo chmod 644 /etc/pki/ca-trust/source/anchors/ca.crt
Then I run the following command, which will integrate my CA into all the certificates trusted by the OS
sudo update-ca-trust extract
Click the image to enlarge.
I confirm that everything is in order by making a CURL request to one of my internal URLs, which use a certificate issued by my PKI, for example, my Xen Orchestra instance.
curl -sSI https://prdxcpxor501.coolcorp.priv:8443/ | head -3
Click the image to enlarge.
There are no certificate errors, so it's OK at this level; my PKI is recognized.
Click the image to enlarge.
Now we will work on the certificate for Vault.
First, we prepare an OpenSSL configuration
at > vault-csr.conf <<'EOF'
[req]
default_bits = 4096
default_md = sha256
prompt = no
distinguished_name = dn
req_extensions = req_ext
[dn]
C = FR
ST = Ile-de-France
L = Paris
O = COOLCORP
OU = IT Infrastructure
CN = prdlinage501
[req_ext]
subjectAltName = @alt_names
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
[alt_names]
DNS.1 = prdlinage501
DNS.2 = prdlinage501.coolcorp.priv
DNS.3 = localhost
IP.1 = 127.0.0.1
EOF
Click the image to enlarge.
I also install OpenSSL, which is not installed by default on Rocky Linux:
sudo dnf install openssl
I generate my private key with 4096 bits
openssl genrsa -out vault.key 4096
Click the image to enlarge.
Then, using this key and the configuration I created just before, I generate the CSR (Certificate Signing Request).
openssl req -new -key vault.key -out vault.csr -config vault-csr.conf
Click the image to enlarge.
This is the CSR that I will present to my PKI to obtain the certificate. At this stage, since I am using Windows, I use the following command:
certreq -attrib "CertificateTemplate:TPL-SRV-WEB-DEFAULT" -submit .\vault.csr
TPL-SRV-WEB-DEFAULT is the name of my certificate template that I use for this type of purpose.
Click the image to enlarge.
At the end of the operation, I have my certificate and key. Once again, the goal here is not to go into detail; everyone can use the method of their choice depending on what they have available.
We keep the key and certificate safe for now (note that the key is a critical piece of data).
Click the image to enlarge.
Click the image to enlarge.
Installing packages
Vault is not included in the base OS packages, so you must first add the HashiCorp repositories
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
You can then install the tool
sudo dnf install -y vault
Click the image to enlarge.
Once installed, we check the version of Vault.
Click the image to enlarge.
The package has preconfigured the necessary components for the application to function, namely:
- Creation of a dedicated user and group: vault:vault
- Creation of directories:
- /opt/vault: to store data (Vault database and key/certificate).
- /etc/vault.d/: to store configurations
- A systemd unit for starting the service: /usr/lib/systemd/system/vault.service
- The binary: /usr/bin/vault
Note that the same binary is used for both the server and client sides; it takes different variables depending on the case. The service runs with Vault in server mode, and we will use the Vault binary in client mode to interact with the server.
Configuring Vault
The default configuration is not of interest to us, but we will set it aside just in case
sudo mv /etc/vault.d/vault.hcl /etc/vault.d/vault.hcl.rpm-orig
Similarly, we remove the certificate and key auto-generated at installation and replace them with the ones we have just created (in my case, my key and certificate were patiently waiting in /tmp).
sudo rm /opt/vault/tls/tls.crt
sudo rm /opt/vault/tls/tls.key
sudo cp /tmp/vault.key /opt/vault/tls/vault.key
sudo cp /tmp/vault.crt /opt/vault/tls/vault.crt
sudo cp /tmp/ca.crt /opt/vault/tls/ca.crt
Click the image to enlarge.
Most importantly, make sure to set the correct permissions on these components
sudo chown -R vault:vault /opt/vault/tls/
sudo chmod 600 /opt/vault/tls/vault.key
sudo chmod 644 /opt/vault/tls/vault.crt
sudo chmod 644 /opt/vault/tls/ca.crt
Click the image to enlarge.
It is time to focus on the configuration itself. This will be relatively basic because we are deploying Vault on a single-node configuration.
Indeed, Vault can be deployed in a cluster, which is actually recommended for production environments. Its replication mechanism is based on Raft and allows multiple instances to run online, replicating the database containing secrets for high availability of the service.
This is not what I will focus on here because I do not need this level of resilience.
I will simply use a single Vault instance on my VM configured to listen on the default port, which is TCP 8200.
Here is the configuration in question
sudo tee /etc/vault.d/vault.hcl > /dev/null <<'EOF'
# Vault configuration - prdlinage501
# Single-node Raft storage, TLS via enterprise PKI
ui = true
# Storage backend: Raft integrated
storage "raft" {
path = "/opt/vault/data"
node_id = "prdlinage501-vault-1"
}
# Listener: HTTPS sur toutes les interfaces
# (0.0.0.0 obligatoire pour que les conteneurs rootless Podman puissent
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file = "/opt/vault/tls/vault.crt"
tls_key_file = "/opt/vault/tls/vault.key"
tls_min_version = "tls12"
# tls_client_ca_file : ne pas déclarer si on n'utilise pas le mTLS client
# tls_prefer_server_cipher_suites : supprimé en Vault 2.0
}
# Cluster address (Raft mono-nœud, loopback suffit)
cluster_addr = "https://127.0.0.1:8201"
# api_addr doit utiliser le FQDN externe (utilisé par volt-agent dans les conteneurs)
api_addr = "https://prdlinage501.coolcorp.priv:8200"
# Disable mlock only if swap is disabled (it usually isn't)
# Keeping mlock enabled (default) to prevent secrets swap
disable_mlock = false
# Seal: Shamir (default, no config needed)
# Telemetry (optional, useful for monitoring)
telemetry {
prometheus_retention_time = "24h"
disable_hostname = true
}
EOF
I had AI comment the configuration to help understand what does what.
Click the image to enlarge.
We always ensure that we have the correct permissions for this new configuration.
sudo chown root:vault /etc/vault.d/vault.hcl
sudo chmod 640 /etc/vault.d/vault.hcl
Click the image to enlarge.
Note the disable_mlock option. By default, Vault prevents the use of swap so that secrets are not written there and potentially exposed. So swap must be disabled on the server.
sudo swapoff -a
Click the image to enlarge.
We need to make sure that it does not reactivate during the next boot by commenting out the associated line in fstab.
sudo vi /etc/fstab
Click the image to enlarge.
As mentioned earlier, Vault uses a specific port to be accessed; we will therefore open it on the server using firewall-cmd.
sudo firewall-cmd --permanent --add-port=8200/tcp
sudo firewall-cmd --reload
Click the image to enlarge.
Now, all that remains is to start the service and ensure that the configuration is correct
sudo systemctl enable --now vault.service
sudo systemctl status vault.service --no-pager
Click the image to enlarge.
Initialization
At this stage, we need to initialize the database.
First, we set the environment variable for the Vault URL so that the vault command we are going to call knows that it needs to connect to the local Vault server.
export VAULT_ADDR=https://127.0.0.1:8200
We check if access is functional.
vault status
We are now at a critical point: creating the database and the protection mechanism associated with it.
It is recommended to use the following command beforehand:
set +o history
In order to disable bash history to prevent any compromising elements from being stored within it.
We initialize the Vault configuration using the following command:
vault operator init -key-shares=5 -key-threshold=3 > /tmp/vault-init.txt
I chose to generate 5 unseal keys, with a minimum of three required.
The entire set is stored in /tmp/vault-init.txt
Warning: This file is extremely critical; it contains all the elements necessary for the security of the Vault configuration that we have just created.
If you examine it, you will find:
- The 5 keys used to unseal Vault
- The root token, which is the token used to authenticate with the Vault instance with the highest level of privileges.
All this information must be retrieved and stored in a secure location (in my case, my KeePass), and the file must then absolutely be deleted. Make sure it has not been synchronized anywhere.
Click the image to enlarge.
As explained, when Vault starts, it is "sealed".
Click the image to enlarge.
We must now unlock it using the following command:
vault operator unseal
We enter the first key.
We repeat this operation 3 times, using the same command but indicating the next key.
You can choose any of the five generated keys; the important thing is to use three different keys to reach the quorum and unseal Vault.
Click the image to enlarge.
You can verify this at the end of the operation.
vault status | grep -E 'Sealed|Initialized'
Initialized should be true and Sealed should be false.
Click the image to enlarge.
A small clarification at this point. It is important to understand that, from now on, each time the Vault instance is restarted (whether it's the service or the server), it will be resealed, and you will need to repeat this operation. That's why I recommend, at this stage, performing an initial server restart and ensuring that you can redo the process.
In a production environment, this could obviously cause problems. Fortunately, mechanisms exist to automatically unlock Vault when it is launched. For example, we can use an Azure vault (which has nothing to do with HashiCorp's Vault), but again, it is a secure space hosted in Azure via a managed service. We can use it to store the keys generated during Vault initialization. Then, we tell our Vault instance to connect to the Azure vault (I repeat, this is not the HashiCorp Vault that we just installed) to retrieve the keys and unlock itself. Other solutions are possible. It's up to you to see what works best for you.
In my case, I accept the fact that I will have to manually enter at least three keys each time I need to restart Vault.
Enabling features
Once unsealed, we can interact with Vault by providing it with the root token generated along with the five keys previously used.
vault login
(Don't forget to set the VAULT_ADDR variable if you reboot in between.)
Click the image to enlarge.
All the following commands will therefore be executed as the root user of the Vault instance.
First step, enable the secret engine
vault secrets enable -path=secret -version=2 kv
Click the image to enlarge.
Let's verify
vault secrets list
Second step, enable the AppRole authentication method.
Click the image to enlarge.
vault auth enable approle
Let's check that this is the case
vault auth list
RBAC configuration for agents
Now we will move on to the policy logic.
Policy
The idea is that each agent should be accompanied by a Vault Client container, which will connect to the Vault instance with a clearly defined role.
For example, my first bot, it-claw, will be associated with a policy that only allows it to read the secrets stored in Vault within the branch.
secret/openclaw/it-claw/
This translates to the following policy using the Vault syntax:
vault policy write openclaw-it-claw-read - <<'EOF'
# Read access to it-claw secrets only
path "secret/data/openclaw/it-claw/*" {
capabilities = ["read"]
}
# Allow listing keys (useful for vault-agent templating)
path "secret/metadata/openclaw/it-claw/*" {
capabilities = ["list", "read"]
}
# Allow token self-management (renew its own lease)
path "auth/token/renew-self" {
capabilities = ["update"]
}
path "auth/token/lookup-self" {
capabilities = ["read"]
}
EOF
We have just created a policy openclaw-it-claw-read that only allows reading (list, read) within the secret tree secret/metadata/openclaw/it-claw/*.
You can also verify the presence of this policy
vault policy list
vault policy read openclaw-it-claw-read
Click the image to enlarge.
Role
Now that we have this policy, it needs to be attached to a role. This is the same RBAC logic as Kubernetes.
We define a list of actions that can be performed on a given tree structure (the policy) and associate it with a role.
vault write auth/approle/role/openclaw-it-claw \
token_policies="openclaw-it-claw-read" \
token_ttl=1h \
token_max_ttl=24h \
secret_id_ttl=0 \
secret_id_num_uses=0
In this case, we have a role openclaw-it-claw with a token lifetime policy of a maximum of 24 hours, and an obligation for the application associated with this role (our agent) to reauthenticate every hour.
Click the image to enlarge.
However, the associated secretID does not expire.
It may not be immediately easy to understand at first.
With this command, we have just created an identity (a role) for the application openclaw-it-claw.
We configure a password (SecretID) that will never expire and can be used indefinitely. In exchange for this password, the application, which is our Vault agent linked to our IT-Claw agent, will receive a token from the Vault server with a limited lifetime. Through this token, the Vault agent associated with the AI agent will have read access to its secrets securely for one hour.
This small diagram should help simplify understanding.
Click the image to enlarge.
Some of you might point out that, in this logic, the secretID is a critical element. It is indeed. We have not used it yet at this stage, but it will have to be retrieved and put to use later. Several techniques can reduce the impact if it is stolen. In my case, one of the simplest improvements would be to restrict the use of this token to a local source IP. To do so, modify the role by adding the secret_id_bound_cidrs and token_bound_cidrs options so that requests are only accepted from localhost. We could also limit the secretID lifetime to 1 year (secret_id_ttl).
vault write auth/approle/role/openclaw-it-claw \
token_policies="openclaw-it-claw-read" \
token_ttl=1h \
token_max_ttl=24h \
secret_id_ttl=8760h \
secret_id_num_uses=0 \
secret_id_bound_cidrs="127.0.0.1/32" \
token_bound_cidrs="127.0.0.1/32"
This is a potential improvement that I have not yet implemented and that needs to be evaluated, but it's worth knowing.
ID
Now that the configuration is in place, we need to retrieve the role_id associated with the role we just created.
ROLE_ID=$(vault read -field=role_id auth/approle/rôle/openclaw-it-claw/rôle-id)
echo "$ROLE_ID"
This is not sensitive information; it's like a login. Therefore, we can write it to a file, specifically in our directory dedicated to our agents, as detailed in the previous article.
sudo mkdir -p /var/lib/openclaw/vault
echo "$ROLE_ID" | sudo tee /var/lib/openclaw/vault/it-claw-role-id > /dev/null
sudo chown openclaw:openclaw /var/lib/openclaw/vault/it-claw-role-id
sudo chmod 644 /var/lib/openclaw/vault/it-claw-role-id
We place this ID in the Vault subdirectory, making sure to specify the correct permissions, since our openclaw user will manipulate this file to manage the agents.
Click the image to enlarge.
Click the image to enlarge.
Everything is now in place within Vault so that it can be used later.
GUI
It is also possible to access the Vault user interface from an external machine using the URL specified in the certificate created at the beginning of this article (the name of my server, for example).
Using HTTPS on port 8200, you should be able to use your root token and access the Vault interface.
Click the image to enlarge.
Click the image to enlarge.
The idea is not to go into detail at this stage, but know that everything can be configured via the GUI.
You may decide not to expose it and not use it for security reasons.
Similarly, it is often recommended to create a new administrator user and not use the root account created by default for administrative tasks.
Since I am not a Vault expert either, and the goal is not to write an advanced Vault tutorial, I will not go further on this point. But feel free to read up and train on this tool; it is very widely used in IT and is considered a reference.
NGINX
The article is already quite comprehensive, but we need to add one more component before moving on: NGINX.
I will not introduce the well-known web server, but we will need it later, especially to provide secure access to the GUI of each agent.
OpenClaw does not natively offer TLS for accessing its interface, and you need to proxy the access if you want to improve security in this area.
Certificate
Once again, we will need a certificate, but this time not for the Vault graphical interface, but for the graphical interface of my first AI agent, it-claw.
For this, I use a new openssl configuration file.
cat > it-claw-csr.conf <<'EOF'
[req]
default_bits = 4096
default_md = sha256
prompt = no
distinguished_name = dn
req_extensions = req_ext
[dn]
C = FR
ST = Ile-de-France
L = Paris
O = COOLCORP
OU = IT Infrastructure
CN = prdlinage501
[req_ext]
subjectAltName = @alt_names
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
[alt_names]
DNS.1 = prdlinage501
DNS.2 = prdlinage501.coolcorp.priv
DNS.3 = localhost
DNS.4 = it-claw.coolcorp.priv
IP.1 = 127.0.0.1
EOF
Click the image to enlarge.
The goal is to have a certificate that can be used by NGINX and that responds to https://it-claw.coolcorp.priv.
I will not go into further detail about the certificate; it's exactly the same logic as for Vault.
We create the key and the CSR (Certificate Signing Request)
openssl genrsa -out it-claw.coolcorp.priv.key 4096
openssl req -new -key it-claw.coolcorp.priv.key -out it-claw.coolcorp.priv.csr -config it-claw-csr.conf
Click the image to enlarge.
And we use the CSR to obtain the certificate.
We keep our key and the certificate aside.
Click the image to enlarge.
Installation and configuration
We install NGINX.
sudo dnf install -y nginx httpd-tools
Click the image to enlarge.
We copy our key and certificate to the correct location so that they can be used by NGINX.
In my case, I choose /etc/pki/tls/certs and set the appropriate permissions.
sudo cp it-claw.coolcorp.priv.crt /etc/pki/tls/certs/it-claw.coolcorp.priv.crt
sudo cp it-claw.coolcorp.priv.key /etc/pki/tls/private/it-claw.coolcorp.priv.key
sudo chmod 644 /etc/pki/tls/certs/it-claw.coolcorp.priv.crt
sudo chmod 600 /etc/pki/tls/private/it-claw.coolcorp.priv.key
sudo chown root:root /etc/pki/tls/certs/it-claw.coolcorp.priv.crt \
/etc/pki/tls/private/it-claw.coolcorp.priv.key
This also involves using NGINX to ensure authentication for accessing the OpenClaw graphical interface.
Authentication
We could go as far as implementing OAUTH2 and using a solution like Azure Entra, but the tutorial is already long enough.
So, I'll stick with a simple web authentication method, but be aware that it's possible to do much better.
I'm using the htpasswd command, which is installed with the httpd-tools package, to create an authentication file in /etc/nginx/htpasswd
sudo mkdir -p /etc/nginx/htpasswd
sudo htpasswd -c /etc/nginx/htpasswd/it-claw bvivi57
In my case, my login for accessing the OpenClaw GUI will be bvivi57.
Click the image to enlarge.
Click the image to enlarge.
Configuration
Finally, let's configure Nginx
sudo tee /etc/nginx/conf.d/it-claw.conf <<'EOF'
server {
listen 443 ssl;
server_name it-claw.coolcorp.priv;
ssl_certificate /etc/pki/tls/certs/it-claw.coolcorp.priv.crt;
ssl_certificate_key /etc/pki/tls/private/it-claw.coolcorp.priv.key;
auth_basic "OpenClaw it-claw";
auth_basic_user_file /etc/nginx/htpasswd/it-claw;
location / {
proxy_pass http://127.0.0.1:18790;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-User $remote_user;
}
}
EOF
This configuration uses our certificates and allows Nginx to respond to it-claw.coolcorp.priv, while also including web authentication.
If this step is completed, Nginx will redirect internally to the container on port 18790, which corresponds to the port selected later to expose the web interface of our first it-claw agent.
The user will need to be passed on so that OpenClaw can use it later.
You thought it was finished, but you were wrong.
We need to allow Nginx to forward requests to this internal port. By default, SELinux will not allow this forwarding.
Therefore, we need to run the following commands:
sudo semanage port -a -t http_port_t -p tcp 18790
sudo setsebool -P httpd_can_network_connect 1
Click the image to enlarge.
Click the image to enlarge.
Also, remember to open the HTTPS port
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
We can now activate the Nginx service.
sudo systemctl enable --now nginx
For now, we cannot go any further with this configuration.
Conclusion
Vault is an extremely powerful tool, but it can be complex to understand initially. However, by combining it with containers that have the Vault binary and appropriate connection solutions, they can securely and dynamically retrieve everything our agents need to function.
Nginx will provide a minimum level of protection and encryption for using the graphical interfaces that our agents might expose to be controlled.
We now have what is needed to secure sensitive data that will need to be used by our OpenClaw agents. We also have a solution for exposing the interfaces of these same agents.
The next article will build on everything we've seen so far. We will address the access and usage dependencies related to our first agent: it's here!