Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

feat: add reauthentication - #36

Merged
Derek Kaser (dkaser) merged 3 commits into
mainfrom
reauthenticate
Apr 17, 2025
Merged

feat: add reauthentication#36
Derek Kaser (dkaser) merged 3 commits into
mainfrom
reauthenticate

Conversation

@dkaser

@dkaser Derek Kaser (dkaser) commented Apr 17, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added a "Reauthenticate" button to the Tailscale settings page, allowing users to force reauthentication.
    • Status information now displays whether the connection is established via Tailscale.
  • Improvements
    • Critical buttons such as "Erase" and "Reauthenticate" are now automatically disabled when connected via Tailscale to prevent accidental disconnection.
  • Localization
    • Added new labels and descriptions for the "Reauthenticate" action and connection status in the English interface.

@coderabbitai

coderabbitai Bot commented Apr 17, 2025

Copy link
Copy Markdown

Walkthrough

The changes introduce a new "Reauthenticate" feature to the Tailscale plugin, allowing users to force a reauthentication of their Tailscale node. The UI now displays whether the current connection is established via Tailscale and conditionally disables critical actions (like erasing config or reauthenticating) when connected via Tailscale to prevent accidental disconnection. Backend logic is added to handle immediate key expiration, with safeguards to prevent this action if currently connected via Tailscale. New localization strings are introduced for the updated UI elements and informational labels.

Changes

File(s) Change Summary
src/usr/local/emhttp/plugins/tailscale/include/Pages/Info.php Added a new row to the status table indicating if the connection is established via Tailscale, using the new connectedViaTS() method and a translated label.
src/usr/local/emhttp/plugins/tailscale/include/Pages/Settings.php Added logic to disable "Erase" and new "Reauthenticate" buttons when connected via Tailscale. Introduced a "Reauthenticate" button that triggers a new JS function to expire the Tailscale key, with UI feedback and backend interaction.
src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Info.php Updated getExitNodes() and getCurrentExitNode() to use null coalescing for safer iteration. Added new public method connectedViaTS() to check if the current server IP is among Tailscale IPs.
src/usr/local/emhttp/plugins/tailscale/include/Tailscale/LocalAPI.php Added new public method expireKey() to POST to the Tailscale API endpoint for immediate key expiration.
src/usr/local/emhttp/plugins/tailscale/include/data/Config.php Added a new 'expire-key' action to the POST handler, preventing key expiration if connected via Tailscale, otherwise logging and invoking the new expireKey() method.
src/usr/local/emhttp/plugins/tailscale/locales/en_US.json Added new localization keys and descriptions for "Reauthenticate" button, its context, and the "Connected via Tailscale" informational label.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SettingsPage
    participant JSFunction
    participant ConfigPHP
    participant LocalAPI
    participant InfoPHP

    User->>SettingsPage: Clicks "Reauthenticate" button
    SettingsPage->>JSFunction: Calls expireTailscaleKeyNow()
    JSFunction->>ConfigPHP: POST /plugins/tailscale/include/data/Config.php (action=expire-key)
    ConfigPHP->>InfoPHP: Calls connectedViaTS()
    alt Not connected via Tailscale
        ConfigPHP->>LocalAPI: Calls expireKey()
        LocalAPI->>LocalAPI: POST to tailscale API (set-expiry-sooner?expiry=0)
        ConfigPHP-->>JSFunction: Success (page reload)
    else Connected via Tailscale
        ConfigPHP-->>JSFunction: Error (exception thrown)
    end
    JSFunction->>SettingsPage: Reloads page
Loading

Poem

A rabbit hops through code so bright,
With buttons new and logic tight.
Reauth now just a click away,
But only safe when not mid-relay!
"Connected via" now clear to see—
Tails wiggling in security.
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c23522 and eec293c.

📒 Files selected for processing (6)
  • src/usr/local/emhttp/plugins/tailscale/include/Pages/Info.php (1 hunks)
  • src/usr/local/emhttp/plugins/tailscale/include/Pages/Settings.php (3 hunks)
  • src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Info.php (2 hunks)
  • src/usr/local/emhttp/plugins/tailscale/include/Tailscale/LocalAPI.php (1 hunks)
  • src/usr/local/emhttp/plugins/tailscale/include/data/Config.php (1 hunks)
  • src/usr/local/emhttp/plugins/tailscale/locales/en_US.json (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/usr/local/emhttp/plugins/tailscale/include/Pages/Info.php (2)
src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Utils.php (2)
  • Utils (5-262)
  • printRow (143-146)
src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Info.php (2)
  • tr (45-48)
  • connectedViaTS (402-405)
src/usr/local/emhttp/plugins/tailscale/include/Pages/Settings.php (1)
src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Info.php (2)
  • Info (5-406)
  • connectedViaTS (402-405)
🪛 PHPStan (2.0.3)
src/usr/local/emhttp/plugins/tailscale/include/Pages/Info.php

35-35: Cannot call method connectedViaTS() on mixed.

(method.nonObject)


35-35: Cannot call method tr() on mixed.

(method.nonObject)


35-35: Cannot call method tr() on mixed.

(method.nonObject)


35-35: Cannot call method tr() on mixed.

(method.nonObject)


35-35: Parameter #1 $title of static method Tailscale\Utils::printRow() expects string, mixed given.

(argument.type)


35-35: Parameter #2 $value of static method Tailscale\Utils::printRow() expects string, mixed given.

(argument.type)

src/usr/local/emhttp/plugins/tailscale/include/data/Config.php

236-236: Cannot call method connectedViaTS() on mixed.

(method.nonObject)

src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Info.php

378-378: Argument of an invalid type mixed supplied for foreach, only iterables are supported.

(foreach.nonIterable)


393-393: Argument of an invalid type mixed supplied for foreach, only iterables are supported.

(foreach.nonIterable)


394-394: Cannot access property $ExitNode on mixed.

(property.nonObject)


395-395: Cannot access property $ID on mixed.

(property.nonObject)


395-395: Method Tailscale\Info::getCurrentExitNode() should return string but returns mixed.

(return.type)


404-404: Parameter #2 $haystack of function in_array expects array, mixed given.

(argument.type)

src/usr/local/emhttp/plugins/tailscale/include/Pages/Settings.php

17-17: Cannot access property $Enable on mixed.

(property.nonObject)


18-18: Parameter #1 $tr of class Tailscale\Info constructor expects Tailscale\Translator, mixed given.

(argument.type)


19-19: Cannot call method connectedViaTS() on mixed.

(method.nonObject)


173-173: Cannot call method tr() on mixed.

(method.nonObject)


173-173: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


176-176: Cannot call method tr() on mixed.

(method.nonObject)


176-176: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


178-178: Cannot call method tr() on mixed.

(method.nonObject)


178-178: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


182-182: Cannot call method tr() on mixed.

(method.nonObject)


182-182: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


187-187: Cannot call method tr() on mixed.

(method.nonObject)


187-187: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


189-189: Cannot call method tr() on mixed.

(method.nonObject)


189-189: Cannot call method tr() on mixed.

(method.nonObject)


189-189: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


189-189: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)

🔇 Additional comments (14)
src/usr/local/emhttp/plugins/tailscale/include/Tailscale/Info.php (3)

378-378: Good defensive programming addition.

Adding null coalescing operator to handle potential null values in $this->status->Peer prevents PHP errors when this property isn't set. This addresses the static analysis warning about non-iterable values.

🧰 Tools
🪛 PHPStan (2.0.3)

378-378: Argument of an invalid type mixed supplied for foreach, only iterables are supported.

(foreach.nonIterable)


393-393: Great consistency with null checking.

Similar to the previous change, this adds proper null handling which prevents potential errors when iterating over $this->status->Peer.

🧰 Tools
🪛 PHPStan (2.0.3)

393-393: Argument of an invalid type mixed supplied for foreach, only iterables are supported.

(foreach.nonIterable)


402-405: Well implemented connection detection method.

The new connectedViaTS() method efficiently determines if the current connection is made through Tailscale by checking if the server's IP address is in the list of Tailscale IPs. The null coalescing operators provide good protection against undefined values.

🧰 Tools
🪛 PHPStan (2.0.3)

404-404: Parameter #2 $haystack of function in_array expects array, mixed given.

(argument.type)

src/usr/local/emhttp/plugins/tailscale/include/Pages/Info.php (1)

35-35: Good UI enhancement for connection status.

This new status row clearly shows users whether they're currently connected via Tailscale, which is important context for the reauthentication feature. The conditional display of "yes"/"no" is implemented correctly.

🧰 Tools
🪛 PHPStan (2.0.3)

35-35: Cannot call method connectedViaTS() on mixed.

(method.nonObject)


35-35: Cannot call method tr() on mixed.

(method.nonObject)


35-35: Cannot call method tr() on mixed.

(method.nonObject)


35-35: Cannot call method tr() on mixed.

(method.nonObject)


35-35: Parameter #1 $title of static method Tailscale\Utils::printRow() expects string, mixed given.

(argument.type)


35-35: Parameter #2 $value of static method Tailscale\Utils::printRow() expects string, mixed given.

(argument.type)

src/usr/local/emhttp/plugins/tailscale/include/Tailscale/LocalAPI.php (1)

83-86: Clean implementation of key expiration functionality.

The new expireKey() method uses the existing tailscaleLocalAPI helper function to call the appropriate Tailscale API endpoint. Setting the expiry to 0 forces immediate reauthentication as intended.

src/usr/local/emhttp/plugins/tailscale/include/data/Config.php (1)

235-241: Excellent safety check for the reauthentication feature.

The implementation correctly prevents users from expiring their key while connected via Tailscale, which would break their current connection. This is an important safeguard to prevent self-disconnection.

The logging before key expiration is helpful for troubleshooting, and the method call is properly implemented.

🧰 Tools
🪛 PHPStan (2.0.3)

236-236: Cannot call method connectedViaTS() on mixed.

(method.nonObject)

src/usr/local/emhttp/plugins/tailscale/locales/en_US.json (4)

47-47: LGTM! New localization key added for reauthentication feature.

The addition of the reauthentication feature is properly supported with this new localization key.


62-63: LGTM! Proper JSON structure maintained.

Good practice to add the comma at the end of the previous entry to maintain valid JSON structure while adding a new entry.


63-63: LGTM! Clear description of the reauthentication feature.

The context message clearly explains the purpose and consequences of the reauthentication action, which is important for user awareness.


102-102: LGTM! New status indicator for Tailscale connections.

This new localization key supports the UI feature that informs users when they're connected via Tailscale, which is important for contextual awareness.

src/usr/local/emhttp/plugins/tailscale/include/Pages/Settings.php (4)

13-22: LGTM! Safety feature to prevent disconnection.

This is a good safety mechanism that prevents users from accidentally disconnecting themselves while using Tailscale. The implementation correctly checks if the current connection is via Tailscale using the connectedViaTS() method.

🧰 Tools
🪛 PHPStan (2.0.3)

17-17: Cannot access property $Enable on mixed.

(property.nonObject)


18-18: Parameter #1 $tr of class Tailscale\Info constructor expects Tailscale\Translator, mixed given.

(argument.type)


19-19: Cannot call method connectedViaTS() on mixed.

(method.nonObject)


173-180: LGTM! Reauthentication feature UI implemented.

The reauthentication feature is properly implemented with clear labeling and context. The button is appropriately disabled when connected via Tailscale to prevent self-disconnection.

🧰 Tools
🪛 PHPStan (2.0.3)

173-173: Cannot call method tr() on mixed.

(method.nonObject)


173-173: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


176-176: Cannot call method tr() on mixed.

(method.nonObject)


176-176: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


178-178: Cannot call method tr() on mixed.

(method.nonObject)


178-178: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


189-189: LGTM! Consistent safety mechanism applied.

Good consistency in applying the same safety mechanism to the Erase button, preventing accidental configuration removal while connected via Tailscale.

🧰 Tools
🪛 PHPStan (2.0.3)

189-189: Cannot call method tr() on mixed.

(method.nonObject)


189-189: Cannot call method tr() on mixed.

(method.nonObject)


189-189: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


189-189: Parameter #1 (mixed) of echo cannot be converted to string.

(echo.nonString)


212-216: LGTM! Async function for key expiration.

The implementation of expireTailscaleKeyNow() properly:

  1. Shows a spinner to indicate processing
  2. Makes an async POST request to expire the key
  3. Reloads the page to reflect changes

This provides good user feedback during the operation.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai

coderabbitai Bot commented Apr 17, 2025

Copy link
Copy Markdown

Warning

Docstrings generation is only available on the Pro tier.

@dkaser
Derek Kaser (dkaser) merged commit 105381b into main Apr 17, 2025
@dkaser
Derek Kaser (dkaser) deleted the reauthenticate branch April 17, 2025 01:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant