Skip to content

feat(mfa): device keys for approving deploys from a phone - #234

Closed
ndbroadbent wants to merge 2 commits into
mainfrom
nathan/device-keys
Closed

ndbroadbent wants to merge 2 commits into
mainfrom
nathan/device-keys

Conversation

@ndbroadbent

Copy link
Copy Markdown
Member

Summary

Adds the gateway side of approving and rejecting deploys from a phone. 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. The phone app itself is a separate project; this PR only adds what it needs on the server.

How it works

  • Enrollment: POST /api/v1/device-keys stores the key unconfirmed and returns an 8-character code for the phone to show. The person types the code into Account Security → Phones (POST /api/v1/device-keys/:id/confirm), and confirming asks for their MFA every time. So a phone can't be added with a Google sign-in alone. The code expires after 15 minutes, and five wrong codes remove the key.

  • Scope: each key has a stored list of allowed actions, currently approving and rejecting deploy approval requests. A device key:

    • never signs anyone in
    • opens no step-up window
    • 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. The statement:

    • names the gateway, action, request, approver and key
    • includes the app, commit, branch, PR, message, requester and CI token
    • is single-use and expires after five minutes
    • is bound to that user, action and request

    The phone sends its signature as inline MFA (<session>.device_key.<proof>). The gateway rebuilds the statement from the current request and refuses the signature if anything has changed since.

  • Audit: the approve and reject audit entries record the signed statement, the signature and the public key. Anyone can verify an approval from the audit log alone.

  • Reset: an admin MFA reset also removes the user's device keys.

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

Not in this PR

  • A phone sign-in flow and a session limited to the routes a phone needs
  • Outbound webhooks for approval events

Testing

  • internal/gateway/auth/mfa/device_keys_test.go covers:
    • enrollment validation and code confirmation, including lockout and replacement
    • the statement 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
  • internal/gateway/handlers/device_key_approval_test.go sends requests through the MFA middleware to cover:
    • approve and reject
    • a reject statement can't approve
    • a proof for one request can't approve another
    • the device key is refused on extend, API token creation and device-key removal
    • the audit entry's signature verifies
  • Web: the Phones card (hidden until a phone enrolls, confirm, remove).
  • Go unit tests and the web unit suite pass locally.

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.
@deepsource-io

deepsource-io Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 61363f9...886012e 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 Nov 30, 2026 1:26p.m. Review ↗
Go Nov 30, 2026 1:26p.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.

@ndbroadbent

Copy link
Copy Markdown
Member Author

Included in #235, which now targets main with both the device keys and the phone sign-in, so they merge together (#235 edits this PR's unreleased migration).

@ndbroadbent ndbroadbent closed this Dec 3, 2026
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