Skip to content

fix(control-plane,mocactl): name the operator's fix for a misconfigured GitHub OAuth app - #413

Merged
pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:fix/405-login-idp-hint
Oct 1, 2026
Merged

pdettori merged 2 commits into
rossoctl:mainfrom
pdettori:fix/405-login-idp-hint

Conversation

@pdettori

@pdettori pdettori commented Oct 1, 2026

Copy link
Copy Markdown
Member

Fixes #405.

Problem

mocactl login printed GitHub's error verbatim — device_flow_disabled, or Not Found for a mistyped SH_GITHUB_CLIENT_ID — and neither says the fix is the operator's.

Change

  • Control plane: new error code identity_provider_misconfigured (502: nothing the caller sends can fix it). identity.ts raises it for device_flow_disabled and for a 404 from /login/device/code (keyed on the status, not GitHub's text). The message is the fix — tick Enable Device Flow, or check SH_GITHUB_CLIENT_ID, naming the rejected id — and keeps GitHub's code so logs still grep for it. Any other GitHub error stays unauthorized.
  • mocactl: classify handles the code before the >= 500 "try again shortly" branch, so mocactl reads the code instead of string-matching GitHub's text:
    login failed: the control plane cannot log anyone in until its operator fixes it — the control plane's GitHub OAuth app has the device flow off (device_flow_disabled): tick Enable Device Flow on the app (deploy/vm/README.md, "The GitHub OAuth app")
    
  • Contract: openapi.yaml lists the code and a 502 response on POST /v1/auth/device. The status-map test and mocactl's contract test cover it.
  • Docs: packages/mocactl/QUICKSTART.md and docs/demos/vm-two-user-acceptance.md (step 1a; findings item 4 marked fixed) quote the new wording.

deploy/knative/demo-multiuser.sh prints .error when a login fails, so it will now show identity_provider_misconfigured. Nothing in it branches on the old code.

Testing

  • New tests, one for each GitHub failure, check the code and the message. Two more cover mocactl's classify and describeError for the new code.
  • control-plane: 420 passed. mocactl: 490 passed.
  • make typecheck and make lint are clean.

🤖 Generated with Claude Code

…ed GitHub OAuth app

`mocactl login` printed GitHub's error verbatim (`device_flow_disabled`, or
`Not Found` for a mistyped client id), neither of which says it is an
operator-side fix.

The control plane now raises a distinct `identity_provider_misconfigured`
(502) for both, with the fix as the message (tick Enable Device Flow; check
SH_GITHUB_CLIENT_ID, naming the id GitHub rejected). mocactl classifies the
code ahead of its >= 500 "try again shortly" branch and says the operator
must fix it. Any other GitHub error stays `unauthorized`.

Fixes rossoctl#405

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>

@huang195 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change works: the code is in the enum, the status map, the OpenAPI spec and mocactl's contract list, and classify puts it ahead of the >= 500 branch. That ordering is tested, because moving the branch after >= 500 would turn the expected operator-misconfigured into unavailable. One must-fix: the doc that both new messages send the operator to still quotes the old wording. Two more things are outside the diff, so they are here rather than inline:

  • The PR body's claim about deploy/knative/demo-multiuser.sh does not hold. login() never reads .error from POST /v1/auth/device (line 151). It takes jq -r .deviceCode, which is the string "null", prints ACTION: open null and enter code null, and polls /v1/auth/device/token with that. The handler only rejects an empty deviceCode, so "null" reaches GitHub, and completeDeviceAuth maps every non-pending error to unauthorized. So the script prints login failed for Alice: unauthorized, not identity_provider_misconfigured. The behaviour itself predates this PR. Either add a one-line check on $start's .error (and .message) before polling, or drop the sentence from the PR body.
  • nit: docs/specs/2026-09-25-mocactl-control-plane-client-design.md §8.1 is the "one table from the API's error codes to UI action", and classify cites it. It has no row for identity_provider_misconfigured.

Author: pdettori (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), OpenAPI, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing

Assisted-By: Claude (Anthropic AI) [email protected]

Comment thread packages/control-plane/src/identity.ts Outdated
throw new CpError(
'identity_provider_misconfigured',
`GitHub knows no OAuth app with client id ${this.clientId} (Not Found): ` +
'check SH_GITHUB_CLIENT_ID (deploy/vm/README.md, "The GitHub OAuth app")',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must-fix: Both new messages point to deploy/vm/README.md, "The GitHub OAuth app". That section still quotes the old output: line 211 says login failed: github device code failed: device_flow_disabled and line 214 says login failed: github device code failed: Not Found. Following the pointer, the operator reads text they will never see. This PR updated QUICKSTART and the acceptance doc but missed the one it links to.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 321cf1e. Both README steps now quote the new lines in fenced blocks. And since the messages no longer name a doc path (see the thread on line 108), nothing points at a stale section any more.

Comment thread packages/control-plane/src/identity.ts Outdated
if (status === 404) {
throw new CpError(
'identity_provider_misconfigured',
`GitHub knows no OAuth app with client id ${this.clientId} (Not Found): ` +

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This puts the raw SH_GITHUB_CLIENT_ID value in a response to an unauthenticated route. In topology (b) of deploy/vm/README.md that route is reachable over the network. An OAuth client id is public, so the normal case is fine. But the case this branch exists for is a wrong value, and a pasted client secret or PAT is also a value GitHub answers with 404. writeError's own doc comment avoids exactly this: a body "is returned to an arbitrary caller". Consider logging the full value server-side and returning a shortened form, such as the first 6 characters plus the length. That still shows a typo.

Also a nit: (Not Found) is hard-coded. The comment above says GitHub's text stays in the message so logs still grep for it, but this branch is keyed on the status. Interpolating body.error would keep that promise when the text differs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken in 321cf1e, with one change. shortClientId shows at most 6 characters and never more than half the value, plus the length: Iv1.fa… (16 chars). I didn't log the full value server-side. If the wrong value is a pasted secret, journald is the wrong place for it too, and the operator already has the full value in control-plane.env. The log line carries the same shortened form, and a test checks that the full id appears in neither the reply nor the log. The nit is fixed too: the message interpolates body.error.

it('reports a mistyped client id (GitHub 404 Not Found) as identity_provider_misconfigured', async () => {
// GitHub's reply never mentions the client id; the message must, or the 404 is undiagnosable.
const { fetch } = fakeFetch({
'/login/device/code': [{ status: 404, body: { error: 'Not Found' } }],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: The PR says the 404 branch is keyed on the status, not GitHub's text. This fixture sends both 404 and 'Not Found', so changing the branch to body.error === 'Not Found' would still pass. A second case with a 404 and some other error string would pin the claim.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 321cf1e. There's a new case: a 404 with error: 'no_such_application' must still give identity_provider_misconfigured, and its message must include (no_such_application). That pins both the status key and the interpolation.

Comment thread packages/control-plane/src/identity.ts Outdated
throw new CpError(
'identity_provider_misconfigured',
"the control plane's GitHub OAuth app has the device flow off (device_flow_disabled): " +
'tick Enable Device Flow on the app (deploy/vm/README.md, "The GitHub OAuth app")',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This message is the same in every deployment, but it names the VM doc. A kind/Knative quickstart operator set the id through make mocactl-quickstart (QUICKSTART §2), so deploy/vm/README.md is the wrong document for them. Line 115 has the same problem. One option is to drop the path and keep just the setting names ("Enable Device Flow", SH_GITHUB_CLIENT_ID), which are the same in both docs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 321cf1e. Both messages now name only the settings (Enable Device Flow, SH_GITHUB_CLIENT_ID), which are the same in the VM README and the kind QUICKSTART. A code comment records why.

…rtened client id, demo start check

- deploy/vm/README.md, which both messages send the operator to, quoted
  the old output; it now shows the new lines.
- The 404 message shows the client id's first characters and length, not
  the whole value: the reply reaches an unauthenticated caller and a wrong
  value may be a pasted secret. Both cases are logged server-side too.
- The 404 branch interpolates GitHub's text instead of hard-coding it, and
  a test pins that it is keyed on the status, not the wording.
- The messages name the settings, not the VM-only doc path.
- demo-multiuser.sh stops at a refused device-flow start and prints the
  control plane's code and message, instead of polling with "null".
- Spec §8.1 gains a row for identity_provider_misconfigured.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
@pdettori

pdettori commented Oct 1, 2026

Copy link
Copy Markdown
Member Author

Thanks. Everything is addressed in 321cf1e:

  • must-fix (deploy/vm/README.md): fixed. See the inline thread.
  • demo-multiuser.sh claim: you're right, it polled with "null" and reported unauthorized. I fixed the script rather than drop the sentence. login() now stops when the start reply has no deviceCode, and prints login failed for Alice: <error>: <message>. demo-multiuser.test.sh has a new mocked run that checks this message and checks that no /v1/auth/device/token poll follows. I confirmed both checks fail without the script change. PR body updated.
  • spec §8.1 nit: added the identity_provider_misconfigured (502) row.
  • Self-review fixes: shortClientId now says "1 char", not "1 chars"; the README no longer claims the log carries "the same line" (the log line has a prefix).

control-plane: 422 passed. mocactl: 490 passed. demo-multiuser.test.sh all ok. tsc and pre-commit are clean.

@huang195 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at 321cf1e. Everything from the last round is fixed. The VM README quotes the new lines, and the messages no longer name a doc path. The client id is shortened in both the reply and the log, and tests pin it. The 404 branch inserts GitHub's text, and a test keys it on the status. The demo stops at a refused start. §8.1 has the row. Removing the new check in demo-multiuser.sh fails both new assertions, so that check is covered. Both suites pass locally: control-plane 422, mocactl 490.

  • nit (PR body): the sample mocactl line still ends with (deploy/vm/README.md, "The GitHub OAuth app"), which 321cf1e removed. The Docs bullet doesn't mention deploy/vm/README.md or the spec row, and the test count says 420 (now 422).

Author: pdettori (MEMBER — maintainer)
Areas reviewed: TypeScript (control-plane, mocactl), Shell (demo + its test), OpenAPI, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: passing

Assisted-By: Claude (Anthropic AI) [email protected]

expect(err.message).toMatch(/\(Not Found\)/);
expect(err.message).toContain('Iv1.fa… (16 chars)');
expect(err.message).not.toContain('Iv1.fakeclientid');
expect(logged().join('\n')).not.toContain('Iv1.fakeclientid');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This assertion also passes when nothing is logged at all. If the 404 branch threw new CpError('identity_provider_misconfigured', …) directly instead of going through misconfigured(), all 25 tests would still pass. I tried it. So nothing tests the 404 log line, even though the commit message describes it ("The log line carries the same shortened form") and it is the operator's only copy of the fix. Adding expect(logged().join('\n')).toContain('Iv1.fa… (16 chars)') would test it, and would also make the not.toContain check meaningful.

@pdettori
pdettori merged commit 03d2ee8 into rossoctl:main Oct 1, 2026
13 checks passed
@pdettori
pdettori deleted the fix/405-login-idp-hint branch October 1, 2026 15:36
pdettori added a commit to pdettori/moca that referenced this pull request Oct 1, 2026
The research smoke and prompt are on main now, so drop the
merge-first notes. The login step quotes mocactl's new operator-fix
message (rossoctl#405), and the fix list marks it fixed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
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.

mocactl login: turn device_flow_disabled and a mistyped client id (GitHub's 'Not Found') into the operator's fix

2 participants