From 99790647876be103bccfc68d5e1451a46c95f30e Mon Sep 17 00:00:00 2001 From: Thomas Gauvin Date: Thu, 10 Oct 2024 16:04:27 +0100 Subject: [PATCH 01/10] thomasgauvin: add credential rotation methods to hyperdrive --- .../connect-to-private-database copy.mdx | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/content/docs/hyperdrive/configuration/connect-to-private-database copy.mdx diff --git a/src/content/docs/hyperdrive/configuration/connect-to-private-database copy.mdx b/src/content/docs/hyperdrive/configuration/connect-to-private-database copy.mdx new file mode 100644 index 000000000000000..d8ac01536fc5ea1 --- /dev/null +++ b/src/content/docs/hyperdrive/configuration/connect-to-private-database copy.mdx @@ -0,0 +1,44 @@ +--- +pcx_content_type: concept +title: Rotating database credentials +sidebar: + order: 8 +--- + +import { TabItem, Tabs, Render } from "~/components"; + +You can change the connection information and the connection credentials of your Hyperdrive configuration in one of two ways: + +1. (Recommended) Create a new Hyperdrive configuration with the new connection information and credentials, and update your Worker to use the new Hyperdrive configuration. +2. Update the existing Hyperdrive configuration with the new connection information and credentials. + +## Use a new Hyperdrive configuration + +Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Worker configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration and easily roll back to the previous configuration if needed. To create a Hyperdrive that connects to an existing PostgreSQL database, use the [wrangler](/workers/wrangler/install-and-update/) CLI or the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers-and-pages/hyperdrive). + +```sh +# wrangler v3.11 and above required +npx wrangler hyperdrive create my-updated-hyperdrive --connection-string="" +``` + +The command above will output the ID of your Hyperdrive. Set this ID in the `wrangler.toml` configuration file for your Workers project: + +```toml +# required for database drivers to function +compatibility_flags = [ "nodejs_compat_v2" ] + +[[hyperdrive]] +binding = "HYPERDRIVE" +id = "" +``` + +To update your Worker to use the new Hyperdrive configuration, redeploy your Worker or use [gradual deployments](https://developers.cloudflare.com/workers/configuration/versions-and-deployments/gradual-deployments/). + +## Update the existing Hyperdrive configuration + +You can update the configuration of an existing Hyperdrive configuration using the [wrangler CLI](/workers/wrangler/install-and-update/). + +```sh +# wrangler v3.11 and above required +npx wrangler hyperdrive update --origin-host --origin-password --origin-user --database --origin-port +``` From 94d16dbf2b71075850ccf45233896a0a889e1cdd Mon Sep 17 00:00:00 2001 From: Thomas Gauvin Date: Thu, 10 Oct 2024 16:10:54 +0100 Subject: [PATCH 02/10] thomasgauvin:rename file and add note to update in situ --- ...vate-database copy.mdx => rotate-credentials.mdx} | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) rename src/content/docs/hyperdrive/configuration/{connect-to-private-database copy.mdx => rotate-credentials.mdx} (72%) diff --git a/src/content/docs/hyperdrive/configuration/connect-to-private-database copy.mdx b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx similarity index 72% rename from src/content/docs/hyperdrive/configuration/connect-to-private-database copy.mdx rename to src/content/docs/hyperdrive/configuration/rotate-credentials.mdx index d8ac01536fc5ea1..81d917e89f69e15 100644 --- a/src/content/docs/hyperdrive/configuration/connect-to-private-database copy.mdx +++ b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx @@ -12,9 +12,11 @@ You can change the connection information and the connection credentials of your 1. (Recommended) Create a new Hyperdrive configuration with the new connection information and credentials, and update your Worker to use the new Hyperdrive configuration. 2. Update the existing Hyperdrive configuration with the new connection information and credentials. -## Use a new Hyperdrive configuration +## Use a new Hyperdrive configuration (Recommended) -Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Worker configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration and easily roll back to the previous configuration if needed. To create a Hyperdrive that connects to an existing PostgreSQL database, use the [wrangler](/workers/wrangler/install-and-update/) CLI or the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers-and-pages/hyperdrive). +Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Worker configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration and easily roll back to the previous configuration if needed. + +To create a Hyperdrive that connects to an existing PostgreSQL database, use the [wrangler](/workers/wrangler/install-and-update/) CLI or the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers-and-pages/hyperdrive). ```sh # wrangler v3.11 and above required @@ -32,7 +34,7 @@ binding = "HYPERDRIVE" id = "" ``` -To update your Worker to use the new Hyperdrive configuration, redeploy your Worker or use [gradual deployments](https://developers.cloudflare.com/workers/configuration/versions-and-deployments/gradual-deployments/). +To update your Worker to use the new Hyperdrive configuration, redeploy your Worker or use [gradual deployments](/workers/configuration/versions-and-deployments/gradual-deployments/). ## Update the existing Hyperdrive configuration @@ -42,3 +44,7 @@ You can update the configuration of an existing Hyperdrive configuration using t # wrangler v3.11 and above required npx wrangler hyperdrive update --origin-host --origin-password --origin-user --database --origin-port ``` + +:::note +Updating the settings of an existing Hyperdrive configuration does not purge Hyperdrive's cache and does not tear down the existing database connection pool. New connections will be established using the new connection information. +::: From b1a1bcec1beffa934a073d052833f403e2939751 Mon Sep 17 00:00:00 2001 From: Jun Lee Date: Thu, 10 Oct 2024 16:15:29 +0100 Subject: [PATCH 03/10] Apply suggestions from code review --- .../docs/hyperdrive/configuration/rotate-credentials.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx index 81d917e89f69e15..7c2feae21b7d9a5 100644 --- a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx +++ b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx @@ -14,9 +14,9 @@ You can change the connection information and the connection credentials of your ## Use a new Hyperdrive configuration (Recommended) -Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Worker configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration and easily roll back to the previous configuration if needed. +Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Worker configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration, and easily roll back to the previous configuration if needed. -To create a Hyperdrive that connects to an existing PostgreSQL database, use the [wrangler](/workers/wrangler/install-and-update/) CLI or the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers-and-pages/hyperdrive). +To create a Hyperdrive that connects to an existing PostgreSQL database, use the [Wrangler](/workers/wrangler/install-and-update/) CLI or the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers-and-pages/hyperdrive). ```sh # wrangler v3.11 and above required From e698d2f1b6b2ae6ef57beab6cc1bec4c6e2932ad Mon Sep 17 00:00:00 2001 From: Thomas Gauvin <35609369+thomasgauvin@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:41:49 +0100 Subject: [PATCH 04/10] Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx --- .../docs/hyperdrive/configuration/rotate-credentials.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx index 7c2feae21b7d9a5..69ec5431d912616 100644 --- a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx +++ b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx @@ -7,7 +7,7 @@ sidebar: import { TabItem, Tabs, Render } from "~/components"; -You can change the connection information and the connection credentials of your Hyperdrive configuration in one of two ways: +You can change the connection information and credentials of your Hyperdrive configuration in one of two ways: 1. (Recommended) Create a new Hyperdrive configuration with the new connection information and credentials, and update your Worker to use the new Hyperdrive configuration. 2. Update the existing Hyperdrive configuration with the new connection information and credentials. From c707605d5c657fe4ee4e53a2b6b34239b2d0bf71 Mon Sep 17 00:00:00 2001 From: Thomas Gauvin <35609369+thomasgauvin@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:42:09 +0100 Subject: [PATCH 05/10] Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx --- .../docs/hyperdrive/configuration/rotate-credentials.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx index 69ec5431d912616..62c21ebbbe8519f 100644 --- a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx +++ b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx @@ -9,7 +9,7 @@ import { TabItem, Tabs, Render } from "~/components"; You can change the connection information and credentials of your Hyperdrive configuration in one of two ways: -1. (Recommended) Create a new Hyperdrive configuration with the new connection information and credentials, and update your Worker to use the new Hyperdrive configuration. +1. Create a new Hyperdrive configuration with the new connection information and credentials, and update your Worker to use the new Hyperdrive configuration (Recommended). 2. Update the existing Hyperdrive configuration with the new connection information and credentials. ## Use a new Hyperdrive configuration (Recommended) From 14eef0a9e7af385bf0761b1ff1a8d447fd9a5362 Mon Sep 17 00:00:00 2001 From: Thomas Gauvin <35609369+thomasgauvin@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:42:30 +0100 Subject: [PATCH 06/10] Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx --- .../docs/hyperdrive/configuration/rotate-credentials.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx index 62c21ebbbe8519f..ee8b3554b9f071d 100644 --- a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx +++ b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx @@ -9,7 +9,7 @@ import { TabItem, Tabs, Render } from "~/components"; You can change the connection information and credentials of your Hyperdrive configuration in one of two ways: -1. Create a new Hyperdrive configuration with the new connection information and credentials, and update your Worker to use the new Hyperdrive configuration (Recommended). +1. Create a new Hyperdrive configuration with the new connection information, and update your Worker to use the new Hyperdrive configuration (Recommended). 2. Update the existing Hyperdrive configuration with the new connection information and credentials. ## Use a new Hyperdrive configuration (Recommended) From dd9b0be84c2f842fa2610a8d1f8a001a03cf0f4f Mon Sep 17 00:00:00 2001 From: Thomas Gauvin <35609369+thomasgauvin@users.noreply.github.com> Date: Thu, 10 Oct 2024 16:43:42 +0100 Subject: [PATCH 07/10] Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx --- .../docs/hyperdrive/configuration/rotate-credentials.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx index ee8b3554b9f071d..8709c8141581061 100644 --- a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx +++ b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx @@ -27,7 +27,8 @@ The command above will output the ID of your Hyperdrive. Set this ID in the `wra ```toml # required for database drivers to function -compatibility_flags = [ "nodejs_compat_v2" ] +compatibility_flags = [ "nodejs_compat" ] +compatibility_date = "2024-09-23" [[hyperdrive]] binding = "HYPERDRIVE" From 9d357c9a7815824ac6e4b3a3495d8b8acea5bccf Mon Sep 17 00:00:00 2001 From: Thomas Gauvin <35609369+thomasgauvin@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:59:55 +0100 Subject: [PATCH 08/10] Apply suggestions from code review --- .../docs/hyperdrive/configuration/rotate-credentials.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx index 8709c8141581061..32fe9482ce495a6 100644 --- a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx +++ b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx @@ -9,10 +9,10 @@ import { TabItem, Tabs, Render } from "~/components"; You can change the connection information and credentials of your Hyperdrive configuration in one of two ways: -1. Create a new Hyperdrive configuration with the new connection information, and update your Worker to use the new Hyperdrive configuration (Recommended). +1. Create a new Hyperdrive configuration with the new connection information, and update your Worker to use the new Hyperdrive configuration. 2. Update the existing Hyperdrive configuration with the new connection information and credentials. -## Use a new Hyperdrive configuration (Recommended) +## Use a new Hyperdrive configuration Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Worker configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration, and easily roll back to the previous configuration if needed. From f16d57239105662b64dafee534e1755424e44446 Mon Sep 17 00:00:00 2001 From: Thomas Gauvin <35609369+thomasgauvin@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:34:37 +0100 Subject: [PATCH 09/10] Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx --- .../docs/hyperdrive/configuration/rotate-credentials.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx index 32fe9482ce495a6..7c4c4b8888c2b4f 100644 --- a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx +++ b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx @@ -14,7 +14,7 @@ You can change the connection information and credentials of your Hyperdrive con ## Use a new Hyperdrive configuration -Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Worker configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration, and easily roll back to the previous configuration if needed. +Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Hyperdrive configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration, and easily roll back to the previous configuration if needed. To create a Hyperdrive that connects to an existing PostgreSQL database, use the [Wrangler](/workers/wrangler/install-and-update/) CLI or the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers-and-pages/hyperdrive). From b8489fdf18d8164116201a6323d6ceb1a21a7eff Mon Sep 17 00:00:00 2001 From: Thomas Gauvin <35609369+thomasgauvin@users.noreply.github.com> Date: Fri, 11 Oct 2024 13:35:04 +0100 Subject: [PATCH 10/10] Update src/content/docs/hyperdrive/configuration/rotate-credentials.mdx --- .../docs/hyperdrive/configuration/rotate-credentials.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx index 7c4c4b8888c2b4f..5caec35e1d1ca4d 100644 --- a/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx +++ b/src/content/docs/hyperdrive/configuration/rotate-credentials.mdx @@ -16,7 +16,7 @@ You can change the connection information and credentials of your Hyperdrive con Creating a new Hyperdrive configuration to update your database credentials allows you to keep your existing Hyperdrive configuration unchanged, gradually migrate your Worker to the new Hyperdrive configuration, and easily roll back to the previous configuration if needed. -To create a Hyperdrive that connects to an existing PostgreSQL database, use the [Wrangler](/workers/wrangler/install-and-update/) CLI or the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers-and-pages/hyperdrive). +To create a Hyperdrive configuration that connects to an existing PostgreSQL database, use the [Wrangler](/workers/wrangler/install-and-update/) CLI or the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers-and-pages/hyperdrive). ```sh # wrangler v3.11 and above required