Secure the function at several layers: who can call it, how it accesses other resources, and how it handles data. 1. Authentication for HTTP triggers - Function keys (AuthorizationLevel.Function or Admin) are simple shared secrets — acceptable for internal webhooks, but not for user authentication. Keep keys in Key Vault and rotate them. - Prefer real identity: enable App Service Authentication ("Easy Auth") with Microsoft Entra ID, or validate JWT bearer tokens in code (Microsoft.Identity.Web in the isolated worker), and check roles or scopes for authorization. - Put Azure API Management in front for token validation (validate-jwt), rate limiting, IP filtering and a single public entry point. 2. Network security - Restrict inbound access with access restrictions (IP rules, service tags), or private endpoints so the function is reachable only inside a VNet (Premium, Flex Consumption or Dedicated plans). - Use VNet integration for outbound calls to private resources (SQL, Storage, Key Vault via private endpoints). - HTTPS only, minimum TLS 1.2, and FTP disabled. 3. Identity for outbound access - Enable a managed identity and use DefaultAzureCredential to access Key Vault, Storage, Service Bus, Cosmos DB and SQL — no connection strings with secrets. - Use identity-based connections for triggers and bindings (for example ServiceBusConnection__fullyQualifiedNamespace). - Grant least-privilege RBAC roles. 4. Secrets and configuration - Store remaining secrets in Key Vault with Key Vault references in app settings. 5. Code-level security - Validate and sanitise input, use parameterised queries, limit request sizes, and never log secrets or personal data. - Keep dependencies updated and scan them for vulnerabilities. 6. Monitoring and governance - Application Insights and Azure Monitor alerts for failures and unusual traffic; Microsoft Defender for Cloud recommendations; Azure Policy to enforce HTTPS-only and managed identity across function apps. Example answer: "Our HTTP functions sat behind API Management, which validated Entra ID tokens; the function also validated the audience and roles. It used a managed identity for Service Bus and Key Vault, was reachable only from APIM through access restrictions, and all secrets were in Key Vault."
Ravindra Wadile · · 0 likes