cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.75k stars 735 forks source link

🐛 BUG: MTLS Certificate fetch doesn't work #6067

Open BernardoSM opened 5 months ago

BernardoSM commented 5 months ago

Which Cloudflare product(s) does this pertain to?

Workers Runtime, Wrangler core

What version(s) of the tool(s) are you using?

^3.47.0 [Wrangler]

What version of Node are you using?

20.9.0

What operating system and version are you using?

Macos 15 (Beta)

Describe the Bug

Hi everyone, why I can't use mtls_certificates binding without --remote?

I created a brand new cf worker project with the following tutorial: https://developers.cloudflare.com/workers/get-started/guide/#1-create-a-new-worker-project I added the mtls certificate like the following tutorial: https://developers.cloudflare.com/workers/runtime-apis/bindings/mtls/#client-authentication-with-mtls

When I run the command wrangler dev the binding environment.MY_CERT is undefined.

But when I run the command with remote like wrangler dev --remote the binding starts to work.

Observed behavior

Is not possible to use mTLS binding fetch with no --remote command. This mean the binding is undefined after you register it correctly and try to use.

Expected behavior

The binding should work even if you don't use --remote command.

Steps to reproduce

  1. Create a brand new cf worker project with the following tutorial: https://developers.cloudflare.com/workers/get-started/guide/#1-create-a-new-worker-project
  2. Add the mtls certificate like the following tutorial: https://developers.cloudflare.com/workers/runtime-apis/bindings/mtls/#client-authentication-with-mtls
  3. Update src/index.js file with the following code
    export default {
    async fetch(request, env, ctx): Promise<Response> {
        console.log(env.MY_CERT)
        return new Response('Hello World!');
    },
    }
  4. Run the command wrangler dev and you'll see env.MY_CERT is undefined
  5. If you run the command wrangler dev --remote you'll see env.MY_CERT is not undefined and more and fetch calls will start to work

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

threepointone commented 5 months ago

Unfortunately we don't support mTLS bindings in local dev yet (https://developers.cloudflare.com/workers/testing/local-development/#supported-resource-bindings-in-different-environments) We should have better warnings/errors when this happens, sorry for the trouble.

malipetek commented 2 months ago

In my case also deployed fetch seems like not working and I have no idea how to debug this.