The Simplest Way to Make Azure Functions and Azure VMs Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams use azure functions and azure vms together to run event tasks and heavy workloads. Functions catch triggers fast, while virtual machines handle long jobs or custom apps. This pair gives your team a great mix of speed and control. Small code runs on demand, and big servers stay ready for deep work. When you set them up right, they pass data and commands without risk. How identity and data flow between azure functions and azure vms First, the function needs a safe way to talk to the virt

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Teams use azure functions and azure vms together to run event tasks and heavy workloads. Functions catch triggers fast, while virtual machines handle long jobs or custom apps.

This pair gives your team a great mix of speed and control. Small code runs on demand, and big servers stay ready for deep work. When you set them up right, they pass data and commands without risk.

How identity and data flow between azure functions and azure vms

First, the function needs a safe way to talk to the virtual machine. You should not store static keys or plain passwords inside your function code. Instead, you can turn on a managed identity for the function app. Azure Active Directory then checks this identity before the function touches the server.

Once the identity check passes, the function can start or stop the server. It can also send scripts to run inside the guest operating system. For app traffic, both tools should sit inside the same virtual network. The function joins a subnet and sends requests to the private IP address. Network security groups sit on the subnet and check every packet first. You can set a rule that only lets the function subnet talk through. This keeps all traffic off the public web and stops outside probes.

Common failure modes and how to scope roles and network paths

Many teams make mistakes when they first link these two cloud tools. A common error is giving the function a broad owner role across everything. If an attacker compromises that function, they can delete or change every server. Another bad habit is using one shared admin account for all remote tasks. Shared accounts make it impossible to see which specific function ran a command.

Teams also run into trouble when they leave server ports open to all. If a function talks to a server over the public web, risk grows. Unlogged commands and queries also hide errors until an outage hits your app. You can fix these issues by setting strict boundaries on roles and networks.

Azure RBAC + Cloud Functions IAM: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Start by scoping the function role to one single virtual machine resource. Give the function only the exact action it needs, such as starting servers. Next, lock down the network path with private endpoints or subnet links. Drop all inbound traffic that does not come from the exact function subnet. Finally, turn on central logs for both the function and the virtual machine. Make sure every script run and data query writes a clear audit record.

Keeping remote scripts and database calls safe on servers

Sometimes a function needs to query a database hosted on a virtual machine. Or it might need to run a shell script to clean up files. In both cases, you must protect any sensitive data that comes back. If a query returns customer emails or phone numbers, masking rewrites matched fields in results. The same rule applies to card numbers and national IDs in your tables.

Keep your scripts small and store them in a safe central place. Do not let a function pass raw user input straight into a server shell. Check every input value inside the function before it sends the network call. Good checks and tight network rules keep your servers safe every day.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

How can an Azure Function run a script on an Azure VM?

You can use the native run command feature through the cloud management API. Give the function a managed identity with permission to run commands on that server.

Do Azure Functions need a public IP to reach an Azure VM?

No, you can link the function app to the virtual network. The function then sends traffic to the private IP address of the server.

How do we stop functions from having too much server access?

Assign a custom role to the function identity at the single server level. Only include the exact permissions needed for that single job, and nothing more.

The query runs. The emails stay hidden.