Repository navigation
Import existing pgEdge Starfleet databases and branches as servers. - #10920
AntTheLimey wants to merge 4 commits into
Conversation
…t credentials rather than a pgEdge account sign-in. pgadmin-org#10746 The Starfleet deployment wizard now lets the user choose between signing in with their pgEdge account and entering API client credentials. Sign-in uses the OAuth 2.0 device authorization grant (RFC 8628) against the pgEdge Auth0 tenant. pgAdmin requests a device code and shows the user code and sign-in link; the browser then polls a pgAdmin endpoint that makes at most one token request per call and honours the interval and slow_down responses, so no request thread waits on the user. The tokens stay in the server-side session, and the user chooses a tenant when the account has more than one; requests then carry the X-pgEdge-Selected-Tenant header. The deployment job receives the access token, and the refresh token where there is one, through its environment in the same way as the API client secret, never on its command line. The refresh token goes to the job alone, as Auth0 rotates it on use, and the job revokes it when it finishes; an unused one is revoked when the wizard's session is cleared. The Auth0 applications are configured per Starfleet API URL in STARFLEET_AUTH0_APPS in config.py. Closes pgadmin-org#10746
…efresh token in the session until the deployment job has started.
Add an Import from pgEdge Starfleet... option to the server group menu. It signs in the same way as the deployment wizard, lists the tenant's databases and branches with whether this address can reach them, and adds or updates a server for each one chosen, optionally saving the password and adding this address to a database's allowlist.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
dpage
left a comment
There was a problem hiding this comment.
I've reviewed only the last commit (75685a7), as asked. Overall it's in good shape: the request validation is careful (the server group belongs to the user, IDs are checked before they go into API paths, and the item count is capped), passwords stay out of responses and logs, and the allowlist update rebuilds the rules from their documented fields. I checked the API calls against the managed API spec, and the user_type values, bare-address CIDRs and replace-on-PATCH behaviour all match it. The backend tests pass locally (7/7). One thing should be fixed before this goes in:
Should fix: importing an item that has no connection details reports "Unexpected response from pgEdge Starfleet." (web/pgadmin/misc/cloud/starfleet/inventory.py:149)
_connection() indexes detail['connection'], so a missing connection raises KeyError, which the MALFORMED handler at line 223 turns into the generic message. According to the API spec, this is a normal response rather than a malformed one in two cases:
- A branch's connection "is present only while the branch is available", and the same goes for a database that is still being created or is failed.
application_read_only"is the read-only role the AI services connect as; a database created before it existed does not have one".
The dialog makes the first case likely, because loadInventory pre-selects every reachable item whatever its status (StarfleetImportDialog.jsx:91), so a reachable database that is still creating is ticked by default and then fails with a message that gives the user nothing to act on. I'd suggest two changes: check for the connection explicitly and give a message that names the item's status, or says the chosen role may not exist on that database; and pre-select only items whose status is available. A test for an item without a connection would cover both.
Suggestion: re-importing renames a server the user has renamed (inventory.py:116)
upsert_server sets server.name on every import, so a user who renamed an imported server, or added a server by hand with the same host, port and user name, gets the Starfleet label back. Keeping the existing name when updating seems kinder; the connection details are what actually need refreshing.
Suggestion: the allowlist message could say the change is not immediate (inventory.py:191)
The spec says an allowlist change moves the database to modifying while the rules are pushed to the ingress, so "Added {0} to the database's allowlist." can show before the address is actually admitted, and an immediate connection attempt may fail. Something like "Added {0} to the database's allowlist; it takes effect once the database is available again." would head off that confusion.
Depends on #10832, and is built on its branch: until that merges, its three commits show here too. Review only the last commit.
What changed
Adds Import from pgEdge Starfleet... to the server group menu. The dialog signs in with #10832's credentials form (pgEdge account or API client), lists the tenant's databases and branches with whether this address can reach them, and adds or updates a server for each one chosen. It can also save the password, subject to
ALLOW_SAVE_PASSWORD, and add this address to a database's allowlist. Closing the dialog signs out and revokes the refresh token, as the wizard does.Shared code touched:
_with_clientgains an opt-in 401 mode for the dialog (the wizard keeps its behaviour),signin_optionsalso returnsallow_save_password, andStarfleetClientgainspatch().Gates
regression/runtests.py --pkg misc.cloud.starfleet: 7 passed, 0 failedjest regression/javascript/misc/cloud: 42 passedeslint -c .eslintrc.jsandpycodestyleon the changed files: cleanAn independent review found two defects: the refresh token was not revoked on close, and sign-in errors were not shown. Both are fixed, with tests.
Risks