feat(tpagectl): implement authentication methods #585
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
thwap/thwap-pagesd!585
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/cli-auth"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Implements Phase 6 authentication methods.
#250 / #251 (already implemented, now documented as complete)
Authorization: Bearer <token>fromconfig.server.token(client.go), covering API key/token from config (#250) and Authentik token support (#251 — the Authentik JWT passes through as the bearer and the daemon verifies it).#252 — interactive device-flow
logincommand (new)internal/tpagectl/authpackage with a top-levellogincommand registered on the root.auth.issuerandauth.client_id(mapstructure:"auth"); credentials resolve from--issuer/--client-idflags or config.{issuer}/.well-known/openid-configuration) supplies the device authorization and token endpoints;golang.org/x/oauth2(promoted to a direct dependency) performs the device flow (DeviceAuth+DeviceAccessTokenpolling with a--timeout).config.SetTokenwrite support into theserver.tokenfield of the config file (the fileLoadwould read, or the default$XDG_CONFIG_HOME/tpagectl/.tpagectl.yamlwhen none exists), so subsequent commands authenticate automatically.configgainsWithContext/FromContextcontext helpers (mirroring the client), used to fall back to config credentials.Why
Phase 6 roadmap task #253.
Testing
SetTokenwrites to an existing file (preserving other fields) and creates the default file;auth.*env mapping; context helperslogin,login --helprendersgo test -race ./...passes (23 packages)golangci-lint runcleanBreaking Changes
None.
golang.org/x/oauth2promoted from indirect to a direct dependency.Notes
Token storage here is the interim config-file approach per decision; OS keychain credential management is a separate roadmap task (#257).
Closes #250
Closes #251
Closes #252
Closes #253
Summary
Phase 6 authentication:
logincommand (OIDC device flow) +config.SetTokenwrite support +auth.*config. Verified:go test -race ./...passes (23 packages) andgolangci-lint run ./...is clean. Closes #250-253.Verified:
golang.org/x/oauth2device flow used correctly (DeviceAuth+DeviceAccessToken), token stored via viper write;auth.issuer/auth.client_idresolve from flags then config;WithContext/FromContextfor config mirrors the client.No blocking issues.
Suggestions (filed as issues)
internal/tpagectl/config/config.go(SetToken) – the token is written via viperWriteConfig, whose defaultconfigPermissionsis0o644(confirmed in the module source), leaving the API token world-readable. Filed as #586 (Priority/High)internal/tpagectl/auth/login.go(discoverEndpoints) – useshttp.DefaultClientwith no timeout; a blackholed issuer hangsloginindefinitely. Filed as #587References / Notes
loginruns the rootBeforehook and builds a daemon HTTP client it never uses — extends #582configFromContextinmain.gostill swallows theFromContexterror → nil — extends #549SetTokenwrites to the first config pathLoadfinds; if that is a system path (/etc/tpagectl), an unprivilegedloginwould fail — consider always writing to the user config pathPraise
--timeout-bounded token pollingnewViperrefactor;WithContext/FromContextmirrors the client pattern