Securing Azure Functions
This lesson explains access keys, authentication, and network options on each hosting plan.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the types of access key.
- Explain why keys are weak authentication.
- Choose a hosting plan for a network requirement.
- Describe identity-based connections.
What is shared with App Service
Azure Functions runs on the same platform as App Service, so transport settings, Easy Auth, access restrictions, managed identities and Key Vault references all work in the same way, and the guidance in the previous lesson applies. By default, clients can use HTTP or HTTPS, so require HTTPS and the latest TLS version. Disable FTP and remote debugging, and avoid wildcards in cross-origin resource sharing (CORS) settings.
Access keys
HTTP-triggered functions have an authorization level. Unless a function is set to anonymous, a request must include an access key. The following table describes the levels and keys.
| Key | Scope | Use |
|---|---|---|
| Function key | One function | Lets a caller invoke that function |
| Host key | All functions in the app | A wider key, for a trusted caller |
| Master key | The whole app, and the admin endpoints | Administrative use only, and it should never be given to clients |
| System key | A specific extension | Used by extensions, such as webhooks |
An access key is a shared secret, not an identity. Keys can be leaked, they do not show who called, and they do not expire by default. Microsoft's guidance is to avoid relying on them to protect production functions, and to use Easy Auth or API Management instead. The admin endpoints at /admin need the master key, and setting functionsRuntimeAdminIsolationEnabled to true disables them.
Function keys
Authentication options
For real caller identity, enable Easy Auth with Microsoft Entra ID, so that callers need a valid token. Another approach places Azure API Management in front of the function, where validate-azure-ad-token and rate limits apply, and the function accepts traffic only from API Management.
For outgoing connections, identity-based connections let a function reach Azure Storage, Service Bus and other services with a managed identity, instead of connection strings. This covers the storage account that the function host uses, which is often a forgotten secret in the setting AzureWebJobsStorage.
Functions authentication
Network access
Network capabilities depend on the hosting plan. Access restrictions work on all plans, with allow and deny rules in priority order, and with no rules, the app accepts traffic from any address. Inbound private endpoints are available on the Flex Consumption, Elastic Premium and Dedicated plans.
| Plan | Access restrictions | Private endpoints | Virtual network integration |
|---|---|---|---|
| Flex Consumption | Yes | Yes | Yes |
| Elastic Premium | Yes | Yes | Yes |
| Dedicated (App Service) | Yes | Yes | Yes |
| Windows Consumption | Yes | No | No |
Flex Consumption is the recommended serverless plan, and the older Linux Consumption plan retires on 30 September 2028. A scenario that needs a function to reach a private database on a serverless plan therefore points to Flex Consumption. If the storage account behind a function app is itself private, the app needs virtual network integration and private endpoints on that account.
Functions networking
Other safeguards
A function that an attacker can call repeatedly may cost money, so a Consumption function can use a daily GB-seconds quota, and API Management can throttle calls. Monitor with Application Insights, and be careful not to log secrets. Defender for App Service covers the platform. Review function code and dependencies, since the most serious flaw in a function is often its own code, such as injection from an unvalidated trigger. A queue message is input too, and it needs validation as much as an HTTP request.
Replacing a shared key
A partner calls an HTTP function with a function key that has been shared by email. The company wants each caller identified, wants to limit each partner to 100 calls a minute, and wants the function to accept traffic only from approved routes. What should you recommend?
Place Azure API Management in front. Use validate-azure-ad-token or subscriptions to identify callers, and rate-limit-by-key to throttle them. Add an access restriction or private endpoint on the function so that it accepts traffic only from API Management, and rotate the exposed key.
A host key is wider than a function key and has the same weakness. Easy Auth alone gives identity, but it provides no per-caller rate limiting. A longer key would change nothing about identity.
Why should the master key never be given to a client?
Show answer
It reaches the whole app and its admin endpoints, far beyond invoking one function.
Exam Tips
Remember for the exam
- Access keys identify an application weakly, so they are not real authentication.
- The master key must never be given to clients.
- Private endpoints need Flex Consumption, Elastic Premium or Dedicated plans.
- Use identity-based connections for AzureWebJobsStorage too.