# Azure SQL Database temporary access

[Temporary access overview](/docs/concepts/temporary-access) covers target setup, connection methods, and credential handling.

Issue temporary SQL-authenticated contained users in one Azure SQL database. This
uses the same [Rust provisioner](/docs/guides/provisioner) and TDS driver as
[SQL Server](/docs/guides/dynamic-mssql).
Push and outbound-only polling work with the existing connection token; no additional
service, runtime, or per-target deployment configuration is needed.

## Connect a database

In **Temporary access → Add target**, select **Azure SQL Database**, choose your
provisioner, and enter the existing database roles to grant, such as `db_datareader`.
Supply the administrator URI in the credential field:

```text
mssql://admin:password@server.database.windows.net:1433/app
```

Percent-encode special characters in the username, password, and database. Use the
server's normal DNS hostname with a private endpoint; DNS inside your network routes
it to the private IP. TLS and certificate verification are mandatory.

The administrator needs `ALTER ANY USER`, permission to grant the selected roles,
and permission to deny `CONNECT` to lease users in that database. It does not need
to create server logins or manage users in `master`. SQL authentication must be enabled.
The browser encrypts the entire target and admin URI to the provisioner.

## Lease lifecycle

Each lease creates a contained user with a random password and a lease-specific SID,
and assigns its roles in one transaction. The result includes the database name;
clients must connect directly to that database when authenticating.

Cleanup verifies the SID and contained-user type, denies new connections, then drops
the user. Password changes do not change the ownership SID. Existing users are never
overwritten, and cleanup does not modify server logins. If the user owns objects,
deletion fails and is retried; the connection denial remains in effect.

There is no native lease deadline for these users. Keep the provisioner online for
scheduled cleanup. Existing sessions and authentication caches can delay revocation.
Microsoft Entra authentication and Microsoft Fabric are not covered by this provider.

## CLI and API

Use `seekrit dynamic target add --name reporting --config target.json`, piping the
admin URI on stdin:

```json
{
  "provider": "azure-sql",
  "executor": "remote",
  "provisionerId": "prv_REPLACE_WITH_REGISTERED_ID",
  "settings": {"roles": ["db_datareader"]},
  "maxTtlSeconds": 3600
}
```

Request a lease with `seekrit dynamic lease <target-id> --ttl 1h`. The lease API
accepts `provider: "azure-sql"`. Existing organization members and service tokens
use their granted access and signing keys without changing provisioner configuration.

See Microsoft's [contained user reference](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-user-transact-sql?view=azuresqldb-current).
