diff --git a/advanced/cancel-previous.md b/advanced/cancel-previous.md index 240568a..04070ae 100644 --- a/advanced/cancel-previous.md +++ b/advanced/cancel-previous.md @@ -198,3 +198,5 @@ Each result cancelled this way carries a `cancellation_reason` of * A re-run that reports the same CI run ID, such as GitHub's "Re-run failed jobs", does not supersede the original attempt. * A previous run older than 24 hours is not superseded. +* With a [CI-only API key](../getting-started/api-keys.md#key-access), a run + supersedes only earlier runs that the same key started. diff --git a/api/overview.md b/api/overview.md index fce51c2..49f407f 100644 --- a/api/overview.md +++ b/api/overview.md @@ -14,6 +14,8 @@ x-app-api-key: You can create an API key in the console under **Settings → API Keys**. The full key is shown only once, when it's created or rotated, so store it securely. +A key's **Access**, chosen when you create it, limits what it can reach. **Full access** reaches every endpoint. **CI: run tests only** reaches the run status, results and report endpoints, and only for runs that key started. **Device sessions only** reaches the [device session](device-sessions.md) endpoints. An endpoint outside a key's access answers `403` with `API_KEY_SCOPE`. See [Key access](../getting-started/api-keys.md#key-access). + Requests can also be authenticated with a DeviceCloud login session, which is how the CLI authenticates after `dcd login`: send `Authorization: Bearer ` together with `x-dcd-org: `, where the signed-in user must be a member of that team. The team ID is a number: `dcd whoami --json` shows it as `org.id`. For scripts and CI, use an API key. A missing or invalid API key returns HTTP `403`. diff --git a/api/results.md b/api/results.md index 3402be7..facbcf1 100644 --- a/api/results.md +++ b/api/results.md @@ -6,6 +6,8 @@ description: "REST API endpoints for one upload's test results: statuses and fai All results endpoints operate on a specific upload identified by its UUID. +With a key that has [**CI: run tests only**](../getting-started/api-keys.md#key-access) access, every endpoint on this page works only for runs that key started. Any other run answers HTTP `404` with the standard error envelope and `"error": "UPLOAD_NOT_FOUND"`, the same as a run that doesn't exist. + **Status values:** `PENDING`, `QUEUED`, `RUNNING`, `PASSED`, `FAILED`, `CANCELLED` --- @@ -51,7 +53,7 @@ curl https://api.devicecloud.dev/results/7e12345f-eb12-12ec-a30b-bb1234f1d12a \ Every attempt is included: a retry appears as its own entry, with `retry_of` set to the `id` of the original attempt. Each entry also includes `config` (the run settings for that test) and `result_files` (references to its stored artifacts, plus the step log itself when it is 512 KB or smaller), which are left out of the example above. Responses for large uploads can therefore run to several megabytes. To poll a run's progress, use the [summary view](#summary-view), or [`GET /uploads/status`](uploads.md#get-upload-status) if you only need the latest attempt of each test. -An upload ID with no results in your team, such as a mistyped one, answers HTTP `200` with an empty `results` list, not `404`. If a poll keeps getting an empty list, check the ID. +An upload ID with no results in your team, such as a mistyped one, answers HTTP `200` with an empty `results` list, not `404` (unless you use a CI-only key, as above). If a poll keeps getting an empty list, check the ID. Each result also has a `cancellation_reason`, which is `null` unless the test was cancelled for a recorded reason: diff --git a/ci-cd/any-ci.md b/ci-cd/any-ci.md index cc54291..d577798 100644 --- a/ci-cd/any-ci.md +++ b/ci-cd/any-ci.md @@ -2,7 +2,7 @@ The DeviceCloud CLI runs anywhere Node 22 or later is installed, so you can call it from any CI service in a single script step. -We recommend using npx so you don't need to install the npm package. In CI, authenticate with an [API key](../getting-started/api-keys.md) — set `DEVICE_CLOUD_API_KEY` as a secret, or pass `--api-key`. For example: +We recommend using npx so you don't need to install the npm package. In CI, authenticate with an [API key](../getting-started/api-keys.md) — set `DEVICE_CLOUD_API_KEY` as a secret, or pass `--api-key`. Give the key **CI: run tests only** access, so a leaked secret can't read your other runs (see [Key access](../getting-started/api-keys.md#key-access)). For example: ```bash npx --yes @devicecloud.dev/dcd@latest cloud --app-file build/app-release.apk --flows .maestro --quiet diff --git a/ci-cd/bitbucket-pipelines.md b/ci-cd/bitbucket-pipelines.md index 148ba0c..2f2ef60 100644 --- a/ci-cd/bitbucket-pipelines.md +++ b/ci-cd/bitbucket-pipelines.md @@ -25,7 +25,7 @@ pipelines: Store your DeviceCloud API key as a **Secured Repository variable** in *Repository settings → Repository variables*. Reference it as `$DEVICE_CLOUD_API_KEY` and pass it to the pipe as `API_KEY`. -Find your API key at [console.devicecloud.dev/settings](https://console.devicecloud.dev/settings). +Create the key under **Settings → API Keys** in the [console](https://console.devicecloud.dev/settings), with **CI: run tests only** access, so a leaked secret can't read your other runs. See [Key access](../getting-started/api-keys.md#key-access). ## Platform Examples diff --git a/ci-cd/bitrise-steps.md b/ci-cd/bitrise-steps.md index ebba1d8..6bd3d99 100644 --- a/ci-cd/bitrise-steps.md +++ b/ci-cd/bitrise-steps.md @@ -13,7 +13,7 @@ The **Device Cloud for Maestro** step runs your Maestro flows on DeviceCloud fro ![The Device Cloud for Maestro step added to a Bitrise workflow](../assets/bitrise-workflow-step.png) -4. Populate the API key using a BitRise secret and set any variables. Most inputs correspond to a [`dcd cloud`](../cli/dcd-cloud.md) flag — see that reference for accepted values. Not every flag has an input: device matrices, for example, aren't available in the step. +4. Populate the API key using a Bitrise secret and set any variables. Give the key **CI: run tests only** access, so a leaked secret can't read your other runs (see [Key access](../getting-started/api-keys.md#key-access)). Most inputs correspond to a [`dcd cloud`](../cli/dcd-cloud.md) flag — see that reference for accepted values. Not every flag has an input: device matrices, for example, aren't available in the step. ![The Device Cloud for Maestro step inputs in Bitrise](../assets/bitrise-step-config.png) diff --git a/ci-cd/eas-workflows.md b/ci-cd/eas-workflows.md index d4edfed..d897ce0 100644 --- a/ci-cd/eas-workflows.md +++ b/ci-cd/eas-workflows.md @@ -35,7 +35,7 @@ eas env:create --scope project --environment production --environment preview -- --name DEVICE_CLOUD_API_KEY --visibility secret --type string --value ``` -You can find your API key in the [DeviceCloud console settings](https://console.devicecloud.dev/settings). +Create the key under **Settings → API Keys** in the [DeviceCloud console](https://console.devicecloud.dev/settings), with **CI: run tests only** access, so a leaked secret can't read your other runs. See [Key access](../getting-started/api-keys.md#key-access). ::: info diff --git a/ci-cd/github-actions.md b/ci-cd/github-actions.md index 239848d..16b0a8d 100644 --- a/ci-cd/github-actions.md +++ b/ci-cd/github-actions.md @@ -13,7 +13,7 @@ To get a pass/fail check on each pull request, which you can require before merg app-file: ``` -Store your API key as a [GitHub Actions secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets) named `DCD_API_KEY`. You can find your API key in the [console settings](https://console.devicecloud.dev/settings). +Store your API key as a [GitHub Actions secret](https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets) named `DCD_API_KEY`. Create the key under **Settings → API Keys** in the [console](https://console.devicecloud.dev/settings), with **CI: run tests only** access, so a leaked secret can't read your other runs. See [Key access](../getting-started/api-keys.md#key-access). ## Trigger Recommendations diff --git a/getting-started/api-keys.md b/getting-started/api-keys.md index bc161a3..1924e56 100644 --- a/getting-started/api-keys.md +++ b/getting-started/api-keys.md @@ -32,8 +32,37 @@ In CI and other non-interactive environments, use an API key. 1. Log in to the [console](https://console.devicecloud.dev/settings). 2. Open **Settings → API Keys** and choose **Create API key**. -3. Give it a **Name**, and choose its **Access** and **Expiry**. **Full access** suits CI and scripts. **Device sessions only** suits AI agents that use [Agent Devices](../mcp/agent-devices.md): such a key can start and drive device sessions and upload builds, but can't start test runs or read results. You can't change a key's access later. -4. Copy the key. It's shown only once, so store it straight away, for example as a CI secret. +3. Give it a **Name**, and choose its **Access** and **Expiry**. For CI, choose **CI: run tests only**; see [Key access](#key-access). +4. Copy the key. It's shown only once, when it's created or rotated, so store it straight away, for example as a CI secret. + +### Key access + +You choose what a key can do when you create it. You can't change it later, so create a new key if you need different access. + +| Access | What the key can do | Use it for | +| --- | --- | --- | +| **Full access** | Everything an API key can do. | Scripts that manage runs or read results across your team | +| **CI: run tests only** | Upload builds and flows, start test runs, and follow, download and report on the runs it started. | CI secrets | +| **Device sessions only** | Start and drive device sessions and upload builds. It can't start test runs or read results. | AI agents using [Agent Devices](../mcp/agent-devices.md) | + +A CI-only key limits what a leaked secret can do. Whoever holds it can start test runs, which are billed, but can't read your other runs, results or artifacts, or change your settings. + +With a CI-only key, these work for the runs the key started: + +- `dcd cloud`, including `--download-artifacts`, `--report` and `--cancel-previous` +- `dcd status` +- `dcd artifacts` + +`--cancel-previous` only cancels earlier runs that the same key started. + +These need a key with full access, or `dcd login`: + +- `dcd list` +- Reading a run that another key or a person started +- The [REST API](../api/overview.md) flow analytics endpoints +- The [MCP server](../mcp/connect.md) + +A command outside a key's access fails with HTTP `403` and the error code `API_KEY_SCOPE`. Asking a CI-only key about a run it didn't start returns `404`, the same as a run that doesn't exist. ### Using an API key diff --git a/public/openapi.yaml b/public/openapi.yaml index 71a6e56..ae46058 100644 --- a/public/openapi.yaml +++ b/public/openapi.yaml @@ -25,8 +25,16 @@ info: `dcd login`: send `Authorization: Bearer ` together with `x-dcd-org: `. For scripts and CI, use an API key. - A key limited to **Device sessions only** reaches the `/device/*` endpoints and - nothing else in this API. Other endpoints answer it with `403` and + A key's access is chosen when it's created: + + - **Full access** reaches every endpoint. + - **CI: run tests only** reaches `GET /uploads/status`, `GET /results/{uploadId}`, + the report endpoints and `POST /results/{uploadId}/download`, and only for + runs that key started. Any other run answers `404` with + `"error": "UPLOAD_NOT_FOUND"`, the same as a run that doesn't exist. + - **Device sessions only** reaches the `/device/*` endpoints. + + An endpoint a key's access doesn't cover answers `403` with `"error": "API_KEY_SCOPE"`. ## Rate limits @@ -242,15 +250,26 @@ paths: '403': $ref: '#/components/responses/Forbidden' '404': - description: No upload in your organization matches. + description: | + No upload in your team matches. For a key with + **CI: run tests only** access, no upload that key started matches. content: application/json: schema: $ref: '#/components/schemas/ErrorEnvelope' - example: - statusCode: 404 - message: Upload not found - error: Upload not found + examples: + notFound: + summary: No such upload + value: + statusCode: 404 + message: Upload not found + error: Upload not found + notStartedByKey: + summary: A CI-only key, and a run it didn't start + value: + statusCode: 404 + message: Upload not found + error: UPLOAD_NOT_FOUND '503': $ref: '#/components/responses/KeyCheckUnavailable' /results/{uploadId}: @@ -350,6 +369,8 @@ paths: $ref: '#/components/responses/InvalidUploadId' '403': $ref: '#/components/responses/Forbidden' + '404': + $ref: '#/components/responses/UploadNotStartedByKey' '503': $ref: '#/components/responses/KeyCheckUnavailable' /results/{uploadId}/report: @@ -485,16 +506,27 @@ paths: $ref: '#/components/responses/Forbidden' '404': description: | - The upload has no results in your organization, or doesn't exist. Unlike + The upload has no results in your team, or doesn't exist. Unlike the report downloads, this one answers with the standard error envelope. + For a key with **CI: run tests only** access, also a run that key didn't + start. content: application/json: schema: $ref: '#/components/schemas/ErrorEnvelope' - example: - statusCode: 404 - message: No results found for this upload - error: Not Found + examples: + noResults: + summary: No results + value: + statusCode: 404 + message: No results found for this upload + error: Not Found + notStartedByKey: + summary: A CI-only key, and a run it didn't start + value: + statusCode: 404 + message: Upload not found + error: UPLOAD_NOT_FOUND '429': $ref: '#/components/responses/RateLimited' '503': @@ -3047,7 +3079,7 @@ components: Forbidden: description: | No credentials, an invalid or expired API key, a Bearer token without a - valid `x-dcd-org`, or a key whose scope doesn't reach this endpoint + valid `x-dcd-org`, or a key whose access doesn't cover this endpoint (`"error": "API_KEY_SCOPE"`). content: application/json: @@ -3061,10 +3093,10 @@ components: message: Invalid API key. Please check your API key and ensure it is valid for this environment. error: Forbidden scope: - summary: Key scope too narrow + summary: Key access too narrow value: statusCode: 403 - message: This API key is limited to device_sessions and can't reach /uploads/list. Use a key with full access for this. + message: This API key is limited to CI (run tests only) and can't reach /uploads/list. Use a key with full access for this. error: API_KEY_SCOPE RateLimited: description: Over 60 requests a minute to this endpoint. Wait `Retry-After` seconds, then retry with backoff. @@ -3078,6 +3110,18 @@ components: example: statusCode: 429 message: 'ThrottlerException: Too Many Requests' + UploadNotStartedByKey: + description: | + Only for a key with **CI: run tests only** access: the key didn't start + this run, or it doesn't exist. + content: + application/json: + schema: + $ref: '#/components/schemas/ErrorEnvelope' + example: + statusCode: 404 + message: Upload not found + error: UPLOAD_NOT_FOUND KeyCheckUnavailable: description: | The API key couldn't be checked because of a temporary problem on @@ -3106,13 +3150,28 @@ components: ETag: $ref: '#/components/headers/ETag' NoResults: - description: The upload has no results in your team, or doesn't exist. + description: | + The upload has no results in your team, or doesn't exist. This body has + only a `message`. For a key with **CI: run tests only** access, a run that + key didn't start also answers `404`, but with the standard error envelope + and `"error": "UPLOAD_NOT_FOUND"`. content: application/json: schema: - $ref: '#/components/schemas/MessageOnlyError' - example: - message: No results found for this upload + anyOf: + - $ref: '#/components/schemas/MessageOnlyError' + - $ref: '#/components/schemas/ErrorEnvelope' + examples: + noResults: + summary: No results + value: + message: No results found for this upload + notStartedByKey: + summary: A CI-only key, and a run it didn't start + value: + statusCode: 404 + message: Upload not found + error: UPLOAD_NOT_FOUND MessageOnlyServerError: description: The report couldn't be built. content: