[PR #6325] [management] Make ssh JWT timeout configurable #25418

Open
opened 2026-08-05 07:05:59 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6325
Author: @allomanta
Created: 6/2/2026
Status: 🔄 Open

Base: mainHead: ssh-jwt-timeout


📝 Commits (10+)

  • b6d35b1 Add max token age to settings
  • e3bc429 Add token age to http api
  • d2a324d Add token age to handler
  • 78055e5 Validate the max token age and update peers
  • 0b3c402 Wire token age to jwtconfig builder
  • 53c576a Tests
  • 0eb09b5 Fix sql query
  • 0108469 Update ssh jwt settings while running
  • 14c5af3 Tests
  • 9bad6b8 Track jwtconfig changes to prevent stale configs

📊 Changes

18 files changed (+503 additions, -75 deletions)

View changed files

📝 client/internal/engine_ssh.go (+17 -7)
📝 client/internal/engine_test.go (+61 -0)
📝 client/server/jwt_cache.go (+102 -11)
client/server/jwt_cache_test.go (+94 -0)
📝 client/server/server.go (+1 -1)
📝 client/ssh/server/jwt_test.go (+24 -0)
📝 client/ssh/server/server.go (+60 -48)
📝 management/internals/shared/grpc/conversion.go (+9 -4)
📝 management/internals/shared/grpc/conversion_test.go (+24 -1)
📝 management/server/account.go (+4 -1)
📝 management/server/account_test.go (+34 -0)
📝 management/server/http/handlers/accounts/accounts_handler.go (+6 -0)
📝 management/server/http/handlers/accounts/accounts_handler_test.go (+47 -0)
📝 management/server/store/sql_store.go (+6 -2)
📝 management/server/store/sql_store_get_account_test.go (+2 -0)
📝 management/server/types/settings.go (+4 -0)
📝 shared/management/http/api/openapi.yml (+5 -0)
📝 shared/management/http/api/types.gen.go (+3 -0)

📄 Description

Describe your changes

Currently the JWToken's max age for netbird ssh is always set to be 10 minutes on the server, which was updated from 5 minutes in #5471. When used with an SSO like Authentik this can lead to validation issues if a user calls netbird up with an --ssh-jwt-cache-ttl larger than 600.
This PR adds routing for the tokens MaxAge config value such that it can be configured by the management UI. I can make a related PR for the UI if this is indeed desired. Currently we've tested locally with a fork where I just added a field to the authentication tab.

I also think that #6197 might be related to this.

#5449, #5471, maybe #6197

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)
    I believe that documentation only needs to be changed if the management UI also updates as this doesn't change anything on its own. But I'm happy to update any documentation if that's an incorrect assumption

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • New Features

    • SSH JWT settings can be updated at runtime without restarting the SSH service; configurable SSH JWT max token age respected.
    • JWT cache now validates tokens using iat/exp claims and honors the current TTL when serving cached tokens.
  • Documentation

    • API schema and client models expose SSH JWT max token age.
  • Tests

    • Added tests for runtime JWT reconfiguration, JWT cache claim/TTL behavior, and max-token-age validation/persistence.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/6325 **Author:** [@allomanta](https://github.com/allomanta) **Created:** 6/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `ssh-jwt-timeout` --- ### 📝 Commits (10+) - [`b6d35b1`](https://github.com/netbirdio/netbird/commit/b6d35b132edc59c7da02d58ce5335009b69dc572) Add max token age to settings - [`e3bc429`](https://github.com/netbirdio/netbird/commit/e3bc429ca1e869d1df1af8c1e5f427df85ae14a9) Add token age to http api - [`d2a324d`](https://github.com/netbirdio/netbird/commit/d2a324d566a6e9cec5e5adc72d72d5c26a1bb08d) Add token age to handler - [`78055e5`](https://github.com/netbirdio/netbird/commit/78055e5d1b7b4ebf268f7eda77cea8f21fcb36f1) Validate the max token age and update peers - [`0b3c402`](https://github.com/netbirdio/netbird/commit/0b3c4024d737a929b784f579195f00295b4861a0) Wire token age to jwtconfig builder - [`53c576a`](https://github.com/netbirdio/netbird/commit/53c576a52584a8c6fdb1766e02dba719334d2eba) Tests - [`0eb09b5`](https://github.com/netbirdio/netbird/commit/0eb09b5b6795838853b8e46b263afa992bef8892) Fix sql query - [`0108469`](https://github.com/netbirdio/netbird/commit/0108469edf5e324504672ea1c7da47c42e650a38) Update ssh jwt settings while running - [`14c5af3`](https://github.com/netbirdio/netbird/commit/14c5af3c114f272daf55b4a39436e4f14059e43a) Tests - [`9bad6b8`](https://github.com/netbirdio/netbird/commit/9bad6b8c42ed775ddc87d88af8f724bf35c60c72) Track jwtconfig changes to prevent stale configs ### 📊 Changes **18 files changed** (+503 additions, -75 deletions) <details> <summary>View changed files</summary> 📝 `client/internal/engine_ssh.go` (+17 -7) 📝 `client/internal/engine_test.go` (+61 -0) 📝 `client/server/jwt_cache.go` (+102 -11) ➕ `client/server/jwt_cache_test.go` (+94 -0) 📝 `client/server/server.go` (+1 -1) 📝 `client/ssh/server/jwt_test.go` (+24 -0) 📝 `client/ssh/server/server.go` (+60 -48) 📝 `management/internals/shared/grpc/conversion.go` (+9 -4) 📝 `management/internals/shared/grpc/conversion_test.go` (+24 -1) 📝 `management/server/account.go` (+4 -1) 📝 `management/server/account_test.go` (+34 -0) 📝 `management/server/http/handlers/accounts/accounts_handler.go` (+6 -0) 📝 `management/server/http/handlers/accounts/accounts_handler_test.go` (+47 -0) 📝 `management/server/store/sql_store.go` (+6 -2) 📝 `management/server/store/sql_store_get_account_test.go` (+2 -0) 📝 `management/server/types/settings.go` (+4 -0) 📝 `shared/management/http/api/openapi.yml` (+5 -0) 📝 `shared/management/http/api/types.gen.go` (+3 -0) </details> ### 📄 Description ## Describe your changes Currently the JWToken's max age for netbird ssh is always set to be 10 minutes on the server, which was updated from 5 minutes in #5471. When used with an SSO like Authentik this can lead to validation issues if a user calls netbird up with an --ssh-jwt-cache-ttl larger than 600. This PR adds routing for the tokens MaxAge config value such that it can be configured by the management UI. I can make a related PR for the UI if this is indeed desired. Currently we've tested locally with a fork where I just added a field to the authentication tab. I also think that #6197 might be related to this. ## Issue ticket number and link #5449, #5471, maybe #6197 ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) - [ ] This change does **not** modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — **OR** I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See [CONTRIBUTING.md](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTING.md#discuss-changes-with-the-netbird-team-first). > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) I believe that documentation only needs to be changed if the management UI also updates as this doesn't change anything on its own. But I'm happy to update any documentation if that's an incorrect assumption ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * SSH JWT settings can be updated at runtime without restarting the SSH service; configurable SSH JWT max token age respected. * JWT cache now validates tokens using iat/exp claims and honors the current TTL when serving cached tokens. * **Documentation** * API schema and client models expose SSH JWT max token age. * **Tests** * Added tests for runtime JWT reconfiguration, JWT cache claim/TTL behavior, and max-token-age validation/persistence. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 07:05:59 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#25418