Skip to content

feat(tls): Secure master-admin with TLS layer LS-245#748

Merged
rolysr merged 1 commit intodevfrom
add-tls-master-saunafs-admin
Feb 18, 2026
Merged

feat(tls): Secure master-admin with TLS layer LS-245#748
rolysr merged 1 commit intodevfrom
add-tls-master-saunafs-admin

Conversation

@rolysr
Copy link
Collaborator

@rolysr rolysr commented Feb 13, 2026

This change introduces a TLS layer to encrypt traffic between the master and the saunafs-admin binary, protecting data in transit and mitigating on-path attacks. For that goal, an optional TLS configuration file path option has been added on all commands for saunafs-admin.

Also, this change allows the shadow metadata servers to start a TLS connection request, which is needed for some saunafs-admin binary to securely communicate to it.

To the reviewers:

  • Notice the changes on src/master/matoclserv.cc which can be divided by two, one is the addition of a protection layer to avoid any possible protocol leak if a client tries to call an *_STARTTLS request if there is an already instantiated tlsSession; the goal of this idea is to force clients to first close their connection reference and then starting a new tls session request from scratch. The second change is that now not only masters can handle *_STARTTLS requests, but shadows can also do it; that change was needed to allowing other components communicating directly to shadow servers through TLS, to have a secure way to protect that communication, like for instance the saunafs-admin binary.
  • Also take a look on the way I exteded the src/common/server_connection.* related files in other to allow optional TLS communication through that connection and when performing any sending or receiving operation from the metadata server.
  • Finally, validate the way I added the corresponding option for TLS related config file on each command of the saunafs-admin. The idea was to make it completely optional and ensuring that all server connection derived instances take it into account if present.

@rolysr rolysr requested a review from Copilot February 13, 2026 18:39
@rolysr rolysr self-assigned this Feb 13, 2026
@rolysr rolysr changed the title feat(tls): Secure master-admin with TLS layer feat(tls): Secure master-admin with TLS layer LS-245 Feb 13, 2026
@rolysr
Copy link
Collaborator Author

rolysr commented Feb 13, 2026

@gemini-code-assist review

@gemini-code-assist
Copy link

Summary of Changes

Hello @rolysr, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the security posture of the system by integrating a TLS layer for communication between the saunafs-admin utility and the master server. It provides a standardized mechanism for administrators to secure their interactions, protecting sensitive data and mitigating potential on-path attacks. The changes extend TLS capabilities to the core networking components and ensure that even shadow metadata servers can leverage encrypted connections, thereby fortifying the overall system's communication channels.

Highlights

  • TLS Encryption for Admin Commands: Introduced an optional --tlsconfigfile command-line option across all saunafs-admin commands, enabling secure, encrypted communication between the admin utility and the master server.
  • Core Connection Layer TLS Support: Implemented TLS session management within the ServerConnection and KeptAliveServerConnection classes, including methods for initiating TLS handshakes and handling encrypted data transmission and reception.
  • Shadow Metadata Server TLS Initiation: Modified the master server's client-to-master service (matoclserv) to allow shadow metadata servers to initiate TLS connection requests, enhancing security for all metadata server interactions.
  • Comprehensive TLS Testing: Added a new system test to validate the end-to-end TLS communication between saunafs-admin and the master server, covering various scenarios including correct/incorrect authentication and shadow server interactions.
Changelog
  • src/admin/chunk_health_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/delete_sessions_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/delete_sessions_command.h
    • Added supportedOptions virtual method declaration.
  • src/admin/dump_config_command.cc
    • Added kTlsMode to supported options.
    • Updated RegisteredAdminConnection::create call to accept a TLS configuration file path.
  • src/admin/info_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/io_limits_status_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/list_chunkservers_command.cc
    • Added kTlsMode to supported options.
    • Updated getChunkserversList calls to pass the TLS configuration file path.
    • Modified getChunkserversList function signature to accept a TLS configuration file path.
  • src/admin/list_chunkservers_command.h
    • Updated getChunkserversList static method declaration to include a TLS configuration file path parameter.
  • src/admin/list_defective_files_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/list_disk_groups_command.cc
    • Added kTlsMode to supported options.
    • Updated ListChunkserversCommand::getChunkserversList call to pass the TLS configuration file path.
  • src/admin/list_disk_groups_command.h
    • Added supportedOptions virtual method declaration.
  • src/admin/list_disks_command.cc
    • Added kTlsMode to supported options.
    • Updated ListChunkserversCommand::getChunkserversList call to pass the TLS configuration file path.
  • src/admin/list_goals_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/list_inotifiers_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/list_metadataservers_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/list_mounts_command.cc
    • Added kTlsMode to supported options.
  • src/admin/list_sessions_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/list_tasks_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/list_tasks_command.h
    • Added supportedOptions virtual method declaration.
  • src/admin/magic_recalculate_metadata_checksum_command.cc
    • Added kTlsMode to supported options.
    • Updated RegisteredAdminConnection::create call to accept a TLS configuration file path.
  • src/admin/manage_locks_command.cc
    • Added kTlsMode to supported options.
    • Updated RegisteredAdminConnection::create call to accept a TLS configuration file path.
  • src/admin/metadataserver_status_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/mount_info_list_command.cc
    • Added kTlsMode to supported options.
    • Updated ServerConnection constructor to accept a TLS configuration file path.
  • src/admin/mount_info_list_command.h
    • Added supportedOptions virtual method declaration.
  • src/admin/promote_shadow_command.cc
    • Added kTlsMode to supported options.
    • Updated RegisteredAdminConnection::create call to accept a TLS configuration file path.
  • src/admin/promote_shadow_command.h
    • Added supportedOptions virtual method declaration.
  • src/admin/ready_chunkservers_count_command.cc
    • Included common/tls_session.h.
    • Added kTlsMode to supported options.
    • Updated ListChunkserversCommand::getChunkserversList call to pass the TLS configuration file path.
  • src/admin/ready_chunkservers_count_command.h
    • Added supportedOptions virtual method declaration.
  • src/admin/registered_admin_connection.cc
    • Modified create method to accept a TLS configuration file path.
    • Updated RegisteredAdminConnection constructor call to pass the TLS configuration file path.
  • src/admin/registered_admin_connection.h
    • Modified create method declaration to accept an optional TLS configuration file path.
    • Updated RegisteredAdminConnection constructor declaration to accept an optional TLS configuration file path.
  • src/admin/reload_config_command.cc
    • Added kTlsMode to supported options.
    • Updated RegisteredAdminConnection::create call to accept a TLS configuration file path.
  • src/admin/reload_config_command.h
    • Added supportedOptions virtual method declaration.
  • src/admin/saunafs_admin_command.cc
    • Defined kTlsMode and kTlsModeDescription constants for the TLS configuration option.
  • src/admin/saunafs_admin_command.h
    • Declared kTlsMode and kTlsModeDescription static constants.
  • src/admin/save_metadata_command.cc
    • Added kTlsMode to supported options.
    • Updated RegisteredAdminConnection::create call to accept a TLS configuration file path.
  • src/admin/stop_master_without_saving_metadata.cc
    • Added kTlsMode to supported options.
    • Updated RegisteredAdminConnection::create call to accept a TLS configuration file path.
  • src/admin/stop_master_without_saving_metadata.h
    • Added supportedOptions virtual method declaration.
  • src/admin/stop_task_command.cc
    • Added kTlsMode to supported options.
    • Updated RegisteredAdminConnection::create call to accept a TLS configuration file path.
  • src/admin/stop_task_command.h
    • Added supportedOptions virtual method declaration.
  • src/common/server_connection.cc
    • Included protocol/cltoma.h and signal.h.
    • Modified sendRequestGeneric to handle TLS sessions using SSL_write.
    • Modified receiveRequestGeneric to handle TLS sessions using SSL_read.
    • Updated ServerConnection constructors to accept an optional TLS configuration file path.
    • Added tlsSession_, tlsConfigFile_, and lastHandshakeError_ member variables.
    • Implemented performTlsHandshake for TLS handshake logic.
    • Implemented startTlsSession to initiate TLS connection requests and set up TLS sessions.
    • Modified connect method to call startTlsSession if a TLS configuration file is provided.
    • Updated sendAndReceive static method to accept a TlsSession pointer.
    • Updated KeptAliveServerConnection's sendAndReceive and NOP thread logic to use the TLS session.
  • src/common/server_connection.h
    • Included common/tls_session.h.
    • Updated ServerConnection constructors to accept an optional TLS configuration file path.
    • Modified sendAndReceive static method signature to include an optional TlsSession pointer.
    • Added tlsSession_, tlsConfigFile_, lastHandshakeError_ member variables.
    • Declared startTlsSession and performTlsHandshake private methods.
    • Updated KeptAliveServerConnection constructors to accept an optional TLS configuration file path.
  • src/master/matoclserv.cc
    • Removed the metadataserver::isMaster() check, allowing matoclserv_starttls to be called regardless of master status.
  • tests/test_suites/ShortSystemTests/test_tls_master_admin_communication.sh
    • Added a new shell script for testing TLS communication between saunafs-admin and the master server.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant security enhancement by adding a TLS layer to encrypt traffic between the master and the saunafs-admin binary. The changes are consistently applied across all admin commands. While the overall approach is sound, I've found some critical functional issues in the new TLS communication logic within ServerConnection, specifically that the function for receiving data over TLS is currently broken and will not work as intended. There is also an opportunity to reduce code duplication across the admin command files, though this is considered a low priority.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an optional TLS layer for saunafs-admin ↔ metadata server communication, and updates the master-side protocol handling to allow shadow metadata servers to accept TLS upgrade requests as well.

Changes:

  • Add --tlsconfigfile support across saunafs-admin commands and pass it through to connections.
  • Extend ServerConnection/RegisteredAdminConnection to initiate STARTTLS and wrap subsequent traffic in TLS.
  • Add a short system test validating saunafs-admin operations over TLS (including shadow connectivity).

Reviewed changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/test_suites/ShortSystemTests/test_tls_master_admin_communication.sh New system test covering saunafs-admin TLS interactions with master and shadow.
src/master/matoclserv.cc Allow handling STARTTLS on non-master personalities (enables shadow TLS upgrade).
src/common/server_connection.h Add optional TLS config path/state to ServerConnection and extend API signatures.
src/common/server_connection.cc Implement STARTTLS request + TLS handshake, and route send/receive via OpenSSL when enabled.
src/admin/saunafs_admin_command.h Define new --tlsconfigfile option constants.
src/admin/saunafs_admin_command.cc Provide --tlsconfigfile option string/description.
src/admin/registered_admin_connection.h Extend RegisteredAdminConnection::create() to accept TLS config path.
src/admin/registered_admin_connection.cc Pass TLS config path through to the underlying connection.
src/admin/info_command.cc Add TLS option and use TLS-enabled ServerConnection.
src/admin/dump_config_command.cc Add TLS option and use TLS-enabled RegisteredAdminConnection.
src/admin/save_metadata_command.cc Add TLS option and use TLS-enabled RegisteredAdminConnection.
src/admin/reload_config_command.h Declare TLS option support.
src/admin/reload_config_command.cc Add TLS option and use TLS-enabled RegisteredAdminConnection.
src/admin/stop_task_command.h Declare TLS option support.
src/admin/stop_task_command.cc Add TLS option and use TLS-enabled RegisteredAdminConnection.
src/admin/stop_master_without_saving_metadata.h Declare TLS option support.
src/admin/stop_master_without_saving_metadata.cc Add TLS option and use TLS-enabled RegisteredAdminConnection.
src/admin/promote_shadow_command.h Declare TLS option support.
src/admin/promote_shadow_command.cc Add TLS option and use TLS-enabled RegisteredAdminConnection.
src/admin/ready_chunkservers_count_command.h Declare TLS option support.
src/admin/ready_chunkservers_count_command.cc Add TLS option and plumb TLS into chunkserver list retrieval.
src/admin/list_chunkservers_command.h Extend chunkserver-list helper to accept TLS config.
src/admin/list_chunkservers_command.cc Add TLS option and pass TLS config into helper.
src/admin/mount_info_list_command.h Declare TLS option support.
src/admin/mount_info_list_command.cc Add TLS option and use TLS-enabled ServerConnection.
src/admin/metadataserver_status_command.cc Add TLS option and use TLS-enabled ServerConnection.
src/admin/manage_locks_command.cc Add TLS option and use TLS-enabled RegisteredAdminConnection.
src/admin/magic_recalculate_metadata_checksum_command.cc Add TLS option and pass TLS config alongside timeout.
src/admin/list_tasks_command.h Declare TLS option support.
src/admin/list_tasks_command.cc Add TLS option and use TLS-enabled ServerConnection.
src/admin/list_sessions_command.cc Add TLS option and use TLS-enabled ServerConnection.
src/admin/list_mounts_command.cc Add TLS option to supported options list.
src/admin/list_metadataservers_command.cc Add TLS option and use TLS-enabled ServerConnection for initial query.
src/admin/list_inotifiers_command.cc Add TLS option and use TLS-enabled ServerConnection.
src/admin/list_goals_command.cc Add TLS option and use TLS-enabled ServerConnection.
src/admin/list_disks_command.cc Add TLS option and pass TLS config into chunkserver list retrieval.
src/admin/list_disk_groups_command.h Declare TLS option support.
src/admin/list_disk_groups_command.cc Add TLS option and pass TLS config into chunkserver list retrieval.
src/admin/list_defective_files_command.cc Add TLS option and use TLS-enabled ServerConnection.
src/admin/io_limits_status_command.cc Add TLS option and use TLS-enabled ServerConnection.
src/admin/delete_sessions_command.h Declare TLS option support.
src/admin/delete_sessions_command.cc Add TLS option and use TLS-enabled ServerConnection.
src/admin/chunk_health_command.cc Add TLS option and use TLS-enabled ServerConnection.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a TLS layer to secure communication between saunafs-admin and the master/shadow servers, which is a great security enhancement. The implementation correctly adds the --tlsconfigfile option across all relevant admin commands and modifies the connection logic to handle TLS sessions.

I've found a critical issue in the TLS data receiving logic that could lead to data corruption or crashes. Please see my detailed comment for suggestions on how to address this, incorporating established rules regarding blocking I/O and graceful shutdowns.

@rolysr rolysr force-pushed the add-tls-master-saunafs-admin branch from 6096638 to 6eda0c1 Compare February 13, 2026 19:00
@rolysr
Copy link
Collaborator Author

rolysr commented Feb 13, 2026

@gemini-code-assist review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a significant security enhancement by adding a TLS layer to encrypt traffic between saunafs-admin and the master/shadow servers. The implementation involves adding a --tlsconfigfile option to nearly all admin commands and modifying the ServerConnection class to handle TLS handshakes and encrypted I/O. The changes are extensive and well-tested with a new integration test.

However, I have identified a few important issues that should be addressed:

  • High Severity: The client-side TLS implementation in server_connection.cc uses a large, fixed-size buffer for receiving messages, which could be a denial-of-service vector.
  • High Severity: The server-side STARTTLS handling in matoclserv.cc does not check if a TLS session is already active, which could lead to resource leaks or undefined behavior if a client sends the request multiple times.
  • Omission: The list-mounts command has the --tlsconfigfile option added to its supported options, but the implementation in run() was not updated to use it, meaning it will not establish a TLS connection. This appears to be an oversight.

I have provided detailed comments on the high-severity issues. Addressing these will improve the robustness, efficiency, and security of the new TLS functionality.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 43 out of 43 changed files in this pull request and generated 5 comments.

@rolysr rolysr force-pushed the add-tls-master-saunafs-admin branch 2 times, most recently from 0fd54a8 to e3f2503 Compare February 13, 2026 20:16
@rolysr rolysr marked this pull request as ready for review February 13, 2026 21:30
@rolysr rolysr force-pushed the add-tls-master-saunafs-admin branch 4 times, most recently from 3bd0f91 to ea8c608 Compare February 18, 2026 10:05
Copy link
Contributor

@lgsilva3087 lgsilva3087 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, please see my minor comments.

@rolysr rolysr force-pushed the add-tls-master-saunafs-admin branch from ea8c608 to 8522b23 Compare February 18, 2026 11:10
Copy link
Collaborator

@dmga44 dmga44 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, @rolysr .

Please check my minor suggestion.

@rolysr rolysr force-pushed the add-tls-master-saunafs-admin branch from 8522b23 to 7c64523 Compare February 18, 2026 12:01
This change introduces a TLS layer to encrypt traffic between the master
and the saunafs-admin binary, protecting data in transit and mitigating
on-path attacks. For that goal, an optional TLS configuration file path
option has been added on all commands for saunafs-admin.

Also, this change allows the shadow metadata servers to start a TLS
connection request, which is needed for some saunafs-admin binary
to securely communicate to it.

Signed-off-by: Rolando Sánchez Ramos <rolysr@leil.io>
@rolysr rolysr force-pushed the add-tls-master-saunafs-admin branch from 7c64523 to 20aa492 Compare February 18, 2026 15:27
@rolysr rolysr merged commit 6ed4f3a into dev Feb 18, 2026
11 checks passed
@rolysr rolysr deleted the add-tls-master-saunafs-admin branch February 18, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants