Connect SPSync to Azure SQL
This guide covers Azure SQL Database and Azure SQL Managed Instance. For SQL Server you run
yourself, or Amazon RDS for SQL Server, read SQL Server. SPSync treats all
of them as the same destination kind, mssql.
Before you start
Section titled “Before you start”- An Azure SQL database, or a Managed Instance with a database in it.
- Either SQL authentication allowed on the server, or a Microsoft Entra identity for SPSync to sign in as. The Entra modes are in preview and not verified against a live Entra-only Azure SQL database; see “Authentication SPSync supports today”.
- ODBC Driver 17 or 18 for SQL Server on the machine that runs SPSync. The desktop app and the Azure managed application include it.
Create the database and a least-privilege user
Section titled “Create the database and a least-privilege user”spsync destination grant-script --kind mssql --identity <name> prints the script below for
your identity, with the right CREATE USER line (--principal sql for a SQL user). SPSync
never runs it. Connect to the database (not master) as the server admin. On Azure SQL Database a
contained user needs no server login. The script below is from the Azure SQL documentation
and has not been run here against a test database.
CREATE USER spsync_loader WITH PASSWORD = 'use-a-long-random-password';GOCREATE SCHEMA sync AUTHORIZATION spsync_loader;GOCREATE SCHEMA sync_staging AUTHORIZATION spsync_loader;GOGRANT CREATE TABLE, CREATE VIEW TO spsync_loader;GOsync is the schema SPSync loads into. sync_staging is where SPSync stages a round before
merging it. CREATE VIEW is only needed for reporting views.
On a Managed Instance you can use the same contained user in a database, or create a login
in master and a user for it, as on SQL Server.
Allow SPSync to reach it
Section titled “Allow SPSync to reach it”- Azure SQL Database: on the logical server, open Networking, then Public access and add a firewall rule with the address SPSync connects from. A database-level rule works too. For the Azure managed application, allow the address it connects out from. Tick “Allow Azure services and resources to access this server” only if you accept every Azure customer’s traffic reaching the firewall.
- Private endpoint: if the server has public access off, SPSync must run where the private endpoint resolves, for example the desktop app on a machine in your network or on a VPN.
- Managed Instance: the instance lives in your virtual network. Open the public endpoint (port 3342) and allow it in the subnet’s network security group from SPSync’s address, or connect over the private endpoint from inside the network.
Encrypt the connection
Section titled “Encrypt the connection”Azure SQL requires an encrypted connection. SPSync opens every SQL Server connection with
Encrypt=yes;TrustServerCertificate=no unless the string says otherwise, and the server’s
certificate chains to a public CA, so you do not need TrustServerCertificate=yes. If the
string turns checking off, SPSync logs a warning on each run and spsync doctor and the
Destination screen show it.
Through an SSH tunnel
Section titled “Through an SSH tunnel”If the database is reachable only through a jump host, SPSync can open an SSH tunnel to that host for each run, forward a local port to the database, and close the tunnel when the run ends. This is a preview: it is tested against a real SSH server in the SPSync test suite, but it has not been run against a live Azure SQL database. The usual case is a small virtual machine in the virtual network that holds the database’s private endpoint, used as the jump host.
-
On a machine you trust, read the jump host’s host key fingerprint. This prints a line containing
SHA256:followed by 43 characters:Terminal window ssh-keyscan -t ed25519 bastion.example.com | ssh-keygen -lf -SPSync asks the server for an ed25519 host key first, then ECDSA, then RSA, so pin the fingerprint of the first of those the server has. If you are unsure, run
ssh-keyscanwithout-tand pin every fingerprint it prints. -
In the connection string, give the database’s address as the jump host sees it, for example
myserver.database.windows.net:1433. SPSync rewrites the address to the local port while the tunnel is open; the string you save is not changed. -
On the Destination screen, tick Reach the database through an SSH bastion and fill in the host, port, user and fingerprint, then paste a private key (and its passphrase) or enter a password. The key is kept in the computer’s keychain and is not shown again.
-
In the CLI, add an
ssh_tunnelblock to the destination in the config file, as below.export-configdoes not write it. With the admin MCP server, the assistant can set the host, port, user and fingerprint, and you enter the key or password on the secure entry page.
destination: kind: mssql connection_string_env: SPSYNC_DSN ssh_tunnel: host: bastion.example.com port: 22 # optional, 22 by default user: spsync host_key_fingerprints: - "SHA256:<the fingerprint from step 1>" private_key_env: keychain:spsync/bastion-key # or file:/path/to/key, or an environment variable name # passphrase_env: BASTION_KEY_PASSPHRASE # only if the key has one # password_env: BASTION_PASSWORD # instead of private_key_envThe host key is always checked. If the jump host presents a key that is not in
host_key_fingerprints, SPSync stops before it sends any credential, and there is no setting
that turns the check off. Keep a second fingerprint in the list while you rotate the host
key. SPSync ignores ~/.ssh/config, known_hosts and any SSH agent: it uses exactly what is
configured here. The key, its passphrase and the password are never written to the config
file or to the control store; they are stored as keychain or Key Vault references, and a
plain environment variable name works for the CLI.
Test connection and spsync doctor open the same tunnel as a run and say so in their
result: connected through SSH tunnel, then the user, host and port, and host key pinned.
The read-only MCP server (spsync mcp serve) opens its own connection to the replica and does
not go through the tunnel.
SPSync adds HostNameInCertificate= with the server name, so the certificate check still runs
against myserver.database.windows.net. That keyword exists in ODBC Driver 18 for SQL Server
only. A tunnel forwards one port, 1433. If the server’s connection policy is Redirect, the
driver is sent to another address and port that the tunnel does not carry, so set the policy
to Proxy (az sql server conn-policy update). This comes from Microsoft’s documentation and
has not been tested here; connections through a private endpoint already use Proxy.
Authentication SPSync supports today
Section titled “Authentication SPSync supports today”The Entra modes are in preview: they are covered by SPSync’s own tests but have not been verified against a live Entra-only Azure SQL database. Test them against a non-production database first.
Choose the mode on the Destination screen (Authentication) or in the destination.auth
block of the config. The best mode your setup allows comes first.
Mode (auth.mode) |
Use it when | What SPSync holds |
|---|---|---|
entra_managed_identity |
SPSync runs on an Azure VM, container or the Azure managed application | Nothing. Azure supplies a token. |
entra_service_principal_certificate |
A script or server outside Azure | The path of a certificate file, read from an environment variable |
entra_default |
The CLI in CI (GitHub OIDC, AKS workload identity) or a developer signed in with az login |
Nothing |
entra_service_principal_secret |
You cannot use a certificate. Allowed, and spsync doctor flags it as weaker |
The name of an environment variable holding the secret |
password |
SQL authentication is allowed on the server | The user name and password in the connection string |
Every Entra mode gets a token for https://database.windows.net/.default (the sovereign
cloud’s own database host for a US Government or China connection) and sends it with each
new connection, so a long load that outlives one token still runs. The connection string then
carries no user or password:
mssql://HOST:1433/yourdatabase?driver=ODBC+Driver+18+for+SQL+ServerFor a database that allows only Microsoft Entra authentication, create the user from the external provider (the grant script does this) and use one of the Entra modes:
destination: kind: mssql connection_string_env: SPSYNC_DSN dataset_name: sync auth: mode: entra_service_principal_certificate tenant_id: 00000000-0000-0000-0000-000000000000 client_id: 11111111-1111-1111-1111-111111111111 certificate_path_env: SPSYNC_SQL_CERTIFICATE # PEM or PFX, the variable holds the pathFor a user-assigned managed identity add client_id; leave auth as
mode: entra_managed_identity for the system-assigned one.
Signing in as the person using the desktop app is not available yet. Neither is Entra
authentication through the ODBC driver’s own Authentication= keyword; SPSync passes the
token itself, which also works on macOS.
spsync doctor shows the mode and the database principal the connection ran as (what
SUSER_SNAME() returns). Nothing in the output, the logs or the run record contains a token
or a secret.
Connect from SPSync
Section titled “Connect from SPSync”Replace HOST with <yourserver>.database.windows.net.
mssql://spsync_loader:PASSWORD@HOST:1433/yourdatabase?driver=ODBC+Driver+18+for+SQL+Server&Encrypt=yes-
Desktop app: open the Destination screen, choose SQL Server / Azure SQL, paste the string into Connection string and choose Test connection.
-
CLI:
Terminal window export SPSYNC_DSN='mssql://spsync_loader:PASSWORD@HOST:1433/yourdatabase?driver=ODBC+Driver+18+for+SQL+Server&Encrypt=yes'spsync export-config --output replication.yaml \--site-url https://contoso.sharepoint.com/sites/x --list Projects \--pipeline-name spsync_dev --prefix dev \--destination-kind mssql --connection-string-env SPSYNC_DSN --dataset-name sync \--client-id <entra-app-client-id> -
AI assistant: with the admin MCP server connected, the assistant reads the requirements and creates the destination. You enter the string on the secure entry page.
What Test connection and doctor check
Section titled “What Test connection and doctor check”They open a real connection with your string. A pass means the firewall lets SPSync in, the
password is right and TLS worked. It does not prove the user can create tables.
spsync doctor reports the same probe as destination-connectivity.
An Azure SQL Database in a paused serverless tier takes a while to resume. The first attempt can fail with a timeout while the database wakes up. Try again after a minute.
Common errors
Section titled “Common errors”| What you see | What it means and the fix |
|---|---|
Cannot open server ... requested by the login. Client with IP address ... is not allowed to access the server |
The firewall rule is missing. Add the address in the message to the server’s firewall rules. |
Login failed for user |
Wrong password, or the user is not in this database. Connect to the database you named, not master. |
Login failed for user '<token-identified principal>' |
The server is Entra-only and you used password. Choose an Entra mode and create the user FROM EXTERNAL PROVIDER. |
could not acquire a credential for auth mode ... with an AADSTS code |
The identity provider refused the token request. The code is Microsoft’s; look it up for the cause (wrong tenant, expired certificate, no managed identity on this host). |
Database ... is not currently available |
A serverless database is resuming. Wait and test again. |
The CREATE TABLE permission was denied |
Run the GRANT and CREATE SCHEMA lines above in that database. |
OpenSSL 4 on macOS with Homebrew
Section titled “OpenSSL 4 on macOS with Homebrew”If a connection fails with OpenSSL library could not be loaded, Homebrew’s openssl alias
now points at OpenSSL 4, which Microsoft’s ODBC Driver 18 does not support. See
Troubleshooting for the one-line fix.