Skip to content

Serve the Azure Functions host over HTTPS in the Functions sample#1691

Open
IEvangelist wants to merge 2 commits into
mainfrom
ievangelist/azure-functions-https
Open

Serve the Azure Functions host over HTTPS in the Functions sample#1691
IEvangelist wants to merge 2 commits into
mainfrom
ievangelist/azure-functions-https

Conversation

@IEvangelist

Copy link
Copy Markdown
Member

Fixes #752

Problem

In the aspire-with-azure-functions sample, the local Azure Functions host (func host start) was only ever served over HTTP. Simply adding --useHttps to the Functions launch profile is not enough — the .NET build of Azure Functions Core Tools cannot auto‑generate a certificate and fails to start:

Auto cert generation is currently not working on the .NET Core build.

func host start --useHttps requires an explicit password‑protected PFX via --cert/--password.

Fix

  • ImageGallery.Functions/Properties/launchSettings.json — add --useHttps so Aspire registers an https endpoint for the Functions resource.
  • ImageGallery.AppHost/AppHost.cs
    • Point WithUrlForEndpoint at the https endpoint.
    • In run mode only, export the trusted ASP.NET Core developer certificate via Aspire's WithHttpsDeveloperCertificate(...) and hand the resulting PFX to the Functions host with WithHttpsCertificateConfiguration(...) (--cert <pfx> --password <generated>). The export password is an ephemeral, per‑run secret parameter, so nothing is committed. The wiring is guarded by IsRunMode so it never affects publish/deploy.

Effective local launch becomes:

func host start --port 7221 --useHttps --cert <exported-dev-cert>.pfx --password <generated>

Verification (local)

Tested locally with .NET 10, Aspire 13.4.3, Azure Functions Core Tools v4.12.0, Docker (Azurite):

Beforecurl http://localhost:7221/admin/host/status200; HTTPS TLS handshake fails (SEC_E_INVALID_TOKEN).

After

  • func launches with --useHttps --cert <pfx> --password <generated> and listens on :7221.
  • curl https://localhost:7221/admin/host/status (no -k) → 200 OK with {"state":"Running","version":"4.1048..."} — i.e. served over HTTPS using the trusted dev cert.
  • Plain http://localhost:7221/... now fails (port is HTTPS‑only).
  • Frontend serves over HTTPS (200).
  • End‑to‑end regression check: uploaded a 400×300 image to the images container → the ThumbnailGenerator blob trigger produced a 170×128 thumbnail in thumbnails. The pipeline is unaffected.

Prerequisite

A trusted ASP.NET Core developer certificate (dotnet dev-certs https --trust) — already part of the Aspire prerequisites linked in the sample README.

Copilot AI review requested due to automatic review settings June 9, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the aspire-with-azure-functions sample so the local Azure Functions host can be served over HTTPS, aligning the Functions endpoint with the frontend’s HTTPS usage and avoiding Core Tools’ inability to auto-generate a cert on the .NET build.

Changes:

  • Add --useHttps to the Functions project launch profile so Aspire registers an https endpoint.
  • Update the AppHost to display the Functions URL via the https endpoint and (in run mode) export the trusted dev cert and pass it to func host start via --cert/--password.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
samples/aspire-with-azure-functions/ImageGallery.Functions/Properties/launchSettings.json Adds --useHttps to ensure the local Functions host is started in HTTPS mode.
samples/aspire-with-azure-functions/ImageGallery.AppHost/AppHost.cs Switches the displayed Functions endpoint to https and wires dev-cert export + func args in run mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread samples/aspire-with-azure-functions/ImageGallery.AppHost/AppHost.cs
@IEvangelist
IEvangelist requested a review from DamianEdwards June 9, 2026 16:09
@IEvangelist
IEvangelist enabled auto-merge (squash) June 9, 2026 19:05
Comment on lines +49 to +50
var functionsCertPassword = builder.AddParameter(
"functions-cert-password", () => Guid.NewGuid().ToString("N"), secret: true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this is only done in run mode, is there any benefit to this being a parameter? Is it just so we can mark it a secret so it gets hidden in the dashboard UI? Parameters show up in the UI and add code here so just want to make sure there's a reasonable benefit.

nit: wrapping

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why use a guid when parameters already handle password generation

Use Aspire's generated parameter support for the local Functions HTTPS certificate password and keep the experimental certificate API warning suppression scoped to the run-mode certificate configuration.

Fixes #752

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@IEvangelist
IEvangelist force-pushed the ievangelist/azure-functions-https branch from 032cc42 to 3a67060 Compare July 9, 2026 11:36
Add explicit Microsoft.OpenApi references where restore resolved a vulnerable transitive version and update file-based AppHost Aspire package directives to 13.4.6 to avoid vulnerable MessagePack transitive dependencies.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure HTTPS works in the Azure Functions sample

4 participants