> For the complete documentation index, see [llms.txt](https://developerdocs.instructure.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developerdocs.instructure.com/services/dap/dap-cli-readme/dap-cli-security.md).

# Security

Table access controls for API keys, and securing the database connection.

## Table access

An API key is restricted to a set of tables: the namespaces and tables that key is allowed to read. Whoever generates the key picks those tables, and the DAP API enforces the restriction on every request for table data. Listing namespaces and tables, and fetching schemas, are not restricted by table.

The DAP CLI requests an access token per table it is about to read, naming that table, and checks the access the Identity Service actually granted before using the token. A table the key is not allowed to read is reported as an error rather than silently returning no data.

{% hint style="info" %}
**Table access is not an OAuth scope.** An OAuth scope describes *what* an access token may do; table access describes *which tables* it may do it to. The two are separate, and the DAP API expresses table access through the OAuth 2.0 Rich Authorization Requests field (`authorization_details`), not through the `scope` parameter. Table access is also unlike Canvas developer key scopes: it is fixed when the key is generated and cannot be edited, and there is nothing to select at token request time.
{% endhint %}

{% hint style="warning" %}
The DAP CLI requires a key with table access attached. Generate a key in the [Instructure Identity Service](https://identity.instructure.com), selecting the tables it may read, before using it with the CLI.
{% endhint %}

### Table access is fixed when the key is generated

The tables are chosen when the key is generated and cannot be edited afterwards. Two consequences:

* A table added to a namespace later does not become readable by an existing key.
* Widening access means generating a new key for the wider set of tables.

### Discovering namespaces and tables

Use [`dap list`](https://developerdocs.instructure.com/services/dap/dap-cli-readme/dap-cli-reference/dap-cli-reference-list.md) to see what exists:

```sh
dap list namespaces                     # every namespace
dap list tables --namespace canvas      # every table in canvas
```

{% hint style="info" %}
`dap list` is **not** filtered by table access. Both subcommands return every namespace and table the DAP API exposes, regardless of what your key may read — the names themselves carry no sensitive data and are also published in the [dataset reference](https://developerdocs.instructure.com/services/dap/dataset.md). A name appearing here does not mean your key can read that table's data.
{% endhint %}

### What happens when a table is not allowed

| Command                                                                                                                         | Behavior                                                                               |
| ------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| [`dap list`](https://developerdocs.instructure.com/services/dap/dap-cli-readme/dap-cli-reference/dap-cli-reference-list.md)     | Unaffected — lists every namespace and table regardless of table access                |
| [`dap schema`](https://developerdocs.instructure.com/services/dap/dap-cli-readme/dap-cli-reference/dap-cli-reference-schema.md) | Succeeds — schemas are metadata and are not restricted per table                       |
| Data commands on a single table                                                                                                 | Fail with an error naming the table                                                    |
| Data commands on several tables                                                                                                 | The disallowed table fails; the remaining tables still run. The command exits non-zero |

Data commands are [`snapshot`](https://developerdocs.instructure.com/services/dap/dap-cli-readme/dap-cli-reference/dap-cli-reference-snapshot.md), [`incremental`](https://developerdocs.instructure.com/services/dap/dap-cli-readme/dap-cli-reference/dap-cli-reference-incremental.md), [`initdb`](https://developerdocs.instructure.com/services/dap/dap-cli-readme/dap-cli-reference/dap-cli-reference-initdb.md) and [`syncdb`](https://developerdocs.instructure.com/services/dap/dap-cli-readme/dap-cli-reference/dap-cli-reference-syncdb.md).

The error for a table the key was not granted reads:

```
ERROR - Requested access to 'canvas/submissions' was not granted by the token issuer.
```

When several tables are requested and some fail, the CLI reports a summary and exits with code `5`:

```
ERROR - Operation snapshot completed with issues: 1 failed out of 3 table(s).
```

## Regional API base URL

The DAP CLI requires the base URL of your regional API Gateway, set through `--base-url` or the [`DAP_API_URL`](https://developerdocs.instructure.com/services/dap/dap-cli-readme/dap-cli-reference/dap-cli-reference-env-vars.md) environment variable. There is no default. The Identity Service shows the correct regional URL for your key when you generate it. The region must match your Canvas instance's region:

| Region                   | API base URL                                         |
| ------------------------ | ---------------------------------------------------- |
| `us-east-1` (`iad`)      | `https://us-east-1.api-gateway.instructure.com`      |
| `us-west-2` (`pdx`)      | `https://us-west-2.api-gateway.instructure.com`      |
| `ca-central-1` (`yul`)   | `https://ca-central-1.api-gateway.instructure.com`   |
| `eu-west-1` (`dub`)      | `https://eu-west-1.api-gateway.instructure.com`      |
| `eu-central-1` (`fra`)   | `https://eu-central-1.api-gateway.instructure.com`   |
| `ap-southeast-1` (`sin`) | `https://ap-southeast-1.api-gateway.instructure.com` |
| `ap-southeast-2` (`syd`) | `https://ap-southeast-2.api-gateway.instructure.com` |

Omitting both the flag and the environment variable fails with:

```
ERROR - Missing DAP API base URL. Please provide the base URL of your regional API Gateway before proceeding.
```

## Secure Database Connection

The DAP client library supports secure connections to databases using SSL/TLS. You can specify the SSL mode by using the `ssl` parameter in the connection string.

### Supported SSL modes

* **`disable`**: SSL is disabled.
* **`prefer`** (default): Attempts an SSL connection first; falls back to a non-SSL connection if SSL fails.
* **`allow`**: Attempts a non-SSL connection first; retries with SSL if the first attempt fails.
* **`require`**: Forces an SSL connection, but certificate verification errors are ignored.
* **`verify-ca`**: Forces an SSL connection and verifies that the server certificate is issued by a trusted certificate authority (CA).
* **`verify-full`**: Forces an SSL connection, verifies that the server certificate is issued by a trusted CA, and ensures the server's hostname matches the certificate.

### Examples

1. **Default SSL mode (prefer)**:

   ```bash
   postgresql://scott:password@server.example.com:5432/testdb
   ```
2. **Forcing SSL connection**:

   ```bash
   postgresql://scott:password@server.example.com:5432/testdb?ssl=require
   ```
3. **Forcing SSL connection and verifying the server certificate**:

   ```bash
   postgresql://scott:password@server.example.com:5432/testdb?ssl=verify-full
   ```

### Important Notes

**`verify-ca`** and **`verify-full`** modes require the CA certificate to be installed on your system to verify the server certificate. If the CA certificate is not installed, the connection will fail.

The location of CA certificates depends on the operating system:

* **Linux**: CA certificates are typically stored in `/etc/ssl/certs/` or similar directories.
* **Windows**: CA certificates are managed in the Windows Certificate Store.
* **macOS**: CA certificates are stored in the Keychain.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developerdocs.instructure.com/services/dap/dap-cli-readme/dap-cli-security.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
