> ## Documentation Index
> Fetch the complete documentation index at: https://docs.certgov.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Workload Identity: Accepting Certs in Your Services

> How to make your services and AWS accounts trust CertGov workload certificates safely: trust the CA, check revocation, and check that the cert belongs to your organization.

CertGov issues and revokes workload certificates. Your services decide whether to accept them. This guide covers the three checks every service that accepts CertGov workload certs must make, with setup for nginx, Envoy/Istio, Go, Java, and AWS IAM Roles Anywhere.

> [!WARNING]
>
> A cert that chains to CertGov only proves CertGov issued it. Every CertGov customer's workload certs chain to the same CA. Skip check 3 below and a workload belonging to another organization can authenticate to your service.

## The three checks

| Check | What it stops | How |
| - | - | - |
| **1. Trust the CertGov workload CA** | Certs from anyone else | Configure the CertGov root as the trusted CA for client certificates |
| **2. Check revocation** | Certs you have revoked in CertGov | Load CertGov's certificate revocation lists (CRLs) and refresh them every few minutes |
| **3. Check the organization** | Certs from other CertGov customers | Require `OU=org:<your-org-id>` in the cert subject |

### Where the files are

| File | URL | Changes |
| - | - | - |
| Root CA certificate | `https://ca.certgov.io/root.crt` | Rarely (root lifetime is 15 years) |
| Workload intermediate | `https://ca.certgov.io/intermediates/workload-prod.crt` | About every 5 years |
| Intermediate CRL (revoked workload certs) | `http://crl.certgov.io/workload-prod.crl` | Every 10 minutes and on every revocation. Valid for 1 hour |
| Root CRL (revoked intermediates) | `http://crl.certgov.io/root.crl` | Yearly, or immediately if an intermediate is revoked |

All files are DER-encoded. Convert to PEM where a tool needs it:

```bash theme={null}
openssl x509 -inform DER -in root.crt -out certgov-root.pem
openssl crl  -inform DER -in workload-prod.crl -out workload-prod.crl.pem
```

> [!NOTE]
>
> CRL addresses use plain HTTP on purpose. CRLs are signed by the CA, so they can't be altered in transit, and many TLS libraries won't fetch CRLs over HTTPS.

### Your organization ID

Every workload cert CertGov issues to your organization carries `OU=org:<your-org-id>` in its subject. CertGov sets it. Your workload can't set or change it. To find yours, open any workload identity and check the trust policy on its page, or read it from one of your certs:

```bash theme={null}
openssl x509 -in workload-cert.pem -noout -subject
# subject=CN = payment-svc.workloads.acme.internal, OU = org:3f1c…
```

> [!WARNING]
>
> **Names are not proof of ownership.** Workload names (CN and SANs) are unique within your organization only. Another CertGov customer can enroll the same name. Always check the organization ID together with any name check.

### Revocation is not automatic

The CRL address is written into every workload cert, but most TLS stacks never fetch it on their own. Go checks nothing. nginx and Envoy check only a CRL file you give them. If you skip the revocation setup below, revoked certs keep working until they expire (1–7 days for most workload types).

Refresh the intermediate CRL every 5 minutes. How often you refresh decides how quickly a revocation reaches your service. Each CRL is valid for 1 hour, which covers a short CertGov outage. If your copy expires, strict validators reject **every** client cert, not only revoked ones.

***

## nginx

nginx checks CRLs for every certificate in the chain once `ssl_crl` is set, so give it both CRLs.

**1. Fetch the CA and CRLs.** Save as `/usr/local/bin/certgov-crl-refresh` and run it from cron every 5 minutes:

```bash theme={null}
#!/usr/bin/env bash
set -euo pipefail
D=/etc/nginx/certgov
mkdir -p "$D"; cd "$D"
curl -fsS https://ca.certgov.io/root.crt | openssl x509 -inform DER -out ca.pem.new
curl -fsS https://ca.certgov.io/intermediates/workload-prod.crt | openssl x509 -inform DER >> ca.pem.new
{ curl -fsS http://crl.certgov.io/workload-prod.crl | openssl crl -inform DER
  curl -fsS http://crl.certgov.io/root.crl          | openssl crl -inform DER; } > crl.pem.new
mv ca.pem.new ca.pem
mv crl.pem.new crl.pem
nginx -t -q && nginx -s reload
```

```cron theme={null}
*/5 * * * * root /usr/local/bin/certgov-crl-refresh
```

**2. Require and check client certs:**

```nginx theme={null}
server {
    listen 443 ssl;
    # ... your server certificate ...

    ssl_client_certificate /etc/nginx/certgov/ca.pem;
    ssl_verify_client      on;
    ssl_verify_depth       2;
    ssl_crl                /etc/nginx/certgov/crl.pem;

    # Check 3: only workloads from your organization.
    if ($ssl_client_s_dn !~ "OU=org:YOUR-ORG-ID") {
        return 403;
    }
}
```

nginx reads `ssl_crl` only at start and reload, which is why the script reloads it.

***

## Envoy and Istio

Give Envoy the CA bundle and both CRLs in its validation context. Refresh the CRL file every 5 minutes with the same script as nginx, then trigger a reload: an SDS update, or a hot restart for file-based config.

```yaml theme={null}
common_tls_context:
  validation_context:
    trusted_ca:
      filename: /etc/envoy/certgov/ca.pem
    crl:
      filename: /etc/envoy/certgov/crl.pem
require_client_certificate: true
```

For check 3, Envoy's built-in SAN matchers can't see the subject `OU`. Check it in a Lua filter in front of your routes:

```lua theme={null}
function envoy_on_request(handle)
  local ssl = handle:streamInfo():downstreamSslConnection()
  local subject = ssl and ssl:subjectPeerCertificate() or ""
  if not string.find(subject, "OU=org:YOUR-ORG-ID", 1, true) then
    handle:respond({[":status"] = "403"}, "certificate does not belong to this organization")
  end
end
```

In Istio, supply the CRL with your `DestinationRule` or `Gateway` TLS settings, and apply the same check with an `EnvoyFilter`.

***

## Go

`crypto/tls` checks the chain but never revocation. Add both checks in `VerifyConnection`:

```go theme={null}
package certgovauth

import (
	"crypto/tls"
	"crypto/x509"
	"errors"
	"fmt"
	"io"
	"net/http"
	"slices"
	"sync"
	"time"
)

const orgOU = "org:YOUR-ORG-ID"

// CRL holds the intermediate's revocation list, refreshed in the background.
type CRL struct {
	mu      sync.RWMutex
	revoked map[string]bool
	next    time.Time
}

func (c *CRL) Refresh(issuer *x509.Certificate) error {
	resp, err := http.Get("http://crl.certgov.io/workload-prod.crl")
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	der, err := io.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	crl, err := x509.ParseRevocationList(der)
	if err != nil {
		return err
	}
	if err := crl.CheckSignatureFrom(issuer); err != nil {
		return fmt.Errorf("CRL not signed by CertGov intermediate: %w", err)
	}
	revoked := make(map[string]bool, len(crl.RevokedCertificateEntries))
	for _, e := range crl.RevokedCertificateEntries {
		revoked[e.SerialNumber.String()] = true
	}
	c.mu.Lock()
	c.revoked, c.next = revoked, crl.NextUpdate
	c.mu.Unlock()
	return nil
}

// TLSConfig requires a CertGov client cert from this org that isn't revoked.
// Call crl.Refresh every few minutes.
func TLSConfig(roots *x509.CertPool, crl *CRL) *tls.Config {
	return &tls.Config{
		ClientAuth: tls.RequireAndVerifyClientCert,
		ClientCAs:  roots, // CertGov root (and intermediate)
		VerifyConnection: func(cs tls.ConnectionState) error {
			if len(cs.VerifiedChains) == 0 {
				return errors.New("no verified chain")
			}
			leaf := cs.VerifiedChains[0][0]
			if !slices.Contains(leaf.Subject.OrganizationalUnit, orgOU) {
				return errors.New("certificate belongs to another organization")
			}
			crl.mu.RLock()
			defer crl.mu.RUnlock()
			if time.Now().After(crl.next) {
				return errors.New("CRL is stale; refusing all client certificates")
			}
			if crl.revoked[leaf.SerialNumber.String()] {
				return errors.New("certificate revoked")
			}
			return nil
		},
	}
}
```

This fails closed when the CRL is stale. If you'd rather keep serving during a CertGov outage, allow a grace period, and make that a deliberate choice.

***

## Java

Turn on revocation checking with CRL fetching from the cert's distribution point:

```bash theme={null}
java -Dcom.sun.net.ssl.checkRevocation=true \
     -Dcom.sun.security.enableCRLDP=true \
     -Djavax.net.ssl.trustStore=certgov-truststore.p12 ...
```

Java then downloads `crl.certgov.io` CRLs itself and caches them until their `nextUpdate`. Check 3 is not built in: read the peer certificate's subject in your request filter (for example `X509Certificate.getSubjectX500Principal()`) and reject anything without `OU=org:YOUR-ORG-ID`.

***

## AWS IAM Roles Anywhere

AWS never fetches CRLs itself. CertGov pushes your CRL into your Roles Anywhere trust anchor within seconds of a revocation, using a role you create. CertGov stores no AWS keys.

**1. Create the trust anchor**

In IAM Roles Anywhere, create a trust anchor with source **External certificate bundle**. Paste the CertGov root (`root.crt`, PEM). Using the root means your setup survives an intermediate replacement. The trust policy in step 3 limits it to the production intermediate.

**2. Create the CertGov push role**

In CertGov, go to **Workload Identities → CRL Distribution**. Under **Create the CertGov push role**, copy the trust policy and permissions policy, and create an IAM role with them (for example `certgov-crl-push`). The trust policy allows only CertGov's AWS identity, and only with your organization's external ID. Don't remove the external ID condition: it stops another CertGov customer from pointing CertGov at your role.

**3. Create the workload role**

Create the IAM role your workloads will assume. Use a trust policy from CertGov:

* **Per workload:** the exact-name policy on the workload identity's page.
* **Shared roles:** the org-wide or per-policy versions on **Workload Identities → CRL Distribution**.

Every version requires your organization ID (`aws:PrincipalTag/x509Subject/OU`). Never remove that condition.

**4. Create the profile**

Create a Roles Anywhere profile that lists the workload role. Set the session duration to the minimum (15 minutes). Revoking a cert doesn't end sessions AWS has already issued.

**5. Connect CertGov**

Back on **Workload Identities → CRL Distribution**, enter the region, trust anchor ARN, profile ARN, workload role ARN, and the push role ARN. Click **Save Configuration**, then **Re-push CRL Now**. The status line shows the CRL ID once AWS has accepted it.

**6. Configure the workload**

Copy the `credential_process` snippet from the workload identity's page into the workload's `~/.aws/config`.

After a revocation, AWS refuses new credentials within seconds. Credentials already issued stay valid until their session ends, at most 15 minutes with the setting above.

### Keeping the CRL current yourself

If your security policy doesn't allow an outside service to assume a role in your account, skip the push role and upload the CRL yourself. CertGov still issues, governs and revokes your workload certs, and still publishes the signed CRL. Your job only copies it into AWS.

1. In step 5 above, leave **CertGov push role ARN** empty and clear **Enable CRL push**. Keep the trust anchor ARN saved, because CertGov uses it in the trust policies it generates.
2. Give the job an AWS identity in your account that allows only `rolesanywhere:ImportCrl` and `rolesanywhere:UpdateCrl`.
3. Import the CRL once and note the `crlId` in the response:

```bash theme={null}
curl -fsS http://crl.certgov.io/workload-prod.crl | openssl crl -inform DER -out workload-prod.crl.pem
aws rolesanywhere import-crl --region us-east-1 \
  --name certgov-workload-prod \
  --trust-anchor-arn arn:aws:rolesanywhere:us-east-1:111122223333:trust-anchor/EXAMPLE \
  --crl-data fileb://workload-prod.crl.pem --enabled
```

4. Run this every 5 minutes, for example from cron or a scheduled Lambda:

```bash theme={null}
#!/usr/bin/env bash
set -euo pipefail
CRL_ID=<crlId from step 3>
T=$(mktemp)
curl -fsS http://crl.certgov.io/workload-prod.crl | openssl crl -inform DER -out "$T"
aws rolesanywhere update-crl --region us-east-1 --crl-id "$CRL_ID" --crl-data "fileb://$T" >/dev/null
rm -f "$T"
```

What changes when you run the job yourself:

* **Revocations reach AWS on your schedule.** With a 5-minute job, a revoked cert can get new credentials for up to 5 minutes more, instead of seconds.
* **Failures are yours to monitor.** CertGov alerts you when its own push fails. It can't see your job, so alert on the job's failures yourself.

***

## Prove it works

Each organization has a **revoked test identity**: a permanently revoked cert and key. Generate it under **Workload Identities**, then present it to your service:

```bash theme={null}
curl -v --cert revoked-test.pem --key revoked-test.key https://your-service.example.com/
```

The TLS handshake must fail, or the service must return 403. If the request succeeds, the service is not checking revocation. Repeat with a valid workload cert from your organization, which must succeed. If you can, also try a cert from a second organization, which must fail.

For AWS, run `aws sts get-caller-identity --profile certgov-workload` with the revoked test identity's cert. AWS should reply `AccessDeniedException`.

## Related

* [Workload Identity overview](https://docs.certgov.app/guides/workload-identity.md)
* [Workload Identity: Setup & Testing](https://docs.certgov.app/guides/workload-identity-quickstart.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.