# Certificates from vaults

Many companies keep their certificates in one place, a vault, and expect each application to read its certificate from there and to notice a new version by itself. CrushMFT 27 Enterprise does this for the certificates of its TLS ports (HTTPS, FTPS, FTP with TLS) with:

| Vault | What CrushMFT reads |
|---|---|
| **Azure Key Vault** | a certificate (its secret, the PFX or PEM Key Vault keeps with the key), in the public cloud, Azure Government or Azure China |
| **AWS Secrets Manager** | a secret holding a PFX (binary), PEM text, or JSON fields |
| **AWS Certificate Manager** | an exportable certificate (a public certificate requested as exportable, or one of a private CA), exported with a passphrase CrushMFT makes for each export |
| **Google Secret Manager** | a secret version holding a PFX, PEM text or JSON fields, global or regional |
| **HashiCorp Vault** | a secret of a KV version 2 or version 1 secrets engine, its fields holding the certificate and key |

CrushMFT only reads a vault. It never writes, renews, disables or deletes anything in it.

## How it works

1. You make the **vault** a **KeyVault connection profile**: where it is, and how CrushMFT signs in to it (see [Adding a vault](#adding-a-vault)). The same profile can also hand passwords and keys to other connections.
2. You read a **certificate** from it (**From a vault**). CrushMFT reads it, checks it, and keeps it like any certificate. Put it on your ports with **Use it on…**.
3. CrushMFT **looks** at the vault every hour (you choose how often, 5 minutes at the least). A look asks only which version is the newest; the key is read only when there is a new one.
4. A **new version** is read, checked (the key belongs to the certificate, the dates, the chain, the names) and put in use on every port that serves it, here, on the DMZs and on the other servers of a cluster, without a restart. Connected users keep their sessions.

**Check now** on the certificate's Renewal tab looks at once, for when you have just put a new version into the vault.

## Adding a vault

A vault is a **KeyVault connection profile**, made like every connection profile ([Connection profiles](Connection-Profiles.md)): in the User Manager, **VFS Item Properties**, **Item type** **KeyVault**, choose the **Wallet Vendor** and fill in how CrushMFT reaches it, then **Save As Connection Profile**. The fields are listed in [Special types, KeyVault](VFS-Special-Types.md#keyvault). **Secret Name** can stay empty: each certificate names its own in Certificates. Secrets you type (an access key's secret, a Vault token, an AppRole secret id) are stored encrypted, as in every connection profile. Only full administrators save KeyVault profiles, and only they see them in Certificates.

The **Vaults** tab of Certificates lists the certificates read from vaults, each with its profile, what it follows, the version in use and the last look.

### Azure Key Vault

**Vault Name or Address**: the vault's name (`contoso-kv`) or `https://NAME.vault.azure.net` as its Overview shows it (Azure Government `.vault.usgovcloudapi.net`, Azure China `.vault.azure.cn`).

CrushMFT signs in with the **OAuth connection profile** the KeyVault profile names, and asks it for a token for Key Vault itself, whatever scope the OAuth profile was made for:

| The OAuth profile's grant type | What to set up in Azure |
|---|---|
| **Azure VM Lookup**, **Azure Arc**, **Azure App Service / Container Apps** (a managed identity; recommended, no secret kept) | Turn on the identity of the VM, the Arc-enabled server (on premises or in another cloud), or the app. Optional: the client id of a user-assigned identity. On an Arc server, the account CrushMFT runs as must be allowed to read the Arc agent's tokens: on Linux add it to the group `himds`, on Windows to "Hybrid agent extension applications". |
| **Azure AKS workload identity** | The pod's service account annotated for workload identity; the profile takes AKS's variables (AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_FEDERATED_TOKEN_FILE) when its fields are empty. |
| **Federation (OIDC)** | An app registration whose federated credential trusts CrushMFT's own OIDC issuer: no secret kept. |
| **Client Credentials**, **Client Credentials (Certificate)** | An app registration with a client secret (which ends, at most two years) or a certificate. |

The identity needs to read the certificate and its key:

- A vault that uses **Azure role-based access control**: the role **Key Vault Certificate User**, on the certificate or on the vault. For the list of certificates in the form, also **Key Vault Reader** on the vault. (A password the same profile hands to other connections needs only **Key Vault Secrets User**.)
- A vault that uses **access policies**: Certificates **Get** and **List**, Secrets **Get**.
- The vault's **networking** must let the CrushMFT server in: its outbound address in the firewall, or a private endpoint.

The certificate's key must be **exportable** (its issuance policy, or an imported certificate). A certificate made with a key that cannot be exported keeps its key inside the vault, so no server can use it for TLS.

### AWS Secrets Manager and AWS Certificate Manager

**AWS Region**: where the secret or the certificate is, such as `eu-central-1`. **AWS Credentials**:

| Signs in with | What to set up in AWS |
|---|---|
| **This machine's role** (recommended, no key kept) | The EC2 instance profile or the ECS task role CrushMFT runs with. |
| **An access key** | An IAM user's access key id and secret. |
| **A role, assumed with an access key** | The key's user may assume the role (`sts:AssumeRole`). |
| **A role, assumed with an OAuth connection profile's token** | The role trusts the identity provider that signs the profile's token, such as CrushMFT's own OIDC server (`AssumeRoleWithWebIdentity`). |

What the identity needs: for Secrets Manager `secretsmanager:DescribeSecret` and `secretsmanager:GetSecretValue` on the secret (and `kms:Decrypt` on its key when it has its own), `secretsmanager:ListSecrets` for the list in the form; for Certificate Manager `acm:DescribeCertificate` and `acm:ExportCertificate` on the certificate, `acm:ListCertificates` for the list. A Secrets Manager secret is named by its name or ARN; a Certificate Manager certificate by its ARN. Certificate Manager keeps only the current certificate, so "Only this version" cannot be used with it.

### Google Secret Manager

**Project ID**, and for regional secrets the **Location** (such as `europe-west3`). CrushMFT signs in with the **OAuth connection profile** the KeyVault profile names: a service account key (JWT Assertion), federation (OIDC), or the Google VM's service account. The identity needs **Secret Manager Secret Accessor** on the secret (and **Secret Manager Viewer** for the list in the form).

### HashiCorp Vault

**Vault Address** `https://vault.example.com:8200` (http only for a Vault on the same machine), the **Namespace** on Vault Enterprise, the **Secrets Engine** (the KV mount, `secret` when empty) and its **KV Version** (2, or 1), and **Vault Sign-in**. A Vault whose certificate comes from a private CA: paste that CA's certificate in **Vault CA Certificate**, and only it is trusted for the Vault.

| Signs in with | What to set up in Vault |
|---|---|
| **A Vault token** | A token whose policy may read the path (KV 2: `read` on `MOUNT/data/PATH` and `MOUNT/metadata/PATH`). |
| **AppRole** | A role id and a secret id; CrushMFT signs in for a token and signs in again before it ends. |

With KV version 1 Vault keeps no versions, so each look reads the fields and compares them: a change is a new version.

## Reading a certificate from a vault

Certificates, **From a vault**:

| Field | |
|---|---|
| **KeyVault profile** | the profile of the vault, shown with its vendor and address |
| **Certificate** | its name in the vault (Azure: the certificate's name; Secrets Manager: the secret's name or ARN; Certificate Manager: the ARN; Google: the secret's id; HashiCorp: the path below the mount). **List what it holds** offers what the sign-in can see. |
| **Versions** | **Always the newest version in the vault** (recommended), or **Only this version** and its id |
| **Look every** | minutes, 60 by default, at least 5 |
| **Kept** | **Kept in CrushMFT** (recommended) or **Only in memory**, see below |
| **Name in CrushMFT**, **Label** | optional |

**Test** reads it and shows what it would serve: its names, its end date, its issuer and chain. Nothing is saved. **Add it** keeps it; then **Use it on…** puts it on a port, as for any certificate.

### What the vault may hold

CrushMFT reads what is there, whatever the vault calls it:

- a **PFX** (PKCS#12) with no password, as Azure Key Vault keeps one, or base64 text of one;
- **PEM text** with the private key (PKCS#8, PKCS#1 `RSA PRIVATE KEY` or `EC PRIVATE KEY`) and the certificates, in any order;
- **JSON fields**: the certificate in `certificate` (or `cert`, `crt`, `tls.crt`), the key in `private_key` (or `key`, `tls.key`), the chain in `ca_chain` (or `chain`, `issuing_ca`, `ca`); or a PFX in `pfx` (base64) with its `password`.

A missing middle certificate is completed as for any certificate ([Chains](Certificates-Chains.md)).

### Kept in CrushMFT, or only in memory

**Kept in CrushMFT** keeps the version in use sealed on the server, with the last versions ([How CrushMFT keeps certificates](Certificates-How-CrushMFT-Keeps-Them.md)). A restart, a vault that cannot be reached, a firewall change or a sign-in that ended never stops a port: it keeps serving the version it has.

**Only in memory** never writes the certificate to disk, for security rules that allow no copy of a key outside the vault. Each server reads it from the vault itself (in a cluster every server needs the right to read the vault), and after a restart a port that uses it serves the built-in certificate until the vault answers. No older versions are kept. Where it is kept cannot be changed afterwards: add it again with the other choice.

## What happens on a new version

At each look:

| The vault has | CrushMFT |
|---|---|
| the version in use | nothing; the look is noted |
| a new version that is **disabled**, **not valid yet**, **deleted** or **not issued** | waits, and looks again at the next look |
| a new version | reads it, checks it, keeps it as the certificate's new version, and the ports, DMZs and cluster servers take it within seconds |
| a new version that **leaves out a name** a port serves | refuses it: see below |

Each look is on the certificate's **Renewal** tab under **Looks**, and in the server log.

### A version that is refused

When the version in use covers a name (say `ftp.example.com`) that the new one does not, and a port serves the certificate, the new version is not used: clients that ask for that name would get a certificate without it. The version in use stays, the Renewal tab says which names are left out, and the **TLS Certificate** alert is sent. Put a version with those names into the vault, or press **Use it anyway** to take it as it is.

A version that has ended, whose key does not belong to its certificate, or that cannot be read is refused the same way, without **Use it anyway**.

## When a look fails

When the vault cannot be reached or refuses CrushMFT (no route, the firewall, a sign-in that ended, a missing role), the version in use stays. CrushMFT tries again after 5, 15 and 60 minutes, then at the usual interval. The **TLS Certificate** alert is sent after a day of failures, or at once when the certificate in use ends within 14 days. The Renewal tab shows the vault's own words and what to change, such as the role to give.

## The Renewal tab of a certificate from a vault

The vault, the name in the vault, what it follows, the version in use and when it was taken, the last and the next look, where it is kept, and the looks. Buttons:

| Button | Does |
|---|---|
| **Check now** | a look now |
| **Use it anyway** | shown for a refused version: takes it as it is |
| **Change** | another KeyVault profile or name in the vault, newest or one version, how often |
| **Stop looking** / **Look again** | stops the looks and keeps the version in use, or starts them again |
| **Stop following** | the certificate stays as an ordinary one, no longer read from the vault (not for one kept only in memory) |

Removing the certificate (Details, **Remove**) removes it from CrushMFT only. Nothing in the vault changes.

## Cluster and DMZ

In a cluster only the server that runs the cluster's scheduled work looks at the vaults; the others get each new version with the certificates (only-in-memory certificates are read by each server, through the same KeyVault profile: profiles are replicated with the users). A DMZ never talks to a vault and holds no vault credentials: it gets the certificate from its server like any other.

## API

`GET /keys/tls-vault` (`tls.vault.status`) lists the certificates read from vaults, each with its KeyVault profile, the version in use and the last look; never a credential. `POST /keys/tls-vault/check` (`tls.vault.check`) is Check now, for one certificate (`name`) or all (`all=true`). The RBAC permission for vaults is `keys.ssl.vault`.

## License

Certificates from vaults are part of the **Enterprise** edition. On other editions the Vaults tab shows what it would do; certificates read before keep being served.
