Skip to content
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

feature: TLS redis tests #105

Merged
merged 12 commits into from
Nov 20, 2024
Merged

feature: TLS redis tests #105

merged 12 commits into from
Nov 20, 2024

Conversation

rustatian
Copy link
Member

@rustatian rustatian commented Nov 20, 2024

Reason for This PR

  • Add TLS test for the new Redis-TLS functionality

Description of Changes

  • Update GHA, include bare-bone redis-server with and without TLS ports

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration for Redis with TLS support.
    • Added a new test function for testing Redis with TLS.
    • Added a script to automate the generation of test certificates.
    • Updated Redis configuration files to support new address and logging settings.
  • Bug Fixes

    • Improved the logic for client certificate handling in TLS configuration.
  • Chores

    • Modified the GitHub Actions workflow to install Redis directly instead of using Docker.
    • Updated the .gitignore file to ignore specific certificate files.

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian added the enhancement New feature or request label Nov 20, 2024
@rustatian rustatian requested a review from wolfy-j November 20, 2024 19:41
@rustatian rustatian self-assigned this Nov 20, 2024
Copy link

coderabbitai bot commented Nov 20, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request modifies the GitHub Actions workflow for Redis by removing the Docker-based setup and replacing it with a direct installation of Redis on the runner. It introduces new steps for installing Redis and generating TLS certificates. Additionally, several configuration files are updated or created to support Redis with TLS, including changes to logging levels and addresses. New tests are added to validate the TLS setup, and a script for generating test certificates is introduced.

Changes

File Path Change Summary
.github/workflows/linux.yml Modified to install Redis directly on the runner, added steps for TLS certificate generation, removed Docker-related commands.
.gitignore Added entry to ignore .rdb files.
kv/tlsconfig.go Modified getClientCertificate function to allow more flexible TLS configuration.
tests/configs/.rr-redis-tls.yaml New configuration file for Redis with TLS support, including RPC and logging settings.
tests/configs/.rr-redis.yaml Updated logging level from error to debug and changed Redis address from 6379 to 16379.
tests/storage_plugin_test.go Added TestRedisTLS function for testing Redis with TLS, modified existing test functions to accept address parameters.
tests/certs/get-test-certs.sh New script to automate the generation of test certificates for the regression test suite.
tests/configs/.rr-redis-global.yaml Updated Redis address from 6379 to 16379.

Possibly related PRs

  • feature: TLS redis tests #105: Enhances the GitHub Actions workflow for Redis to include TLS support, aligning with the main PR's transition from Docker to direct Redis installation.

Suggested reviewers

  • wolfy-j

Poem

🐰 In the meadow, the code does play,
Redis hops in a brand new way.
TLS certificates shining bright,
No more Docker, just pure delight!
With tests and configs all in line,
Our rabbit code is simply divine! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Outside diff range and nitpick comments (6)
tests/configs/.rr-redis.yaml (1)

Missing TLS configuration file for Redis tests

The test file storage_plugin_test.go contains a test case TestRedisTLS that explicitly looks for a configuration file at configs/.rr-redis-tls.yaml, but this file is missing from the repository. This is a critical issue as the TLS test will fail without the proper configuration.

  • Add the missing tests/configs/.rr-redis-tls.yaml file with appropriate TLS configuration settings for Redis
  • The file should include TLS-specific settings like certificates, keys, and TLS-enabled Redis connection parameters
🔗 Analysis chain

Line range hint 1-15: Verify TLS configuration file relationship

This appears to be the non-TLS configuration file. Since this PR introduces TLS testing, we should verify that there's a corresponding TLS configuration file with appropriate settings.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for the existence and contents of the TLS configuration file
# Expected: Find a companion TLS config file with appropriate TLS settings

# Check for the TLS config file
echo "Checking for TLS configuration file..."
fd -t f ".rr-redis-tls.yaml" tests/configs/

# If found, show its contents focusing on TLS-related settings
echo "Checking TLS-specific settings..."
rg -A 5 "tls:" tests/configs/

Length of output: 237


Script:

#!/bin/bash
# Let's broaden our search to find any TLS-related configuration files
echo "Searching for TLS-related YAML files..."
fd -e yaml -e yml . tests/configs/

echo "Searching for TLS-related configurations in YAML files..."
rg -l "tls|ssl|cert" tests/configs/

echo "Showing contents of all YAML files in configs directory..."
for f in $(fd -e yaml -e yml . tests/configs/); do
    echo "=== Contents of $f ==="
    cat "$f"
    echo -e "\n"
done

Length of output: 453


Script:

#!/bin/bash
# Let's check the PR changes to understand the TLS testing context
echo "Checking PR changes for TLS-related files..."
git diff --name-only

echo "Checking PR changes content..."
git diff

echo "Looking for test files related to TLS..."
rg -l "tls|TLS" tests/

Length of output: 348


Script:

#!/bin/bash
# Let's examine the test file that mentions TLS
echo "Checking TLS-related test content..."
cat tests/storage_plugin_test.go

# Also check if there are any Redis-related test files
echo -e "\nChecking Redis-related test files..."
rg -l "redis" tests/

Length of output: 8828

tests/configs/.rr-redis-tls.yaml (1)

1-19: Consider enhancing configuration flexibility and documentation

Recommendations for improvement:

  1. Support environment variables for certificate paths to make the configuration more flexible across different test environments
  2. Add comments in the YAML file documenting the certificate requirements and expected format
  3. Consider adding validation for minimum TLS version and cipher suites for enhanced security

Example enhancement:

 tls:
+  # Client certificate in PEM format
   cert: ${REDIS_CLIENT_CERT:-./certs/localhost+2-client.pem}
+  # Client private key in PEM format
   key: ${REDIS_CLIENT_KEY:-./certs/localhost+2-client-key.pem}
+  # Root CA certificate for verification
   root_ca: ${REDIS_ROOT_CA:-./certs/rootCA.pem}
+  # Minimum TLS version (recommended: TLS 1.2)
+  min_version: "1.2"
.github/workflows/linux.yml (2)

43-52: Consider pinning Redis version and adding verification step

While the installation steps are well-structured, consider:

  1. Pinning the Redis version for reproducible builds
  2. Adding a verification step to ensure Redis is installed correctly
 sudo apt-get update
-sudo apt-get install redis
+sudo apt-get install redis-server=6:7.2.* # Pin to specific version
+redis-server --version # Verify installation

61-61: Remove trailing whitespace

There is a trailing space at the end of line 61.

-mkcert -client localhost 127.0.0.1 ::1 
+mkcert -client localhost 127.0.0.1 ::1
🧰 Tools
🪛 yamllint

[error] 61-61: trailing spaces

(trailing-spaces)

kv/tlsconfig.go (1)

Line range hint 119-128: Consider adding early validation of certificate files

The current implementation defers all certificate validation to the callback function. Consider validating the certificate files' existence and permissions when the configuration is first loaded.

Example implementation:

func getClientCertificate(cfg *TLSConfig) func(_ *tls.CertificateRequestInfo) (*tls.Certificate, error) {
	if cfg == nil || cfg.Cert == "" || cfg.Key == "" {
		return nil
	}
+	// Validate certificate files early
+	if _, err := os.Stat(cfg.Cert); err != nil {
+		return nil
+	}
+	if _, err := os.Stat(cfg.Key); err != nil {
+		return nil
+	}
+	// Validate file permissions (on Unix systems)
+	if runtime.GOOS != "windows" {
+		certInfo, _ := os.Stat(cfg.Cert)
+		keyInfo, _ := os.Stat(cfg.Key)
+		if mode := certInfo.Mode().Perm(); mode&0077 != 0 {
+			return nil
+		}
+		if mode := keyInfo.Mode().Perm(); mode&0077 != 0 {
+			return nil
+		}
+	}
	return func(_ *tls.CertificateRequestInfo) (*tls.Certificate, error) {
		cert, err := tls.LoadX509KeyPair(cfg.Cert, cfg.Key)
		if err != nil {
			return nil, err
		}
		return &cert, nil
	}
}

This change:

  • Validates file existence early
  • Checks file permissions on Unix systems
  • Provides better error handling and user experience
tests/storage_plugin_test.go (1)

217-250: Consider extracting common test setup code.

The error handling and shutdown mechanism is duplicated across test functions (TestRedis, TestRedisGlobalSection, and TestRedisTLS). Consider extracting this into a helper function to improve maintainability.

Here's a suggested refactor:

+func setupTestContainer(t *testing.T, cont *endure.Container) (chan struct{}, *sync.WaitGroup) {
+    sig := make(chan os.Signal, 1)
+    signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
+
+    wg := &sync.WaitGroup{}
+    wg.Add(1)
+
+    stopCh := make(chan struct{}, 1)
+
+    ch, err := cont.Serve()
+    assert.NoError(t, err)
+
+    go func() {
+        defer wg.Done()
+        for {
+            select {
+            case e := <-ch:
+                assert.Fail(t, "error", e.Error.Error())
+                err = cont.Stop()
+                if err != nil {
+                    assert.FailNow(t, "error", err.Error())
+                }
+            case <-sig:
+                err = cont.Stop()
+                if err != nil {
+                    assert.FailNow(t, "error", err.Error())
+                }
+                return
+            case <-stopCh:
+                err = cont.Stop()
+                if err != nil {
+                    assert.FailNow(t, "error", err.Error())
+                }
+                return
+            }
+        }
+    }()
+
+    return stopCh, wg
+}

Then use it in the test functions:

-    sig := make(chan os.Signal, 1)
-    signal.Notify(sig, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
-    
-    wg := &sync.WaitGroup{}
-    wg.Add(1)
-    
-    stopCh := make(chan struct{}, 1)
-    
-    go func() {
-        defer wg.Done()
-        for {
-            select {
-            case e := <-ch:
-                assert.Fail(t, "error", e.Error.Error())
-                err = cont.Stop()
-                if err != nil {
-                    assert.FailNow(t, "error", err.Error())
-                }
-            case <-sig:
-                err = cont.Stop()
-                if err != nil {
-                    assert.FailNow(t, "error", err.Error())
-                }
-                return
-            case <-stopCh:
-                err = cont.Stop()
-                if err != nil {
-                    assert.FailNow(t, "error", err.Error())
-                }
-                return
-            }
-        }
-    }()
+    stopCh, wg := setupTestContainer(t, cont)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 211c70a and 023cca8.

📒 Files selected for processing (6)
  • .github/workflows/linux.yml (2 hunks)
  • .gitignore (1 hunks)
  • kv/tlsconfig.go (1 hunks)
  • tests/configs/.rr-redis-tls.yaml (1 hunks)
  • tests/configs/.rr-redis.yaml (1 hunks)
  • tests/storage_plugin_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore
🧰 Additional context used
🪛 actionlint
.github/workflows/linux.yml

54-54: shellcheck reported issue in this script: SC2046:warning:10:7: Quote this to prevent word splitting

(shellcheck)

🪛 yamllint
.github/workflows/linux.yml

[error] 61-61: trailing spaces

(trailing-spaces)

🔇 Additional comments (7)
tests/configs/.rr-redis.yaml (1)

8-8: LGTM: Appropriate log level for test environment

Setting the log level to debug is suitable for test configurations as it provides detailed logging output during test execution, which is particularly valuable when debugging TLS-related issues.

tests/configs/.rr-redis-tls.yaml (3)

1-4: LGTM! Basic configuration looks good.

The version specification and RPC configuration are appropriate for testing purposes, with the service correctly bound to localhost.


10-15: LGTM! Redis configuration is well-structured.

Using a non-default port (6380) is a good practice to avoid conflicts with existing Redis instances during testing.


6-8: Verify logging of sensitive information

While debug logging is appropriate for tests, ensure that sensitive TLS-related information (certificates, keys) is not exposed in the logs.

✅ Verification successful

TLS certificates and keys are properly handled in test configuration

Based on the verification results, the TLS configuration in .rr-redis-tls.yaml uses certificate and key files stored in a dedicated certs directory, and there are no instances of sensitive TLS data being logged in the test files. The logging statements found are primarily for test assertions and plugin initialization. The debug level logging in this test configuration is appropriate and safe.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any logging statements in the test files that might expose sensitive TLS information
rg -g '*.go' -i '(log|print|fmt).*\.(key|cert|password|secret)' ./tests/

Length of output: 74


Script:

#!/bin/bash
# Let's check the Redis TLS test configuration and related test files for any sensitive data logging
rg -g '*.{go,yaml}' -i 'tls' ./tests/ -A 5 -B 5

# Also check for any logging statements in test files
rg -g '*.go' -i '(log|print|fmt).*' ./tests/ -A 2

Length of output: 12216

.github/workflows/linux.yml (1)

62-65: Add cleanup step for sensitive certificate files

The workflow should clean up sensitive certificate files after tests complete.
[security]
Add this step after the tests:

      - name: Cleanup sensitive files
        if: always()
        run: |
          cd tests
          rm -rf certs/
          rm -f localhost+2*.pem
          rm -f rootCA.pem
kv/tlsconfig.go (1)

Line range hint 119-128: Verify the TLS configuration usage in tests

Let's ensure that the TLS configuration changes are properly tested and documented.

✅ Verification successful

Let's gather more specific information about the TLS configuration usage in tests and the actual test implementation.


TLS configuration changes are properly tested and integrated

The verification shows that:

  • TLS configuration is properly tested in TestRedisTLS function
  • Test configuration file .rr-redis-tls.yaml includes the necessary TLS certificate paths
  • The driver correctly uses the TLS configuration through tlsConfig function to initialize Redis client
  • The changes in the TLS configuration code align with both test and production usage
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for TLS-related test cases and configurations
echo "Searching for TLS test cases..."
rg -l "TLS|tls" --type go --type yaml

# Search for certificate/key path configurations
echo "Searching for certificate configurations..."
rg -l "cert.*=|key.*=" --type yaml

# Check for any potential hardcoded certificate paths
echo "Checking for hardcoded certificate paths..."
rg -l "\.crt|\.key|\.pem" --type go --type yaml

Length of output: 530


Script:

#!/bin/bash
# Check the TLS configuration in the test yaml file
echo "Content of TLS config file:"
cat tests/configs/.rr-redis-tls.yaml

# Check the test implementation
echo -e "\nTLS-related test implementation:"
rg -A 10 "TLS|tls" tests/storage_plugin_test.go

# Check how TLS config is used in the driver
echo -e "\nTLS usage in driver:"
rg -A 5 "TLS|tls" kv/driver.go

Length of output: 1608

tests/storage_plugin_test.go (1)

253-253: Verify TLS connection in test method.

While reusing testRPCMethodsRedis ensures consistent validation, consider adding TLS-specific assertions.

Let's verify if the connection is using TLS:

Consider adding TLS connection verification to testRPCMethodsRedis:

func testRPCMethodsRedis(t *testing.T) {
    conn, err := net.Dial("tcp", "127.0.0.1:6001")
    assert.NoError(t, err)
+
+    // For TLS tests, verify TLS connection
+    if tlsConn, ok := conn.(*tls.Conn); ok {
+        assert.True(t, tlsConn.ConnectionState().HandshakeComplete)
+        assert.NotNil(t, tlsConn.ConnectionState().PeerCertificates)
+    }
+
    client := rpc.NewClientWithCodec(goridgeRpc.NewClientCodec(conn))

tests/configs/.rr-redis-tls.yaml Outdated Show resolved Hide resolved
.github/workflows/linux.yml Outdated Show resolved Hide resolved
.github/workflows/linux.yml Outdated Show resolved Hide resolved
.github/workflows/linux.yml Outdated Show resolved Hide resolved
kv/tlsconfig.go Show resolved Hide resolved
tests/storage_plugin_test.go Outdated Show resolved Hide resolved
tests/storage_plugin_test.go Outdated Show resolved Hide resolved
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
.github/workflows/linux.yml (2)

43-52: Add error handling to installation steps

The installation steps look good but could benefit from error handling to ensure the workflow fails fast if any step fails.

 - name: Install Redis
   run: |
+    set -eo pipefail
     sudo apt update
     sudo apt-get install -y lsb-release curl gpg libnss3-tools
     curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
     sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
     echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
     sudo apt-get update
     sudo apt-get install redis

43-66: Consider refactoring into reusable components

The Redis installation and TLS setup could be refactored into reusable composite actions or separate scripts for better maintainability and reuse across workflows.

Consider:

  1. Creating a composite action for Redis installation
  2. Moving TLS setup to a separate script
  3. Creating a reusable workflow for Redis-related CI tasks

This would make the workflow more maintainable and allow reuse in other repositories that need Redis with TLS support.

🧰 Tools
🪛 actionlint

54-54: shellcheck reported issue in this script: SC2046:warning:10:7: Quote this to prevent word splitting

(shellcheck)

🪛 yamllint

[error] 61-61: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 023cca8 and 95702b9.

📒 Files selected for processing (3)
  • .github/workflows/linux.yml (2 hunks)
  • tests/configs/.rr-redis-tls.yaml (1 hunks)
  • tests/storage_plugin_test.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/configs/.rr-redis-tls.yaml
  • tests/storage_plugin_test.go
🧰 Additional context used
🪛 actionlint
.github/workflows/linux.yml

54-54: shellcheck reported issue in this script: SC2046:warning:10:7: Quote this to prevent word splitting

(shellcheck)

🪛 yamllint
.github/workflows/linux.yml

[error] 61-61: trailing spaces

(trailing-spaces)

🔇 Additional comments (2)
.github/workflows/linux.yml (2)

56-59: Make mkcert installation more robust

The previous review comment about making mkcert installation more robust is still valid.


71-72: Remove obsolete Docker command

The previous review comment about removing the docker-compose down command is still valid as we're no longer using Docker.

.github/workflows/linux.yml Outdated Show resolved Hide resolved
.github/workflows/linux.yml Outdated Show resolved Hide resolved
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
.github/workflows/linux.yml (1)

43-51: Consider pinning Redis version for consistent test environments

While the installation process is secure, consider pinning the Redis version to ensure consistent test environments across different runs.

 sudo apt update
 sudo apt-get install -y lsb-release curl gpg libnss3-tools
 curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
 sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
 echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
 sudo apt-get update
-sudo apt-get install redis
+sudo apt-get install redis=6:7.2.*  # Pin to specific version
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 95702b9 and 8431022.

📒 Files selected for processing (2)
  • .github/workflows/linux.yml (2 hunks)
  • tests/configs/.rr-redis-tls.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/configs/.rr-redis-tls.yaml
🧰 Additional context used
🪛 actionlint
.github/workflows/linux.yml

54-54: shellcheck reported issue in this script: SC2046:warning:10:7: Quote this to prevent word splitting

(shellcheck)

🪛 yamllint
.github/workflows/linux.yml

[error] 61-61: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
.github/workflows/linux.yml (1)

65-65: Verify Redis startup and TLS configuration

The Redis server is started but there's no verification that it's running correctly with TLS. Also, the TLS port (16380) is non-standard which might cause confusion.

✅ Verification successful

Redis TLS configuration appears appropriate for testing environment

The non-standard TLS port (16380) is acceptable in this context as:

  1. This is a CI/CD testing environment where port conflicts need to be avoided
  2. The test configuration is properly referenced in the test setup (go test command)
  3. Both standard (6379) and TLS (16380) ports are explicitly configured
  4. The Redis server startup is implicitly verified by the subsequent Go tests that would fail if Redis wasn't running correctly
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Redis is running with correct TLS configuration
echo "Checking Redis process and ports..."
ps aux | grep redis-server
netstat -tlpn | grep redis

echo "Verifying Redis responds on both ports..."
redis-cli ping
redis-cli -p 16380 --tls --cert certs/localhost+2-client.pem \
  --key certs/localhost+2-client-key.pem \
  --cacert certs/rootCA.pem ping

Length of output: 652


Script:

#!/bin/bash
# Let's check the workflow file to understand the Redis setup context
cat .github/workflows/linux.yml

Length of output: 3453

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (1)
.github/workflows/linux.yml (1)

43-52: Add error handling to Redis installation steps

While the installation steps are secure, they would benefit from error handling to ensure each step completes successfully.

 - name: Install Redis
   run: |
+    set -e  # Exit on any error
     sudo apt update
     sudo apt-get install -y lsb-release curl gpg libnss3-tools
     curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
+    [ $? -eq 0 ] || { echo "Failed to download and import Redis GPG key"; exit 1; }
     sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
     echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
     sudo apt-get update
     sudo apt-get install redis
+    redis-server --version || { echo "Redis installation failed"; exit 1; }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8431022 and 4ab1e1e.

📒 Files selected for processing (1)
  • .github/workflows/linux.yml (2 hunks)
🧰 Additional context used
🪛 actionlint
.github/workflows/linux.yml

54-54: shellcheck reported issue in this script: SC2046:warning:10:7: Quote this to prevent word splitting

(shellcheck)


67-67: shellcheck reported issue in this script: SC2046:warning:4:70: Quote this to prevent word splitting

(shellcheck)

🪛 yamllint
.github/workflows/linux.yml

[error] 61-61: trailing spaces

(trailing-spaces)

🔇 Additional comments (1)
.github/workflows/linux.yml (1)

56-59: 🛠️ Refactor suggestion

Pin mkcert version for reproducible builds

Using the latest version URL is fragile and could lead to unexpected behavior. Pin to a specific version for reproducibility.

.github/workflows/linux.yml Outdated Show resolved Hide resolved
.github/workflows/linux.yml Outdated Show resolved Hide resolved
.github/workflows/linux.yml Outdated Show resolved Hide resolved
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (3)
tests/certs/get-test-certs.sh (3)

1-10: Add security warnings to the documentation

While the documentation clearly describes the generated files, it should include explicit warnings about:

  • These certificates being for testing purposes only
  • Not using these certificates in production
  • The potential security implications of committing test certificates to the repository
 # Generate some test certificates which are used by the regression test suite:
+# WARNING: These certificates are for testing purposes only and should never be used
+# in production environments. They are self-signed and have weak security parameters.
+# WARNING: Committing certificates to source control may pose security risks.
 #
 #   tests/tls/ca.{crt,key}          Self signed CA certificate.

45-58: Enhance OpenSSL configuration security

The OpenSSL configuration could be more secure with additional restrictions and extended key usage.

 [ server_cert ]
 keyUsage = digitalSignature, keyEncipherment
 nsCertType = server
+extendedKeyUsage = serverAuth
+basicConstraints = CA:FALSE
 subjectAltName = @alt_names
 
 [ client_cert ]
 keyUsage = digitalSignature, keyEncipherment
 nsCertType = client
+extendedKeyUsage = clientAuth
+basicConstraints = CA:FALSE
 
 [ alt_names ]
 IP.1 = 127.0.0.1
 DNS.1 = localhost
+# Add additional test domains if needed
+# DNS.2 = redis.test.local

1-64: Add script permissions check and cleanup functionality

Consider adding these improvements for better CI/CD integration:

  1. Check script execution permissions
  2. Add cleanup functionality
  3. Add usage instructions

Add this to the beginning of the script:

 #!/bin/bash
+
+# Ensure script is executable
+if [ ! -x "$0" ]; then
+    echo "Error: Script must be executable"
+    exit 1
+fi
+
+# Add usage function
+usage() {
+    echo "Usage: $0 [--cleanup]"
+    echo "  --cleanup  Remove all generated certificates"
+    exit 1
+}
+
+# Add cleanup function
+cleanup() {
+    echo "Cleaning up generated certificates..."
+    rm -rf tests/tls
+}
+
+# Handle command line arguments
+while [ "$1" != "" ]; do
+    case $1 in
+        --cleanup )  cleanup
+                    exit
+                    ;;
+        * )         usage
+                    exit 1
+    esac
+    shift
+done
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4ab1e1e and 7fdf352.

📒 Files selected for processing (15)
  • .github/workflows/linux.yml (2 hunks)
  • .gitignore (1 hunks)
  • tests/certs/ca.crt (1 hunks)
  • tests/certs/ca.key (1 hunks)
  • tests/certs/ca.txt (1 hunks)
  • tests/certs/client.crt (1 hunks)
  • tests/certs/client.key (1 hunks)
  • tests/certs/get-test-certs.sh (1 hunks)
  • tests/certs/openssl.cnf (1 hunks)
  • tests/certs/redis.crt (1 hunks)
  • tests/certs/redis.dh (1 hunks)
  • tests/certs/redis.key (1 hunks)
  • tests/certs/server.crt (1 hunks)
  • tests/certs/server.key (1 hunks)
  • tests/configs/.rr-redis-tls.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (7)
  • tests/certs/ca.crt
  • tests/certs/ca.txt
  • tests/certs/client.crt
  • tests/certs/openssl.cnf
  • tests/certs/redis.crt
  • tests/certs/redis.dh
  • tests/certs/server.crt
🚧 Files skipped from review as they are similar to previous changes (2)
  • .gitignore
  • tests/configs/.rr-redis-tls.yaml
🧰 Additional context used
🪛 actionlint
.github/workflows/linux.yml

54-54: shellcheck reported issue in this script: SC2046:warning:4:70: Quote this to prevent word splitting

(shellcheck)

🪛 Gitleaks
tests/certs/ca.key

1-52: Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.

(private-key)

tests/certs/client.key

1-28: Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.

(private-key)

tests/certs/redis.key

1-28: Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.

(private-key)

tests/certs/server.key

1-28: Identified a Private Key, which may compromise cryptographic security and sensitive data encryption.

(private-key)

tests/certs/get-test-certs.sh Outdated Show resolved Hide resolved
tests/certs/get-test-certs.sh Outdated Show resolved Hide resolved
tests/certs/get-test-certs.sh Outdated Show resolved Hide resolved
.github/workflows/linux.yml Outdated Show resolved Hide resolved
.github/workflows/linux.yml Show resolved Hide resolved
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian merged commit 9a1a468 into master Nov 20, 2024
6 checks passed
@rustatian rustatian deleted the feature/redis-tls-tests branch November 20, 2024 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant