[PR #7056] [infrastructure] Generate a session cookie encryption key on fresh self-hosted installs #29502

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/7056
Author: @Optic00
Created: 8/4/2026
Status: 🔄 Open

Base: mainHead: codex/harden-session-cookie-key-review


📝 Commits (8)

  • ea9c554 test: cover self-hosted session cookie key defaults
  • c7cec82 [infrastructure] protect embedded IdP session cookies by default
  • 7482dde [infrastructure] configure enterprise IdP cookie encryption
  • 9268e20 test: safely source infrastructure installers
  • 73b928f test: validate session keys in their YAML sections
  • 55a123d test: validate datastore encryption keys
  • a95f558 test: simplify session cookie key checks
  • 70cf766 Merge branch 'main' into codex/harden-session-cookie-key-review

📊 Changes

3 files changed (+15 additions, -1 deletions)

View changed files

📝 .github/workflows/test-infrastructure-files.yml (+9 -0)
📝 infrastructure_files/getting-started-enterprise.sh (+2 -0)
📝 infrastructure_files/getting-started.sh (+4 -1)

📄 Description

Describe your changes

The community and enterprise bootstrap scripts now generate a dedicated server.auth.sessionCookieEncryptionKey from 32 random bytes for fresh installations.
The key is Base64-encoded, persisted independently from the datastore encryption key, and reused from the generated configuration after restarts.

The community script now also creates config.yaml with mode 0600 before writing it, matching the existing enterprise behavior.

The server already supports the session cookie encryption key, but the bootstrap scripts left it unset.
This adds defense-in-depth for newly generated deployments while preserving the existing server-side nonce validation.
Because this only changes newly generated configuration, existing installations and sessions are unchanged.

A focused regression test checks key presence, decoded length, separation from the datastore key, YAML placement, and file mode for both scripts.
It is included in the infrastructure workflow.

Closes #7054

Stack

None.

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)
  • I ran and tested this change locally - I did not rely on CI to find out whether it works
  • This PR has a single purpose (not a fix + refactor + feature in one)
  • This change is a trivial fix, OR it links an issue the NetBird team agreed on beforehand. Changes to the public API, gRPC protocols, functionality behavior, CLI / service flags, or new features always need that agreement first. 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 because it only hardens generated secret material and file permissions for fresh bootstrap-script output.

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

Not applicable.

Summary by CodeRabbit

  • Security Enhancements
    • Improved session security by generating dedicated encryption keys during setup.
    • Protected generated configuration files with restricted permissions.
    • Added verification checks to ensure secure session-cookie configuration is applied consistently across setup scripts.

🔄 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/7056 **Author:** [@Optic00](https://github.com/Optic00) **Created:** 8/4/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `codex/harden-session-cookie-key-review` --- ### 📝 Commits (8) - [`ea9c554`](https://github.com/netbirdio/netbird/commit/ea9c554dfccbbbf09e2c85f0c1241e935a11e77d) test: cover self-hosted session cookie key defaults - [`c7cec82`](https://github.com/netbirdio/netbird/commit/c7cec8232429e7572d340cd3e63a61ac866a02f3) [infrastructure] protect embedded IdP session cookies by default - [`7482dde`](https://github.com/netbirdio/netbird/commit/7482dde5df6b08b92992654ff342658d5a9c1c04) [infrastructure] configure enterprise IdP cookie encryption - [`9268e20`](https://github.com/netbirdio/netbird/commit/9268e20203296575ebf4bcde9b4ceabe94f6935a) test: safely source infrastructure installers - [`73b928f`](https://github.com/netbirdio/netbird/commit/73b928f44ff1b9428f243fe599f18c10ff82d16b) test: validate session keys in their YAML sections - [`55a123d`](https://github.com/netbirdio/netbird/commit/55a123d0071be47398a0a0412d2adec46e391cbd) test: validate datastore encryption keys - [`a95f558`](https://github.com/netbirdio/netbird/commit/a95f558deb46ae6ef352bb08d2b5df084f78811b) test: simplify session cookie key checks - [`70cf766`](https://github.com/netbirdio/netbird/commit/70cf766d8a22eee738fc5d60adfb433b27803434) Merge branch 'main' into codex/harden-session-cookie-key-review ### 📊 Changes **3 files changed** (+15 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/test-infrastructure-files.yml` (+9 -0) 📝 `infrastructure_files/getting-started-enterprise.sh` (+2 -0) 📝 `infrastructure_files/getting-started.sh` (+4 -1) </details> ### 📄 Description ## Describe your changes The community and enterprise bootstrap scripts now generate a dedicated `server.auth.sessionCookieEncryptionKey` from 32 random bytes for fresh installations. The key is Base64-encoded, persisted independently from the datastore encryption key, and reused from the generated configuration after restarts. The community script now also creates `config.yaml` with mode `0600` before writing it, matching the existing enterprise behavior. The server already supports the session cookie encryption key, but the bootstrap scripts left it unset. This adds defense-in-depth for newly generated deployments while preserving the existing server-side nonce validation. Because this only changes newly generated configuration, existing installations and sessions are unchanged. A focused regression test checks key presence, decoded length, separation from the datastore key, YAML placement, and file mode for both scripts. It is included in the infrastructure workflow. ## Issue ticket number and link Closes #7054 ## Stack <!-- branch-stack --> None. ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) - [x] I ran and tested this change locally - I did not rely on CI to find out whether it works - [x] This PR has a single purpose (not a fix + refactor + feature in one) - [x] This change is a trivial fix, **OR** it links an issue the NetBird team agreed on beforehand. Changes to the public API, gRPC protocols, functionality behavior, CLI / service flags, or new features always need that agreement first. See [CONTRIBUTING.md](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTING.md#ticket-first-pr-second). > 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 because it only hardens generated secret material and file permissions for fresh bootstrap-script output. ### Docs PR URL (required if "docs added" is checked) Not applicable. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Security Enhancements** * Improved session security by generating dedicated encryption keys during setup. * Protected generated configuration files with restricted permissions. * Added verification checks to ensure secure session-cookie configuration is applied consistently across setup scripts. <!-- 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 08:08:11 -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#29502