Skip to content

Add protected mode. #1190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add protected mode. #1190

wants to merge 1 commit into from

Conversation

prvyk
Copy link
Contributor

@prvyk prvyk commented May 7, 2025

Redis starts by default in 'protected mode' - binds to localhost only unless auth is specified. This PR adds the same to Garnet, except we don't check for auth - the user can explicitly bind elsewhere, and this override protected mode binding.

Docker builds automatically disable protected mode and so bind by default to 0.0.0.0.

Note: CommandLineBooleanOption is added to get compatibility with redis's yes/no parsing.

@prvyk prvyk force-pushed the protectedmode branch from f08b6a4 to 90d3c36 Compare May 7, 2025 15:18
@prvyk prvyk force-pushed the protectedmode branch from 90d3c36 to 05a2abc Compare May 8, 2025 18:01
@badrishc badrishc requested a review from Copilot May 8, 2025 19:39
Copy link
Contributor

@Copilot 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 introduces support for a "protected mode" configuration similar to Redis, allowing Garnet to bind to localhost by default unless overridden. Key changes include updating the test configuration to disable protected mode, adding a new CommandLineBooleanOption for protected mode, and updating the address parser and Dockerfiles to factor in this new setting.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/Garnet.test/redis.conf Updated protected mode setting (changed from yes to no) while leaving an inconsistent comment.
test/Garnet.test/GarnetServerConfigTests.cs Added test assertion for the protected mode flag.
libs/host/defaults.conf Added a default protected mode setting ("yes") for non-Docker scenarios.
libs/host/Configuration/TypeConverters.cs Enhanced type conversion to support CommandLineBooleanOption.
libs/host/Configuration/Redis/RedisOptions.cs Introduced a new Redis option for protected mode.
libs/host/Configuration/Options.cs Added option validation and integrated protected mode flag into configuration.
libs/host/Configuration/CommandLineTypes.cs Defined the CommandLineBooleanOption enum with aliases for true/false.
libs/common/Format.cs Updated TryParseAddressList to handle the new protected mode parameter.
Dockerfiles (various) Modified ENTRYPOINTs to force disable protected mode in Docker builds.
Comments suppressed due to low confidence (1)

test/Garnet.test/redis.conf:108

  • The comment indicates that protected mode is enabled by default, but the configuration immediately below sets it to 'no'. Please update the comment to accurately reflect the intended default behavior for this test configuration.
# By default protected mode is enabled. You should disable it only if

@badrishc badrishc requested a review from vazois May 8, 2025 19:41
@@ -533,6 +533,10 @@ internal sealed class Options
[Option("enable-debug-command", Required = false, HelpText = "Enable DEBUG command for 'no', 'local' or 'all' connections")]
public ConnectionProtectionOption EnableDebugCommand { get; set; }

[OptionValidation]
[Option("protected-mode", Required = false, HelpText = "Enable protected mode.")]
public CommandLineBooleanOption ProtectedMode { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need Garnet's version of options to be CommandLineBooleanOption instead of a simple bool. RedisOptions makes sense for compatibility with redis.conf.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think CommandLineBooleanOption may be fine here, leaving the comment for discussion and input from others.

Copy link
Contributor Author

@prvyk prvyk May 9, 2025

Choose a reason for hiding this comment

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

The reason was to allow CommandLine.Core to parse 'yes' as true, so '--protected-mode yes/no' parsers as true/false respectively. I couldn't find any nicer way of enhancing the parser.

If we don't care for that compatibility, I can switch to a bool and switch the docker definition to '--protected-mode false'. Let's see what others say...

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.

2 participants