-
Notifications
You must be signed in to change notification settings - Fork 796
fix(cli): credentials to flat ~/.config/dimos-credentials, plain text #3549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,9 @@ | |
| Device-code flow (RFC 8628 shaped) against login.dimensional.org — built for robots: | ||
| no browser or clipboard needed on this machine. The CLI prints an 8-character code, | ||
| you approve it from any signed-in browser (laptop, phone), and the minted API key is | ||
| stored in the system keyring, falling back to a 0600 file (`CREDENTIALS_PATH`) on | ||
| headless machines with no keyring backend. `DIMOS_API_KEY` (via GlobalConfig) | ||
| overrides any stored login. | ||
| stored in the system keyring, falling back to a plain-text 0600 file | ||
| (`CREDENTIALS_PATH`, just the key) on headless machines with no keyring | ||
| backend. `DIMOS_API_KEY` (via GlobalConfig) overrides any stored login. | ||
| """ | ||
|
|
||
| import json | ||
|
|
@@ -62,28 +62,27 @@ def _keyring() -> ModuleType | None: | |
| return None | ||
|
|
||
|
|
||
| def _store(creds: dict[str, str]) -> str: | ||
| """Persist credentials; returns a human-readable location for the login message.""" | ||
| blob = json.dumps(creds) | ||
| def _store(key: str) -> str: | ||
| """Persist the API key; returns a human-readable location for the login message.""" | ||
| if kr := _keyring(): | ||
| kr.set_password(_KEYRING_SERVICE, _KEYRING_USER, blob) | ||
| kr.set_password(_KEYRING_SERVICE, _KEYRING_USER, key) | ||
| return "system keyring" | ||
| CREDENTIALS_PATH.parent.mkdir(parents=True, exist_ok=True) | ||
| # No keyring backend (typical on robots): owner-only file, the same convention | ||
| # gh / aws / kubectl use for exactly this situation. | ||
| fd = os.open(CREDENTIALS_PATH, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600) | ||
| with os.fdopen(fd, "w") as f: | ||
| f.write(blob) | ||
| f.write(key + "\n") | ||
| return str(CREDENTIALS_PATH) | ||
|
|
||
|
|
||
| def _load() -> dict[str, str] | None: | ||
| def _load() -> str | None: | ||
| if kr := _keyring(): | ||
| if blob := kr.get_password(_KEYRING_SERVICE, _KEYRING_USER): | ||
| return cast("dict[str, str]", json.loads(blob)) | ||
| if key := kr.get_password(_KEYRING_SERVICE, _KEYRING_USER): | ||
| return cast("str", key) | ||
| try: | ||
| return cast("dict[str, str]", json.loads(CREDENTIALS_PATH.read_text())) | ||
| except (OSError, ValueError): | ||
| return CREDENTIALS_PATH.read_text().strip() or None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ArtifactsFocused legacy JSON credential end-to-end test source
Baseline scalar credential execution output
Legacy JSON credential execution output
|
||
| except OSError: | ||
| return None | ||
|
|
||
|
|
||
|
|
@@ -103,8 +102,7 @@ def api_key() -> str | None: | |
| """The credential for cloud calls: DIMOS_API_KEY first, then the stored login.""" | ||
| if global_config.dimos_api_key: | ||
| return global_config.dimos_api_key | ||
| creds = _load() | ||
| return creds.get("api_key") if creds else None | ||
| return _load() | ||
|
|
||
|
|
||
| def login() -> None: | ||
|
|
@@ -117,7 +115,7 @@ def login() -> None: | |
| time.sleep(d["interval"]) | ||
| r = _post("/auth/token", device_code=d["device_code"]) | ||
| if r["status"] == "ok": | ||
| where = _store({"api_key": r["api_key"], "email": r["email"]}) | ||
| where = _store(r["api_key"]) | ||
| typer.echo(f"Logged in as {r['email']} (key {r['key_id']}…, stored in {where})") | ||
| return | ||
| if r["status"] in ("denied", "expired"): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users authenticated by the preceding implementation have
{"api_key":"...","email":"..."}stored in the legacy file or keyring._load()now returns that whole object as a string, soapi_key()passes it through andwhoami()sendsBearer {"api_key":...}instead of the API key. Existing logged-in users will therefore be rejected until they manually log in again. Decode the legacy JSON shape when it contains a stringapi_key(optionally rewriting it in the new format), while preserving new plain-text credentials.Artifacts
Isolated legacy JSON credential reproduction script
Before-change legacy JSON credential behavior
Current-change legacy JSON credential behavior