Sub topic 12
Network ports, the service account, and security considerations
This chapter explains what network access a gateway needs, which Windows account it runs under, and how credentials and data are protected. It assumes you can install a gateway and map a data source to a dataset, as covered in the earlier chapters. It also assumes you know what a firewall rule, an outbound port, and a Windows service are.
The gateway only makes outbound connections
The on-premises data gateway never listens for connections from the internet. It opens outbound connections to Azure Relay (built on Azure Service Bus) and holds them open. When the Power BI service needs to refresh a dataset, it puts a request on the relay. The gateway picks up the request, queries the data source on the local network, and sends the result back over the same outbound channel.
This has two practical consequences:
- You do not open inbound ports or publish the gateway machine to the internet.
- Your firewall work is an outbound allow-list. If refresh fails with a connectivity error, the cause is usually an outbound rule or a proxy.
Ports and destinations
The gateway uses these outbound TCP ports.
| Port | Purpose | If blocked |
|---|---|---|
| 443 | HTTPS to Microsoft Entra ID, the Power BI service, and Azure Relay | The gateway cannot work |
| 5671, 5672 | AMQP connections to Azure Service Bus | The gateway can fall back to HTTPS over 443 |
| 9350 to 9354 | Service Bus relay listeners over TCP | The gateway can fall back to HTTPS over 443 |
Port 443 is the only one that is strictly required. Opening the others lets the gateway use direct TCP, which usually performs better than tunneling everything through HTTPS. When the gateway has to fall back to HTTPS, refreshes still work but can be slower.
Allow by fully qualified domain name where your firewall supports it. Typical destinations include *.servicebus.windows.net, login.microsoftonline.com, and *.powerbi.com. Microsoft publishes the full list of required domains and updates it over time, so check the current list instead of copying one from an old runbook. Allow-listing individual IP addresses is fragile because the relay addresses change.
Testing connectivity
Run this on the gateway machine, not on your workstation. The result reflects the firewall path from the gateway.
Test-NetConnection -ComputerName watchdog.servicebus.windows.net -Port 9350To check every Service Bus port in one pass:
$ports = 443, 5671, 5672, 9350, 9351, 9352, 9353, 9354
foreach ($p in $ports) {
Test-NetConnection -ComputerName watchdog.servicebus.windows.net -Port $p |
Select-Object ComputerName, RemotePort, TcpTestSucceeded
}TcpTestSucceeded : True means the TCP handshake completed. It does not prove that TLS inspection or a proxy is leaving the traffic intact. The gateway app also has a network connectivity test on its Diagnostics tab. Run it as well, because it tests the actual endpoints that your gateway version uses.
Forcing HTTPS mode and using a proxy
If you cannot open the TCP ports, you can tell the gateway to use HTTPS only. Recent gateway versions expose this as a setting on the Network tab of the gateway app. Older versions used a setting in Microsoft.PowerBI.EnterpriseGateway.exe.config. Check the documentation for your installed version before editing that file.
If the gateway machine reaches the internet through a proxy, the proxy settings go in the same configuration file (a defaultProxy section). Two proxy problems are common:
- The proxy requires authentication, and the gateway service account has no credentials for it.
- The proxy performs TLS inspection and replaces certificates. Exempt the gateway destinations from inspection.
The gateway service account
The gateway runs as a Windows service. By default it runs as NT SERVICE\PBIEgwService, a virtual service account created by the installer. The account needs the "Log on as a service" right, and the default account has it.
It is important to separate what this account does from what it does not do:
- It runs the gateway process. It reads the gateway's configuration and writes its logs.
- It is not used to sign in to your data sources, unless the data source accepts Windows authentication and you chose that option. In that case, the credentials you stored for the data source are used, not the service account.
You can change the service account in the gateway app under Service Settings. The usual reason is Kerberos single sign-on or another scenario that needs a domain identity. If you switch to a domain account, apply these rules:
- Use a dedicated account for the gateway, not a personal account or a shared admin account.
- Do not give the account local administrator rights. It does not need them.
- Use a password that does not expire, or document the rotation process. When a password expires, the service stops and every dataset behind that gateway fails to refresh.
- Grant only the rights the service needs. The account must be able to log on as a service and read its own gateway files.
Changing the service account restarts the service. Do it in a maintenance window, and keep the recovery key close in case you need to restore the gateway.
How credentials are protected
When you add a data source in the Power BI service, the service encrypts the credentials with the gateway's public key before storing them in the cloud. Only the gateway holds the matching private key, so only the gateway can decrypt the credentials. At refresh time, the gateway decrypts them in memory and opens the connection to the data source.
The data path works like this:
- The service sends the query to the gateway over the Service Bus connection, protected by TLS.
- The gateway queries the data source on your network, using the stored credentials.
- The gateway compresses and encrypts the result and sends it to the service.
Data is protected in transit between the gateway and the cloud. The hop between the gateway and the data source follows whatever your data source offers. For SQL Server, enable encryption on the connection, and avoid using TrustServerCertificate as a permanent workaround.
Practical security checklist
- Least-privilege data source accounts. Create a read-only SQL login limited to the schemas or views the dataset needs. If someone obtains the stored credentials, the damage is limited to read access on those objects.
- Limit gateway administrators. Gateway admins can add data sources and see which datasets use them. Keep that list short and review it.
- Limit data source users. Granting a user access to a data source lets that user bind their own datasets to it, and so read data through the gateway. Grant it to people, not to broad groups.
- Control who can install gateways. Tenant administrators can restrict gateway installation to approved users in the admin settings. This reduces unmanaged personal-mode gateways running on laptops.
- Prefer standard mode on a server. A personal-mode gateway runs under one person's Windows sign-in, so it stops when that person's session or device is unavailable. It also has no central administration.
- Protect the recovery key. Anyone with the key and a copy of the gateway configuration can restore it onto another machine. Store the key in your password manager or vault, not in a shared document.
- Patch the machine and the gateway. Outdated gateway versions can lose support, and old versions miss connectivity improvements.
- Isolate the host. Keep the gateway machine out of general-purpose use. Do not browse the web or install unrelated software on it.
Common errors in this area
| Symptom | Likely cause | Check |
|---|---|---|
| Gateway shows as offline in the service | Outbound 443 blocked, proxy change, or stopped service | Gateway app status, `Get-Service PBIEgwService` |
| Refresh works slowly after a network change | TCP ports blocked and traffic falling back to HTTPS | Port test above |
| Service fails to start after a reboot | Group policy removed "Log on as a service" | Service logon settings and local security policy |
| All refreshes fail on one day each quarter | Service account password expired | Account status in the directory |
| Connectivity test passes but refresh fails | Proxy or TLS inspection altering traffic | Proxy logs, inspection exceptions |
Exercise
A gateway machine can reach login.microsoftonline.com on port 443, but Test-NetConnection to ports 5671 and 9350 through 9354 fails. Datasets still refresh, but more slowly than before the firewall change. Why does it still work, and what should you do?
Show answer
Only port 443 is required. When the Service Bus TCP and AMQP ports are blocked, the gateway falls back to HTTPS over 443, so refreshes work but with lower performance. Ask the firewall team to allow outbound 5671, 5672, and 9350 to 9354 to the Service Bus destinations, or deliberately set the gateway to HTTPS mode so the behavior is predictable.
Exercise
The gateway service runs under a domain account whose password just expired. Which datasets are affected, and why is the data source credential not the problem?
Show answer
Every dataset that refreshes through that gateway is affected, because the service itself cannot start or authenticate. The data source credentials are stored separately, encrypted in the cloud, and decrypted by the gateway. They never depended on the service account's password. Fix the account password, restart the service, and then confirm the gateway shows as online.