Skip to content

[Hyperdrive] add drivers and orms docs #22125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d7eb2e1
[Hyperdrive] drafting custom cert support for Hyperdrive
thomasgauvin Mar 24, 2025
d578ae1
corrections
thomasgauvin Mar 28, 2025
7a2aeb5
wip
thomasgauvin Apr 8, 2025
1bb1afc
add changelog
thomasgauvin Apr 8, 2025
2eb045c
adjust per comments
thomasgauvin Apr 8, 2025
6131158
add note on wrangler version
thomasgauvin Apr 8, 2025
a4409e7
add troubleshooting guides for ssl certs
thomasgauvin Apr 8, 2025
a5bcb69
change changelog entry date
thomasgauvin Apr 8, 2025
28638fa
Update src/content/docs/hyperdrive/configuration/tls-ssl-certificates…
thomasgauvin Apr 9, 2025
8442a7b
Update src/content/docs/hyperdrive/configuration/tls-ssl-certificates…
thomasgauvin Apr 9, 2025
a637925
PCX review
Oxyjun Apr 9, 2025
a244fa6
add drivers and orms to hyperdrive docs
thomasgauvin Apr 30, 2025
d490626
Apply suggestions from code review
Oxyjun May 1, 2025
9297e73
Apply suggestions from code review
Oxyjun May 1, 2025
28676b2
Specifying product when rendering partials
Oxyjun May 1, 2025
721b41e
Importing Render components
Oxyjun May 1, 2025
0410c7b
Fixing invalid links
Oxyjun May 1, 2025
03cb1cc
adjust per discord feedback
thomasgauvin May 2, 2025
249d6d6
more nits
thomasgauvin May 2, 2025
02df4be
Pushing changes to Postgres Drizzle ORM tutorial
Oxyjun May 6, 2025
0517e7b
Editing MySQL version of the tutorial
Oxyjun May 7, 2025
955db1e
Adding note about when to run the optional
Oxyjun May 8, 2025
ed882f4
Removing outdated redirects to avoid breaking
Oxyjun May 8, 2025
f1444e2
Adding missing redirects.
Oxyjun May 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
corrections
  • Loading branch information
thomasgauvin committed Apr 30, 2025
commit d578ae1d1bf08930cd0ea2004147103d4f44d90d

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ sidebar:

import { TabItem, Tabs, Render, WranglerConfig } from "~/components";

Hyperdrive provides additional ways to secure connectivity to your database. Hyperdrive supports:

1. **Server certificates** for TLS (SSL) modes such as `verify-ca` and `verify-full` for increased security. When configured, Hyperdrive will verify that the certificates have been signed by the expected certificate authority (CA) to avoid man-in-the-middle attacks.
2. **Client certificates** for Hyperdrive to authenticate itself to your database with credentials beyond beyond username/password. To properly use client certificates, your database must be configured to verify the client certificates provided by a client, such as Hyperdrive, to allow access to the database.

Hyperdrive can be configured to use only server certificates, only client certificates, or both depending on your security requirements and database configurations.
Hyperdrive provides additional ways to secure connectivity to your database. Hyperdrive supports
verification of server certificates for TLS (SSL) encryption for increased security. Hyperdrive also supports
using client certificates to authenticate itself to your database for stricter authentication beyond username/password.

:::note

Support for server certificates and client certificates is not available for MySQL (beta). Support for server certificates and client certificates is only available for local development using `npx wrangler dev --remote` which runs your Workers and Hyperdrive in Cloudflare's network with local debugging.
Support for server certificates and client certificates is not available for MySQL (beta).

:::

Expand All @@ -28,67 +25,50 @@ Hyperdrive supports 3 common encryption [TLS/SSL modes](https://www.postgresql.o

- `require` (default): TLS is required for encrypted connectivity and server certificates are validated (based on WebPKI).
- `verify-ca`: Hyperdrive will verify that the database server is trustworthy by verifying that the certificates of the server have been signed by the expected root certificate authority or intermediate certificate authority.
- `verify-full`: Identical to `verify-ca`, but Hyperdrive also requires the database hostname to match a Subject Alternative Name (SAN) present on the certificate.
- `verify-full`: Identical to `verify-ca`, but Hyperdrive also requires the database hostname must match a Subject Alternative Name (SAN) present on the certificate.

By default, all Hyperdrive configurations are encrypted with SSL/TLS (`require`). This requires your database to be configured to accept encrypted connections (with SSL/TLS).
By default, all Hyperdrive configurations are encrypted with SSL/TLS (`require`). This requires
that your database is configured to accept encrypted connections (with SSL/TLS).

You can configure Hyperdrive to use `verify-ca` and `verify-full` for a more stringent security configuration, which provide additional verification checks of the server's certificates. This helps guard against man-in-the-middle attacks.
You can configure Hyperdrive to use
`verify-ca` and `verify-full` for a more stringent security configuration, which
provide additional verification checks of the server's certificates. This
helps guard against man-in-the-middle attacks.

To configure Hyperdrive to verify the certificates of the server, you must provide Hyperdrive with the certificate of the root certificate authority (CA) or an intermediate certificate which has been used to sign the certificate of your database.
To configure Hyperdrive to verify the certificates of the server, you must provide Hyperdrive with the certificate of the root certificate authority (CA) or an intermediate certificate which
has been used to sign the certificate of your database.

### Step 1: Upload your the root certificate authority (CA) certificate

Using Wrangler, you can upload your root certificate authority (CA) certificate:

```bash
# requires Wrangler 4.9.0 or greater
npx wrangler cert upload certificate-authority --ca-cert \<ROUTE_TO_CA_PEM_FILE\>.pem --name \<CUSTOM_NAME_FOR_CA_CERT\>

---

Uploading CA Certificate tmp-cert...
Success! Uploaded CA Certificate <CUSTOM_NAME_FOR_CA_CERT>
ID: <YOUR_ID_FOR_THE_CA_CERTIFICATE>
Success! Uploaded CA Certificate \<CUSTOM_NAME_FOR_CA_CERT\>
ID: \<YOUR_ID_FOR_THE_CA_CERTIFICATE\>
...
```

:::note

You must use the CA certificate bundle that is for your specific region. You can not use a CA certificate bundle that contains more than one CA certificate, such as a global bundle of CA certificates containing each region's certificate.

:::

### Step 2: Create your Hyperdrive configuration using the CA certificate and the SSL mode

Once your CA certificate has been created, you can create a Hyperdrive configuration with the newly created certificates using either the dashboard or Wrangler. You must also specify the SSL mode of `verify-ca` or `verify-full` to use.

<Tabs>
Once your CA certificate has been created, you can create a Hyperdrive configuration with the newly created
certificates using either the dashboard or Wrangler. You must also specify the SSL mode of `verify-ca` or `verify-full` to use.

<TabItem label="Wrangler">
Using Wrangler, enter the following command in your terminal:

Using Wrangler, enter the following command in your terminal to create a Hyperdrive configuration with the CA certificate and a `verify-full` SSL mode:
UPDATE WRANGLER

```bash
npx wrangler hyperdrive create <NAME_OF_HYPERDRIVE_CONFIG> --connection-string="postgres://user:password@HOSTNAME_OR_IP_ADDRESS:PORT/database_name" --ca-certificate-id <YOUR_CA_CERT_ID> --sslmode verify-full
npx wrangler hyperdrive create \<NAME_OF_HYPERDRIVE_CONFIG\> --connection-string="postgres://user:password@HOSTNAME_OR_IP_ADDRESS:PORT/database_name" --certificate-authority-id \<YOUR_CA_CERT_ID\>
```
</TabItem>

<TabItem label="Dashboard">

From the dashboard, follow these steps to create a Hyperdrive configuration with server certificates:

1. In the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers/hyperdrive), navigate to **Storage & Databases > Hyperdrive** and click **Create configuration**.
2. Select **Server certificates**.
3. Specify a SSL mode of **Verify CA** or **Verify full**
4. Select the SSL certificate of the certificate authority (CA) of your database that you have previously uploaded with Wrangler.

</TabItem>

</Tabs>



When creating the Hyperdrive configuration, Hyperdrive will attempt to connect to the database with the provided credentials. If the command provides successful results, you have properly configured your Hyperdrive configuration to verify the certificates provided by your database server.
When creating the Hyperdrive configuration, Hyperdrive will attempt to connect to the database with the
provided credentials. If the command provides successful results, you have properly configured your Hyperdrive
configuration to verify the certificates provided by your database server.

:::note

Expand All @@ -98,16 +78,17 @@ Hyperdrive will attempt to connect to your database with the provided credential

## Client certificates

Your database can be configured to [verify a certificate provided by the client](https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-CLIENTCERT), in this case, Hyperdrive. This serves as an additional factor to authenticate clients (in addition to the username and password).
Your database can be configured to [verify a certificate provided by the client](https://www.postgresql.org/docs/current/libpq-ssl.html#LIBPQ-SSL-CLIENTCERT), in this case, Hyperdrive. This serves
as an additional factor to authenticate clients (in addition to the username and password).

For the database server to be able to verify the client certificates, Hyperdrive must be configured to provide a certificate file (`client-cert.pem`) and a private key with which the certificate was generated (`private-key.pem`).
For the database server to be able to verify the client certificates, Hyperdrive must be configured to provide a certificate
file (`client-cert.pem`) and a private key with which the certificate was generated (`private-key.pem`).

### Step 1: Upload your client certificates (mTLS certificates)

Upload your client certificates to be used by Hyperdrive using Wrangler:

```bash
# requires Wrangler 4.9.0 or greater
npx wrangler cert upload mtls-certificate --cert client-cert.pem --key client-key.pem --name <CUSTOM_NAME_FOR_CLIENT_CERTIFICATE>

---
Expand All @@ -121,36 +102,8 @@ ID: <YOUR_ID_FOR_THE_CLIENT_CERTIFICATE_PAIR>
### Step 2: Create a Hyperdrive configuration

You can now create a Hyperdrive configuration using the newly created client certificate bundle using the dashboard or Wrangler.


<Tabs>

<TabItem label="Wrangler">

Using Wrangler, enter the following command in your terminal to create a Hyperdrive configuration with using the client certificate pair:
Using Wrangler, run the following command:

```bash
npx wrangler hyperdrive create <NAME_OF_HYPERDRIVE_CONFIG> --connection-string="postgres://user:password@HOSTNAME_OR_IP_ADDRESS:PORT/database_name" --mtls-certificate-id <YOUR_CLIENT_CERT_PAIR_ID>
npx wrangler hyperdrive create <NAME_OF_HYPERDRIVE_CONFIG> --connection-string="postgres://user:password@HOSTNAME_OR_IP_ADDRESS:PORT/database_name" --certificate-authority-id <YOUR_CA_CERT_ID> --mtls-certificate-uuid <YOUR_CLIENT_CERT_PAIR_ID>
```
</TabItem>

<TabItem label="Dashboard">

From the dashboard, follow these steps to create a Hyperdrive configuration with server certificates:

1. In the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers/hyperdrive), navigate to **Storage & Databases > Hyperdrive** and click **Create configuration**.
2. Select **Client certificates**.
3. Select the SSL client certificate and private key pair for Hyperdrive to use during the connection setup with your database server.

</TabItem>

</Tabs>


When Hyperdrive connects to your database, it will provide a client certificate signed with the private key to the database server. This allows the database server to confirm that the client, in this case Hyperdrive, has both the private key and the client certificate. By using client certificates, you can add an additional authentication layer for your database to ensures that only Hyperdrive can connect to it.

:::note

Hyperdrive will attempt to connect to your database with the provided credentials to verify they are correct before creating a configuration. If you encounter an error when attempting to connect, refer to Hyperdrive's [troubleshooting documentation](/hyperdrive/observability/troubleshooting/) to debug possible causes.

:::
Loading