Locking down SQL Server: disabling sa and closing the Docker network gap
While investigating a memory pressure issue, we found hundreds of failed login attempts against the default sa account in the SQL Server error log. A bot was actively probing our database. This is how we hardened the setup in two layers: fixing the credential risk first, then closing the network exposure Docker quietly left open.
While investigating a memory pressure issue, we found something unexpected in the SQL Server error log — hundreds of failed login attempts against the default sa account. A bot was actively probing our database. This is how we hardened the setup in two layers: first fixing the credential risk, then closing the network exposure that Docker quietly left open.
How we found it
The discovery was accidental. We were digging through SQL Server logs looking for clues about the RAM exhaustion issue — and buried in the error log were repeated login failures against the sa account. Not occasional noise. Hundreds of attempts, clearly automated.
The sa account is SQL Server's built-in system administrator — enabled by default, with a fixed, well-known name. It's one of the first things any automated attack script will try. Seeing it hit repeatedly made it clear we needed to act.
Note: A bot doesn't need to succeed on every attempt — it just needs to succeed once. The
saaccount being active and reachable from the internet is a standing invitation.
The two risks we needed to fix
We identified two distinct problems requiring two distinct fixes:
1. The credential risk: sa was enabled with a known name, making it a permanent target for brute-force attempts regardless of password strength.
2. The network risk: SQL Server's port was reachable from the internet — and Docker had bypassed the server's standard firewall rules to make it so.
We fixed them in order: credential risk first, then network exposure.
Layer 1: disabling sa and creating a dedicated account
Microsoft's own guidance recommends disabling the sa account and using a named account instead. The reasoning is simple: an attacker can't brute-force an account name they don't know. Disabling sa removes the guaranteed target.
We created a new SQL Server login with a strong password and the necessary permissions for the application, updated the connection string, verified the application connected correctly — and then disabled sa.
-- Create a new dedicated login
CREATE LOGIN [app_user] WITH PASSWORD = 'your-strong-password';
-- Grant necessary permissions
USE [YourDatabase];
CREATE USER [app_user] FOR LOGIN [app_user];
ALTER ROLE db_owner ADD MEMBER [app_user];
-- Disable the sa account
ALTER LOGIN [sa] DISABLE;
Warning: Always verify the new login works correctly — application connects, queries run — before disabling
sa. Disabling your only working login on a remote server is not a recoverable situation without console access.
Layer 2: closing the Docker network gap
With the credential risk addressed, we turned to the network. Our application and SQL Server run on the same server — there's no legitimate reason for SQL Server's port to be reachable from the internet. Closing it should have been straightforward. It wasn't.
Docker manages its own network rules using iptables — and by default, it inserts those rules in a way that bypasses the standard INPUT chain that tools like ufw or standard iptables rules operate on. A port that appears blocked by your firewall can still be reachable if Docker has opened it at a lower level.
Important: This is a well-known Docker behavior that catches many people off guard. Blocking a port with
ufwor standardiptables INPUTrules does not block Docker-exposed ports. Docker operates in theFORWARDchain, above your firewall rules.
The correct place to block Docker container traffic from external interfaces is the DOCKER-USER chain — a chain Docker provides specifically for this purpose, and which is evaluated before Docker's own rules.
# Block all external traffic to Docker containers
iptables -I DOCKER-USER -i eth0 -j DROP
This single rule drops all inbound traffic arriving on the external interface (eth0) before it reaches any Docker container — including SQL Server. Internal communication between the .NET application and SQL Server on the same host is unaffected.
Allowing temporary access when needed
Occasionally we need to connect to SQL Server directly from a specific machine — for maintenance, inspection, or running queries manually. Rather than opening the port permanently, we add a temporary rule for that specific IP and remove it when done.
# Allow a specific IP (insert before the DROP rule)
iptables -I DOCKER-USER -i eth0 -s 194.110.13.91 -j ACCEPT
# Remove it when done
iptables -D DOCKER-USER -i eth0 -s 194.110.13.91 -j ACCEPT
The -I flag inserts the rule at the top of the chain, so it's evaluated before the DROP rule. When access is no longer needed, -D removes it. No permanent exposure, no lingering open ports.
What this hardening achieved
✓ Brute-force attempts against sa are now pointless — the account doesn't exist as a target
✓ SQL Server's port is unreachable from the internet — Docker's network gap is closed
✓ Temporary access is possible when needed, without permanently reopening exposure
⚠ iptables rules don't survive a reboot by default — persistence requires saving rules with iptables-save or a tool like iptables-persistent
Key takeaways
Check your error logs regularly — not just for errors. The bot activity was invisible until we looked. Error logs surface things that monitoring dashboards don't always catch.
Disable sa and use a named account. Microsoft recommends it. A fixed, well-known account name is a permanent attack surface regardless of password strength.
Docker bypasses standard firewall rules. ufw and iptables INPUT rules don't block Docker-exposed ports. Use the DOCKER-USER chain for anything you want to block at the container level.
Temporary access is better than permanent exposure. The IP allowlist pattern — add, use, remove — keeps the attack surface minimal without sacrificing operational flexibility.