Skip to content

feat: sign a command-line client in through the browser - #282

Merged
kcrmin merged 1 commit into
developfrom
feature/500-device-authorization
Aug 9, 2026
Merged

feat: sign a command-line client in through the browser#282
kcrmin merged 1 commit into
developfrom
feature/500-device-authorization

Conversation

@kcrmin

@kcrmin kcrmin commented Aug 9, 2026

Copy link
Copy Markdown
Member

UI 짝: Idea2Strategy/Idea2Strategy-ui#176
상위 이슈: Idea2Strategy/Idea2Strategy#479

CLI 가 비밀번호를 stdin 으로 읽는다. 즉 CLI 를 구동하는 무언가가 사용자의 비밀번호를 쥐어야
한다
— "설치하고 설정해줘" 라는 지시를 받은 AI 에이전트를 포함해서. 에이전트에게 건네려고 만든
도구에는 맞지 않는 모양이고, CLI 를 아무리 조심스럽게 짜도 고쳐지지 않는다. 비밀이 잘못된 곳에
있기 때문이다.

기기 인증이 그것을 옮긴다. CLI 는 코드 두 개를 받아 짧은 쪽을 표시하고 긴 쪽으로 폴링한다.
사용자는 이미 자격을 가진 브라우저 세션에서 승인한다.

코드 두 개는 서로 대체할 수 없다

user code 는 사람이 읽고 다시 입력하므로 오독 문자를 뺐다 — 0/O·1/I 없음, 단어가 되지 않도록
모음 없음(BCDFGHJKLMNPQRSTVWXZ23456789). 의도적으로 약하고, 그렇기 때문에 승인 요청만 할 수
있다.
토큰을 받는 것은 256비트 device code 뿐이다. 어깨너머로 본 코드로는 세션을 훔칠 수 없다.

둘 다 다이제스트로만 저장한다. DB 를 읽을 수 있는 사람이 남의 대기 중 로그인을 완성하지 못한다.

소진은 단일 조건부 문장이다

update … where status='APPROVED' … returning approved_account_id 그 자체가 판정이다. 읽고 나서
쓰면 동시에 도착한 두 폴링이 둘 다 APPROVED 를 보고 토큰을 두 번 받는다. 이미 소진된 device code
는 APPROVED 가 아니라 UNKNOWN 으로 답해, 재사용이 새 발급처럼 보이지 않게 했다.

세션은 로그인과 같은 것을 발급한다

같은 refresh family, 같은 auth epoch, 같은 credential version 이다. 이걸 건너뛴 기기 세션은
비밀번호를 바꿔도 살아남는데, 접근을 회수하는 사람이 기대하는 것은 정확히 그 반대다.

스키마

identity.device_authorization_requests 를 정본 DBML 과 마이그레이션에 추가했다. CHECK 제약이
"승인자 없는 APPROVED" 와 "승인자 있는 PENDING" 을 둘 다 막는 것을 로컬 postgres 에서 실제로
확인했다.

짚어둘 변경

findPasswordLoginByAccountId 를 추가하면서 IdentityQueryPort 가 함수형 인터페이스가 아니게
됐다. 거기 기대던 테스트 두 곳을 구현체로 바꿨다 — 포트에 default 를 주면 실제 어댑터가 메서드를
조용히 빠뜨릴 수 있다.

검증

:db-migration:test · :modules:backend-application:test · :apps:idea2strategy-cli:test 통과.

남은 것

브라우저를 여는 login --browser 까지 이 PR 에 있다. 실제 왕복은 UI PR 과 함께 배포된 뒤에만
확인할 수 있다.

🤖 Generated with Claude Code

The CLI reads a password from standard input, so anything driving it has to hold the
customer's password — including an AI agent told to install and configure it. That is
the wrong shape for a tool meant to be handed to an agent, and no amount of care in
the CLI fixes it: the secret is in the wrong place.

A device authorization moves it. The CLI asks for a pair of codes, prints the short
one, and polls with the long one; the customer approves in a browser session that
already holds their credential.

The two codes are not interchangeable. The user code is read aloud and retyped, so it
drops characters that are misread — no 0/O, 1/I, no vowels to spell words — which
makes it weak on purpose, and it can therefore only ever request approval. The device
code is a full 256-bit secret and is the only thing that collects a token. Both are
stored as digests, so a database reader cannot finish somebody's pending login.

Consumption is a single conditional update returning the account, not a read followed
by a write: two polls arriving together must not both collect a token. A device code
that already collected one answers UNKNOWN rather than APPROVED, so a replay cannot
look like a fresh grant.

The session it mints is the same one a password login mints — same refresh family,
auth epoch, and credential version — because a device-approved session that skipped
those would outlive a password change, which is exactly what someone revoking access
expects it not to do.

Adding findPasswordLoginByAccountId stopped IdentityQueryPort being a functional
interface. The two tests that leaned on that now implement it, rather than the port
gaining a default that would let a real adapter silently omit the method.

Refs #479

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kcrmin
kcrmin merged commit 08bb014 into develop Aug 9, 2026
2 checks passed
@kcrmin
kcrmin deleted the feature/500-device-authorization branch August 9, 2026 21:56
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