Skip to content

feat: approve deploys from a phone (device keys and phone sign-in) - #235

Open
ndbroadbent wants to merge 4 commits into
mainfrom
nathan/mobile-sign-in
Open

ndbroadbent wants to merge 4 commits into
mainfrom
nathan/mobile-sign-in

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Approve and reject deploys from a phone. This PR holds the whole server side: device keys (previously #234) and the phone app's sign-in.

Device keys

The phone holds a device key: a P-256 key in its Secure Enclave or StrongBox. After Face ID or a fingerprint, the key signs a statement describing one exact deploy approval request.

  • Enrollment: POST /api/v1/device-keys needs a recent MFA step-up. The phone app enrolls its key right after signing in, and the key is usable at once. A user exempt from MFA gets no step-up, so can't add a phone.
  • Scope: each key stores the actions it may sign, currently approving and rejecting deploy approval requests. A device key never signs anyone in, opens no step-up window and doesn't count toward MFA enrollment. Every other MFA route refuses it with device_key_not_accepted.
  • Signing: POST /api/v1/deploy-approval-requests/:id/device-key-challenge returns a canonical JSON statement. It names the gateway, action, request, approver and key, and includes the app, commit, branch, PR, message, requester and CI token. It's single-use, expires after five minutes and is bound to that user, action and request. The phone sends its signature as inline MFA. The gateway rebuilds the statement from the current request and refuses the signature if anything changed.
  • Audit: the approve and reject entries record the signed statement, the signature and the public key, so an approval can be verified from the audit log alone.
  • Management: Account Security → Phones lists the user's phones and removes one. An admin MFA reset also removes the user's device keys.

Phone sign-in

  • The app signs in like the CLI (RFC 8252, PKCE), using its custom URL scheme (com.docspring.rackgateway:/auth/callback) where the CLI uses a loopback address.
  • GET /api/v1/auth/mobile/start sends the sign-in sheet to Google. Google returns to the existing /api/v1/auth/cli/callback, so deployments don't add a redirect URI in the Google Cloud console. A cli_login_states.client column marks a login as cli or mobile.
  • The sheet then goes to the same MFA page a CLI login uses ("Approve Phone Sign-In"), where the person uses TOTP, a passkey or a security key.
  • /api/v1/auth/cli/return sends the app a single-use login code. POST /api/v1/auth/mobile/complete redeems it with the PKCE verifier. Each code only redeems for the kind of client that started its login.
  • The result is a mobile session with MFA verified and a fresh step-up, so the app can enroll its key straight away.

The mobile session

  • It can only reach the phone's routes: info, MFA status, listing and enrolling device keys, and deploy approval requests (list, read, get a challenge, approve, reject).
  • Everything else answers 403 mobile_session_route, and the rack proxy refuses it outright.
  • Approving or rejecting still needs a device key signature of that one request.

Docs: user-guide/mfa/phone-approvals.

The iPhone app that uses this is in mobile/ios on a separate branch. Outbound webhooks for approval events come later.

Testing

  • auth/mfa/device_keys_test.go covers:
    • enrollment validation and the statement's contents;
    • single use, and binding to action and target;
    • a request that changed after signing;
    • another user's key, a removed key, and an admin reset.
  • handlers/device_key_approval_test.go goes through the MFA middleware:
    • approve and reject;
    • a reject statement can't approve;
    • a proof for one request can't approve another;
    • the device key is refused elsewhere;
    • the audit entry's signature verifies.
  • handlers/auth_mobile_test.go covers the full sign-in against a fake identity provider:
    • the sheet goes through the MFA page;
    • single-use codes and the PKCE verifier;
    • a mobile code refused at the CLI endpoint;
    • only the app's redirect URI accepted;
    • no code for an unknown user.
  • routes/mobile_session_test.go goes through the full router:
    • the route allowlist, including the rack proxy;
    • enrolling a key needs a recent step-up.
  • db/mobile_session_test.go checks that login codes are bound to their client.
  • Web: the Phones card and the MFA page's phone sign-in title.
  • Tried end to end on a staging gateway with the iPhone app: Google sign-in, TOTP in the sheet, key enrolled, and a deploy approved with Face ID.

A phone can now hold a device key: a P-256 key in its Secure Enclave or
StrongBox that signs a statement of one exact deploy approval request
after Face ID or a fingerprint.

- Enrolling stores the key unconfirmed and returns an 8-character code.
  Confirming it in Account Security needs the user's MFA, so a phone
  can't be added with a Google sign-in alone. Five wrong codes remove it.
- Each key has a list of allowed actions (approve and reject deploy
  approval requests). A device key never signs in, opens no step-up
  window and doesn't count as MFA enrollment.
- A challenge route issues a single-use, five-minute statement bound to
  the user, action and request. The gateway rebuilds it when the
  signature arrives and refuses it if anything changed.
- The approval's audit entry records the signed statement, signature and
  public key, so anyone can verify it from the audit log alone.
- Account Security shows a Phones card once a phone has enrolled.
The phone app signs in like the CLI (RFC 8252, PKCE), with its custom URL
scheme instead of a loopback address. It returns through the CLI's
existing Google redirect, so deployments register no new redirect URI.

- POST /auth/mobile/start accepts only the app's redirect URI. The
  callback skips the browser binding and MFA steps for a mobile login
  and sends the app a single-use login code; POST /auth/mobile/complete
  redeems it with the code verifier for a 90-day mobile session.
- Login codes are bound to the kind of client that started the login:
  a mobile code can't make a CLI session, or the reverse.
- A mobile session reaches only the phone's routes (device keys, its
  own verification, deploy approvals). Everything else refuses it,
  including the rack proxy.
- Until it verifies MFA it can only enroll its key or verify with one.
  Confirming the phone's key on the computer verifies the session that
  enrolled it. Later sign-ins verify by signing a statement of the new
  session with the confirmed key. Neither opens a step-up window, and
  approvals still need a signature of their own.
@deepsource-io

deepsource-io Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 61363f9...8f93e07 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Dec 3, 2026 3:03a.m. Review ↗
Go Dec 3, 2026 3:03a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

The phone app's sign-in now continues like a CLI login after Google: the same browser sheet shows the gateway's MFA
step (a TOTP code, a passkey or a security key), and only then returns to the app with its login code. The mobile
session starts verified, with a step-up window, and the app enrolls its device key inside that window.

That replaces the confirmation code the phone showed and the person typed into the web UI, and the device key
signature that verified later sign-ins:

- POST /device-keys needs a recent step-up; a key is usable as soon as it's stored
- device keys have no confirmation code, expiry or confirmed_at any more
- /device-keys/{id}/confirm and /auth/mobile/mfa/* are gone, with the mobile_session.verify statement
- the Phones card lists phones and removes them; the MFA page names a sign-in from the phone app
@ndbroadbent
ndbroadbent force-pushed the nathan/mobile-sign-in branch from df2e29d to 8f93e07 Compare December 1, 2026 01:24
@ndbroadbent ndbroadbent changed the title feat(auth): phone app sign-in with Google and a mobile session feat: approve deploys from a phone (device keys and phone sign-in) Dec 3, 2026
@ndbroadbent
ndbroadbent changed the base branch from nathan/device-keys to main December 3, 2026 03:02
@ndbroadbent ndbroadbent closed this Dec 3, 2026
@ndbroadbent ndbroadbent reopened this Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant