Skip to content

Commit 02ea098

Browse files
Add api, commands, and binding support for mTLS certificates (cloudflare#2567)
* Add mtls-certificate api Mostly simple proxies to the SSL mTLS endpoints Adds a new OAuth scope to allow this * Add mtls-certificate commands * Support bindings of type mtls_certificate * Add tests * Add changeset
1 parent 4328e9f commit 02ea098

File tree

20 files changed

+1112
-3
lines changed

20 files changed

+1112
-3
lines changed

.changeset/clean-jokes-tan.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Add mtls-certificate commands and binding support
6+
7+
Functionality implemented first as an api, which is used in the cli standard
8+
api commands
9+
10+
Note that this adds a new OAuth scope, so OAuth users will need to log out and
11+
log back in to use the new 'mtls-certificate' commands
12+
However, publishing with mtls-certifcate bindings (bindings of type
13+
'mtls_certificate') will work without the scope.

packages/wrangler/src/__tests__/configuration.test.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe("normalizeAndValidateConfig()", () => {
6868
bindings: [],
6969
},
7070
dispatch_namespaces: [],
71+
mtls_certificates: [],
7172
usage_model: undefined,
7273
vars: {},
7374
define: {},
@@ -2190,6 +2191,75 @@ describe("normalizeAndValidateConfig()", () => {
21902191
});
21912192
});
21922193

2194+
describe("[mtls_certificates]", () => {
2195+
it("should error if mtls_certificates is not an array", () => {
2196+
const { diagnostics } = normalizeAndValidateConfig(
2197+
{
2198+
mtls_certificates: "just a string",
2199+
} as unknown as RawConfig,
2200+
undefined,
2201+
{ env: undefined }
2202+
);
2203+
2204+
expect(diagnostics.hasWarnings()).toBe(false);
2205+
expect(diagnostics.hasErrors()).toBe(true);
2206+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2207+
"Processing wrangler configuration:
2208+
- The field \\"mtls_certificates\\" should be an array but got \\"just a string\\"."
2209+
`);
2210+
});
2211+
2212+
it("should error on non valid mtls_certificates", () => {
2213+
const { diagnostics } = normalizeAndValidateConfig(
2214+
{
2215+
mtls_certificates: [
2216+
"a string",
2217+
123,
2218+
false,
2219+
{
2220+
binding: 123,
2221+
namespace: 123,
2222+
},
2223+
{
2224+
binding: "CERT_ONE",
2225+
id: "1234",
2226+
},
2227+
{
2228+
binding: "CERT_TWO",
2229+
certificate_id: 1234,
2230+
},
2231+
// this one is valid
2232+
{
2233+
binding: "CERT_THREE",
2234+
certificate_id: "1234",
2235+
},
2236+
{
2237+
binding: true,
2238+
service: "1234",
2239+
},
2240+
],
2241+
} as unknown as RawConfig,
2242+
undefined,
2243+
{ env: undefined }
2244+
);
2245+
2246+
expect(diagnostics.hasWarnings()).toBe(false);
2247+
expect(diagnostics.hasErrors()).toBe(true);
2248+
expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2249+
"Processing wrangler configuration:
2250+
- \\"mtls_certificates\\" bindings should be objects, but got \\"a string\\"
2251+
- \\"mtls_certificates\\" bindings should be objects, but got 123
2252+
- \\"mtls_certificates\\" bindings should be objects, but got false
2253+
- \\"mtls_certificates[3]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"namespace\\":123}.
2254+
- \\"mtls_certificates[3]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":123,\\"namespace\\":123}.
2255+
- \\"mtls_certificates[4]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":\\"CERT_ONE\\",\\"id\\":\\"1234\\"}.
2256+
- \\"mtls_certificates[5]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":\\"CERT_TWO\\",\\"certificate_id\\":1234}.
2257+
- \\"mtls_certificates[7]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":true,\\"service\\":\\"1234\\"}.
2258+
- \\"mtls_certificates[7]\\" bindings should have a string \\"certificate_id\\" field but got {\\"binding\\":true,\\"service\\":\\"1234\\"}."
2259+
`);
2260+
});
2261+
});
2262+
21932263
describe("[unsafe.bindings]", () => {
21942264
it("should error if unsafe is an array", () => {
21952265
const { diagnostics } = normalizeAndValidateConfig(

packages/wrangler/src/__tests__/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe("wrangler", () => {
5050
wrangler dispatch-namespace 📦 Interact with a dispatch namespace
5151
wrangler d1 🗄 Interact with a D1 database
5252
wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
53+
wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
5354
wrangler login 🔓 Login to Cloudflare
5455
wrangler logout 🚪 Logout from Cloudflare
5556
wrangler whoami 🕵️ Retrieve your user info and test your auth config
@@ -99,6 +100,7 @@ describe("wrangler", () => {
99100
wrangler dispatch-namespace 📦 Interact with a dispatch namespace
100101
wrangler d1 🗄 Interact with a D1 database
101102
wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
103+
wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
102104
wrangler login 🔓 Login to Cloudflare
103105
wrangler logout 🚪 Logout from Cloudflare
104106
wrangler whoami 🕵️ Retrieve your user info and test your auth config

0 commit comments

Comments
 (0)