Need help setting up Tesla fleet through cloudflare tunnel

I am trying to setup Tesla fleet on my home assistant but I’ve been accessing my home assistant through a cloudflare tunnel.

On all the guides I’ve seen they say to use an Nginx proxy server to have the public key accessible to the outside.

Since I am using a cloudflare tunnel I don’t think I need to use an ngnix proxy server but don’t know how to setup my cloudflare to allow the public key to be accessible.

Any guide or help would be greatly appreciated

1 Like

Hi,
I have the same question, did you allready found the solution?

If you also have your domain/dns on cloudflare you might not need to host the file on your system but can serve it from cloudflare directly.

I managed to get it working by adding a worker with default template and then edit the code to the following:

const TESLA_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
your key
-----END PUBLIC KEY-----
`;
  
export default {
  async fetch(request) {
    const url = new URL(request.url);
    if (url.pathname === "/.well-known/appspecific/com.tesla.3p.public-key.pem") {
      return new Response(TESLA_PUBLIC_KEY, {
        headers: {
          "Content-Type": "application/x-pem-file",
          "Cache-Control": "public, max-age=86400"
        }
      });
    }

    // fallback
    
    return new Response("Not found", { status: 404 });
  }
};

then add a route in the worker to YOURDOMAIN.com/.well-known/appspecific/* (start with the domain itself, don’t add https://)

Thanks! I also have found this out in the mean time.
Took me a while to also found out that I had some rules on Cloudflare that prevented access from the Tesla servers, but now it works.

Also for others: I have this worker linked to a subdomain, so subdomain.YOURDOMAIN.com/.well-known/appspecific/
As the script returns “Not found” for any other path, I think this may block all regular access to your domain if you install it at the main domain level (?).