> ## Documentation Index
> Fetch the complete documentation index at: https://patch.codemagic.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Security and access

> How Patch handles authentication, team access, API tokens, and optional code signing.

Patch separates who can publish updates (CLI and dashboard auth) from whether clients trust updates (optional code signing).

## Authentication

### Dashboard sign-in

Sign-in uses GitHub, Bitbucket Cloud, or GitLab OAuth. Installs with domains require at least one configured provider; the first admin email must match the verified primary address on that account when `REGISTRATION_MODE=invite_only`.

The [installer](/docs/install) walks you through creating the OAuth app.

### CLI sign-in

  <TabItem value="react-native" label="React Native">

Developers sign in through the browser — `cmpatch login` opens the dashboard and completes over a localhost redirect (pass `--token` to sign in with a personal access token instead):

```bash
cmpatch login --server-url https://updates.example.com
```

In a project set up with `cmpatch init`, the server URL is already known and
`cmpatch login` needs no flag. Credentials are stored locally in `~/.codemagic-patch/`.

  </TabItem>
  <TabItem value="capacitor" label="Capacitor">

`cmpatch-capacitor login` opens the dashboard in a browser and completes sign-in through a localhost redirect. To sign in with a personal access token, pass `--token`:

```bash
cmpatch-capacitor login --server-url https://updates.example.com
```

If `CODEMAGIC_PATCH_SERVER_URL` or a default server (`cmpatch-capacitor config set --server-url`) is set, `--server-url` is not needed. Credentials are stored in `~/.codemagic-patch/credentials-capacitor.json`, readable only by your user and separate from `cmpatch` credentials. `--no-browser` prints the sign-in URL instead of opening it. The URL must be opened on the same machine, so use `--token` over SSH.

  </TabItem>
</SdkTabs>

### API tokens (CI and automation)

For CI and scripting, create personal access tokens:

  <TabItem value="react-native" label="React Native">

```bash
cmpatch token create --name ci
```

  </TabItem>
  <TabItem value="capacitor" label="Capacitor">

```bash
cmpatch-capacitor token create --name ci --expires-in-days 365
```

  </TabItem>
</SdkTabs>

- Prefix: `cm_pat_…`
- Shown once at creation: store in your secret manager
- Supply via `CODEMAGIC_PATCH_TOKEN` or `--token`
- Revoke with `token revoke` (or from the dashboard) when compromised

An API token can manage apps, deployments, and releases, but it cannot create credentials, grant access, or move an app. These need a browser sign-in (the dashboard, or `login` without `--token`): `token create`, `member add`, `member invite`, `member update`, `member provision`, `member rotate-token`, and `app transfer`. So do `webhook create`, `webhook update`, and `webhook rotate-secret`, which decide where release events are sent. A token can still remove members, invitations, and tokens. Through the API a token can also create a team and name its owner in the same request (`POST /v1/teams` with `owner`); the invited account gets that new team and none of your existing ones. The server logs each refused token request with the token's ID, so a leaked token trying these commands shows up in the server log.

Revoking a token ends the access the token itself had. Roles and invitations it granted to other accounts earlier stay until you remove them, and so do teams it created and the owners it named for them: an owner signs in on their own and can invite others. After a leak, review the teams, members, and pending invitations the token's account can see. On a server with `REGISTRATION_MODE=invite_only`, a pending invitation also lets the invited address create an account.

An account created with `cmpatch member provision` is a service account that belongs to the team that created it. An admin of that team replaces its token from a browser sign-in with `cmpatch member rotate-token --email <email>`; the old token stops working at once, so update the CI secret that held it.

### Sessions and signing out everywhere

A browser or CLI sign-in lasts at most 90 days (`OAUTH_SESSION_MAX_AGE_DAYS`), however often it refreshes. A CLI sign-in approved from the dashboard shares the deadline of that dashboard sign-in; signing out of the dashboard does not end it. After the deadline, sign in again.

If a token or device may be compromised, use **Sign out everywhere** on the dashboard's API tokens page. It ends every session on your account, this browser and every CLI included, and deletes all your API tokens. Sign in again, then create new tokens and update your CI secrets.

:::warning
Treat `cm_pat_…` tokens like production credentials. Scope pipeline access and rotate on schedule.
:::

### Auth precedence

`--token` → `CODEMAGIC_PATCH_TOKEN` → the credential stored by `login`

## Code signing (update integrity)

Beyond server authentication, Patch supports cryptographic signing of release manifests so clients only install packages signed with your private key.

Enable at app creation or later:

  <TabItem value="react-native" label="React Native">

```bash
cmpatch app create --name MySignedApp-iOS --require-code-signing
cmpatch app setting --app MyApp-iOS --require-code-signing=true
```

  </TabItem>
  <TabItem value="capacitor" label="Capacitor">

```bash
cmpatch-capacitor app create --name MySignedApp-iOS --require-code-signing
cmpatch-capacitor app setting --app MyApp-iOS --require-code-signing=true
```

  </TabItem>
</SdkTabs>

Create a private and public key pair with OpenSSL:

```bash
# generate private RSA key
openssl genrsa -out patch-private-key.pem 2048

# export public key
openssl rsa -in patch-private-key.pem -pubout -out patch-public-key.pem
```

  <TabItem value="react-native" label="React Native">

Copy the public key (`cat patch-public-key.pem`, including the `BEGIN` / `END` lines) into native config as `CodemagicPatchPublicKey`. See [Native setup](/docs/setup/native-setup) for `Info.plist`, `strings.xml`, or Expo plugin wiring.

  </TabItem>
  <TabItem value="capacitor" label="Capacitor">

Copy the public key (`cat patch-public-key.pem`, including the `BEGIN` / `END` lines) into `capacitor.config.ts` as `publicKey` in each platform block. A `CodemagicPatchPublicKey` native resource overrides this value. See [Native setup](/docs/setup/native-setup-capacitor).

  </TabItem>
</SdkTabs>

Publish signed releases with the private key:

  <TabItem value="react-native" label="React Native">

```bash
cmpatch release-react --platform ios --deployment Staging \
  --private-key-path ./patch-private-key.pem --yes
```

  </TabItem>
  <TabItem value="capacitor" label="Capacitor">

```bash
cmpatch-capacitor release create --bundle-path www \
  --app MyApp-iOS --deployment Staging --target-binary-version "1.2.0" \
  --private-key-path ./patch-private-key.pem
```

The signature is an RS256 JWT of the bundle's package hash. The SDK verifies it on the device.

  </TabItem>
</SdkTabs>

  <TabItem value="react-native" label="React Native">

When building a `.cmpatch` artifact with code signing enabled, pass `--private-key-path` to `cmpatch bundle` as well.

  </TabItem>
  <TabItem value="capacitor" label="Capacitor">

`cmpatch-capacitor release create` signs the bundle during upload; there is no separate bundle step.

  </TabItem>
</SdkTabs>

The SDK reads the public key from the binary at launch, so ship a new native build (and reinstall on devices) before clients can verify signed OTAs. OTA updates cannot add or change the public key.

With the key in the binary, the client rejects releases with missing or invalid signatures.

If no public key is configured, the client does not verify signatures and installs both signed and unsigned releases.

## Server secrets

`.env.selfhost` contains production secrets (Postgres, Silo, OAuth, worker keys). Back it up and never commit it. See [Configuration reference](/docs/reference/configuration).

## CI hygiene

- Store `CODEMAGIC_PATCH_TOKEN` in CI secret stores only
- Use separate tokens per pipeline or environment where possible
- Release to Staging before Production ([CI integration](/docs/using-patch/ci-integration))
