# SQL Server temporary access

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

SQL Server uses the same [Rust provisioner](/docs/guides/provisioner) with either
inbound HTTPS or outbound-only polling. The same service can handle other targets
without changing its deployment or adding environment variables.

## Connect a database

In **Temporary access → Add target**, select **SQL Server**, choose a registered
provisioner, select database roles such as `db_datareader`, and set the maximum
lifetime. Enter the administrator connection string in the credential field:

```text
mssql://admin:password@sql.internal:1433/app
```

Percent-encode special characters in the username, password, and database. TLS
and certificate verification are mandatory. The browser encrypts the target and
administrator credential to your provisioner before upload.

The provisioning account needs permission to create, alter, and drop SQL logins
and database users, inspect their metadata, and add members to the selected
database roles. Reserve generated `sk_` names for leases. This integration supports
SQL Server authentication, not contained Azure SQL users or Windows/Entra authentication.

## Lease lifecycle

The provisioner generates a password locally and creates a SQL login, database
user, and role memberships in one transaction. It encrypts the result directly
for the requester. Cleanup checks a deterministic login SID before touching a
principal, so a restart needs no local journal and unrelated same-name principals
are rejected.

SQL Server has no native timestamp expiry for these logins. Seekrit schedules
revocation and retries failures. Revocation disables the login before dropping
the database user and login; existing sessions can delay the final drop and are
not forcibly terminated. Keep the provisioner running and connected for cleanup.

## CLI and API

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

```json
{
  "provider": "mssql",
  "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: "mssql"`. See the [CLI reference](/docs/reference/cli) and
[API reference](/docs/reference/api) for commands and endpoints.
