Skip to content

Implement AUTH command#268

Merged
buraksezer merged 18 commits intomasterfrom
feat/authentication
May 26, 2025
Merged

Implement AUTH command#268
buraksezer merged 18 commits intomasterfrom
feat/authentication

Conversation

@buraksezer
Copy link
Copy Markdown
Collaborator

This PR provides an implementation Redis-style AUTH command.

Supported by cluster client:

func WithCredentials(username, password string) ClusterClientOption {
	return func(cfg *clusterClientConfig) {
		cfg.authentication = &config.Authentication{
			Enabled:  true,
			Username: username,
			Password: password,
		}
	}
}

Embedded client is authenticated by default.

The configuration is quite simple:

authentication:
  enabled: false
  username: "your-username"
  password: "your-password"

Olric returns the following error if the client is unauthorized:

(error) NOAUTH authentication required

buraksezer added 18 commits May 25, 2025 20:25
Introduced functionality to handle the AUTH command, including a new `Auth` type with associated methods for command creation and parsing. Added relevant tests to ensure correct behavior and error handling for invalid arguments.
Introduced optional username/password-based authentication for client connections. Updated the configuration, command handlers, and internal server logic to enforce authentication when enabled. Includes tests and error handling for invalid credentials.
Renamed "precond" to "precondition" for clearer semantics and improved readability. Added support for setting Redis protocol version to 2 in client configuration.
Introduced an `Authentication` struct to the client configuration, enabling username/password-based authentication. This includes validation, sanitization, and integration with Redis client options. Adjusted related code to ensure proper handling of authentication settings.
Introduce an `authentication` field in the `clusterClientConfig` and a `WithCredentials` option to enable authentication via username and password. The authentication configuration is applied to the client during initialization if provided.
Added detailed comments and descriptions to structs, methods, and errors across multiple files, improving code readability and maintainability. Minor grammar corrections were also made in existing comments to ensure consistency and clarity.
Updated go-redis to v9.8.0 and golang.org/x/sync to v0.14.0 in go.mod and go.sum. These changes ensure the project uses newer versions with potential bug fixes and improvements.
Added a mechanism to propagate client authentication settings when enabled and implemented a new test suite for authentication scenarios. Fixed a semaphore acquisition error in the routing table and an issue in quorum checking logic. Minor typo correction in a log message was also applied.
Introduce an `errAuthRequired` error in the server code to signal when authentication is needed. Update configuration files to include an `authentication` section, allowing authentication to be enabled or disabled with customizable credentials. Default settings disable authentication for flexibility during setup.
Replaced direct error comparisons with `errors.Is` for better error handling. Added detailed comments and refined docstrings for several functions to enhance clarity and maintainability. Minor grammar fixes were made in descriptions.
Replaced `Enabled` with `RequirePass` and introduced `Enabled2` for improved authentication logic. This ensures consistency in configuration parsing and simplifies enabled checks by leveraging `RequirePass`.
Refactored the authentication logic to use only the `RequirePass` field, removing the `Username` and `Password` fields across the codebase. Updated related checks and tests to align with the new structure, and replaced `Enabled2` with a simplified `Enabled` method. This streamlines the configuration and reduces complexity.
Updated all references to the authentication field `RequirePass` across the codebase to `Password` for consistency and clarity. This includes changes in struct definitions, method implementations, and test configurations.
Removed usernames from the authentication flow, simplifying logic and function signatures. Updated related tests, error messages, and configuration files to reflect the password-only model.
Authentication settings have been updated to simplify the configuration by removing the disabled "username" field. Supporting functions and comments were added to manage the password-based authentication flow in the system. This change enhances clarity and prepares for future improvements.
Updated the error message text for authentication to use a capitalized format for consistency. Clarified the comment describing the `authCommandHandler` function to better convey its purpose and behavior.
Clarify the purpose of the Config struct and add documentation for the Authentication field to describe its role in securing access with authentication settings. This improves code readability and understanding for developers.
Adjusted the test error message in system_test.go to match the updated command format. Removed dead links related to Kubernetes and Docker Compose from the README, streamlining the documentation structure.
@buraksezer buraksezer merged commit 7621009 into master May 26, 2025
4 checks passed
@buraksezer buraksezer deleted the feat/authentication branch May 26, 2025 15:57
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.

1 participant