-
-
Notifications
You must be signed in to change notification settings - Fork 297
refactor: remove deprecated SSL fields and update config parsing for PostgreSQL #919
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
Conversation
|
Warning Rate limit exceeded@arxdsilva has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 59 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughThe pull request modifies the SSL configuration handling by removing legacy SSL fields from the Changes
Sequence Diagram(s)sequenceDiagram
participant Loader as Config Loader
participant Parser as Parse Function
participant DBParser as parseDatabaseURL Function
Loader->>Parser: Read configuration file
Parser->>Parser: Remove legacy SSL fields
Parser->>Parser: Add PGSSL fields & update logic
Parser->>DBParser: Pass database URL for parsing
DBParser->>DBParser: Extract PGSSLMode from URL
DBParser-->>Parser: Return updated configuration
Parser-->>Loader: Updated configuration with PGSSL settings
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
config/config.go (1)
371-371: Consider validating the user-provided sslmode.
Here, you accept any value forsslmodefrom the query parameters. Add a quick check to ensure it’s one of the known PostgreSQL SSL modes (e.g., "disable", "require", etc.).Example snippet:
if u.Query().Get("sslmode") != "" { + validModes := map[string]bool{"disable": true, "require": true, "verify-ca": true, "verify-full": true} + userMode := u.Query().Get("sslmode") + if !validModes[userMode] { + log.Warningf("Invalid sslmode: %s, defaulting to 'disable'", userMode) + cfg.PGSSLMode = "disable" + } else { cfg.PGSSLMode = userMode + } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
config/config.go(2 hunks)config/config_test.go(4 hunks)
🔇 Additional comments (5)
config/config.go (1)
237-237: Question the fallback from the default "require" to "disable".
Line 179 sets a default of"require", but here, when no config file is found, you're overriding it to"disable". This may be intentional; if not, consider aligning both defaults or clarifying the intended behavior.Do you want me to scan the codebase to see if there's a dependency on default
"require"?config/config_test.go (4)
39-39: Test behavior is consistent with the fallback SSL mode.
This test verifies the code’s fallback to"disable"when no config file is found, matching the logic at line 237 inconfig.go.
185-185: Great test coverage for PREST_PG_URL override.
This confirms that"sslmode=disable"is correctly interpreted from the environment variable.
196-196: Correctly testing DATABASE_URL-based sslmode.
This ensures"sslmode=disable"is parsed as expected from theDATABASE_URL.
235-235: Accurate test of parseDatabaseURL with "require" sslmode.
Verifies that"sslmode=require"is properly recognized and stored incfg.PGSSLMode.
6d5e3d5 to
6fd9d4e
Compare
There was a problem hiding this 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
🧹 Nitpick comments (1)
config/config.go (1)
63-115: Consider updating documentation for SSL configuration changes.The
Preststruct has undergone significant SSL configuration changes. Consider adding documentation comments to explain:
- The available SSL modes and their security implications
- The recommended SSL mode for production environments
- Examples of secure SSL configuration
Add documentation comments above the struct:
// Prest basic config +// SSL Configuration: +// PGSSLMode: PostgreSQL SSL mode (disable, allow, prefer, require, verify-ca, verify-full) +// PGSSLCert: Path to client certificate file +// PGSSLKey: Path to client private key file +// PGSSLRootCert: Path to root certificate file type Prest struct {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
config/config.go(3 hunks)config/config_test.go(5 hunks)testdata/prest.toml(0 hunks)
💤 Files with no reviewable changes (1)
- testdata/prest.toml
🚧 Files skipped from review as they are similar to previous changes (1)
- config/config_test.go
🔇 Additional comments (2)
config/config.go (2)
258-261: LGTM! Well-structured PostgreSQL SSL configuration.The new PostgreSQL-specific SSL configuration fields are correctly implemented and follow PostgreSQL's naming convention.
370-370: LGTM! Correct parsing of SSL mode from database URL.The SSL mode is correctly parsed from the database URL and assigned to the new PostgreSQL-specific field.
6fd9d4e to
54eac9a
Compare
54eac9a to
5e86f56
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
config/config.go (1)
179-181:⚠️ Potential issueSecurity concern: Default SSL mode set to "disable".
Setting
pg.ssl.modeto "disable" by default is a security risk. PostgreSQL recommends using at least "prefer" as the default SSL mode to ensure secure communication when possible.Apply this diff to improve security:
- viper.SetDefault("pg.ssl.mode", "disable") + viper.SetDefault("pg.ssl.mode", "prefer")Note: The TODO comment suggests that this is a temporary setting until the migration to
pgxis complete. However, it's crucial to maintain secure defaults even during the transition period.
🧹 Nitpick comments (1)
config/config.go (1)
230-230: Consider splitting the Parse function.The TODO comment on line 230 correctly identifies that the
Parsefunction should be split into smaller, more focused methods. This would improve maintainability and testability.Consider breaking down the
Parsefunction into these methods:
parseAuthConfigparseHTTPConfigparseDBConfigparseJWTConfigparseCORSConfigparseExposeConfigparseCacheConfigparseAccessConfigparsePluginConfigExample refactor:
func (p *Prest) parseDBConfig() { p.PGURL = viper.GetString("pg.url") p.PGHost = viper.GetString("pg.host") p.PGPort = viper.GetInt("pg.port") p.PGUser = viper.GetString("pg.user") p.PGPass = viper.GetString("pg.pass") p.PGDatabase = viper.GetString("pg.database") p.PGSSLMode = viper.GetString("pg.ssl.mode") p.PGSSLKey = viper.GetString("pg.ssl.key") p.PGSSLCert = viper.GetString("pg.ssl.cert") p.PGSSLRootCert = viper.GetString("pg.ssl.rootcert") // ... other DB-related config }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
config/config.go(3 hunks)config/config_test.go(4 hunks)testdata/prest.toml(0 hunks)
💤 Files with no reviewable changes (1)
- testdata/prest.toml
🚧 Files skipped from review as they are similar to previous changes (1)
- config/config_test.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyze (go)
🔇 Additional comments (3)
config/config.go (3)
82-85: LGTM! PostgreSQL-specific SSL fields are properly defined.The SSL-related fields in the
Preststruct have been correctly renamed to use thePGprefix, making it clear that these are PostgreSQL-specific configurations.
238-238: Excellent! Secure default for SSL mode when config file is not found.The code sets a secure default of "prefer" for SSL mode when the configuration file is not found, which aligns with PostgreSQL's security recommendations.
371-373: LGTM! Proper handling of SSL mode from database URL.The code correctly extracts and sets the SSL mode from the database URL's query parameters.
5e86f56 to
4a65168
Compare
4a65168 to
cc22c3c
Compare
There was a problem hiding this 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
♻️ Duplicate comments (1)
config/config.go (1)
179-181:⚠️ Potential issueSecurity concern: Default SSL mode set to "disable".
Setting
pg.ssl.modeto "disable" by default is a security risk. PostgreSQL recommends using at least "prefer" as the default SSL mode to ensure secure communication when possible.Apply this diff to improve security:
- viper.SetDefault("pg.ssl.mode", "disable") + viper.SetDefault("pg.ssl.mode", "prefer")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
config/config.go(3 hunks)config/config_test.go(14 hunks)testdata/prest.toml(0 hunks)
💤 Files with no reviewable changes (1)
- testdata/prest.toml
🧰 Additional context used
🪛 golangci-lint (1.62.2)
config/config_test.go
108-108: Error return value of w.Write is not checked
(errcheck)
🪛 GitHub Actions: test code
config/config_test.go
[error] 41-41: TestParse/no_envs failed: expected: false, actual: true
[error] 235-235: Test_parseDatabaseURL failed: expected: 'assert', actual: 'require'
🔇 Additional comments (1)
config/config.go (1)
238-238: LGTM! Good security practice.Setting the fallback SSL mode to "prefer" is a good security practice as it maintains secure defaults when the config file is not found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
config/config.go (1)
230-231: Remove outdated TODO comment.The TODO comment about splitting the config can be removed as it has been addressed by the recent refactoring that split the configuration parsing into separate functions.
-// todo: split config onto methods to simplify this func Parse(cfg *Prest) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
config/config.go(5 hunks)
🔇 Additional comments (2)
config/config.go (2)
179-181: Security concern: Default SSL mode set to "disable".Setting
pg.ssl.modeto "disable" by default is a security risk. PostgreSQL recommends using at least "prefer" as the default SSL mode to ensure secure communication when possible.
243-247: LGTM! Well-structured configuration parsing.The refactoring of configuration parsing into separate functions (
parseAuthConfig,parseHTTPConfig,parseDBConfig,loadCacheConfig) improves code organization and maintainability by following the Single Responsibility Principle.Also applies to: 425-480
650f450 to
5be879c
Compare
5be879c to
238c633
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
♻️ Duplicate comments (1)
config/config_test.go (1)
43-44:⚠️ Potential issueFix failing test: TestParse/no_envs.
The test is failing because the assertion doesn't match the default value set in
viperCfg(). The test expectscfg.Debugto befalse, but it's gettingtrue.Apply this diff to fix the test:
- assert.Equal(t, false, cf.Debug) + assert.Equal(t, viper.GetBool("debug"), cf.Debug)🧰 Tools
🪛 GitHub Actions: test code
[error] 44-44: TestParse failed: Not equal: expected: false, actual: true
🧹 Nitpick comments (1)
config/config_test.go (1)
338-343: Use the helper function to clean up environment variables.The
unsetEnvhelper function is well-structured but currently unused. Consider using it in test cases that modify environment variables to ensure proper cleanup.For example, in the
TestParsefunction:func TestParse(t *testing.T) { + unsetEnv(t) t.Run("no envs", func(t *testing.T) { t.Setenv("PREST_CONF", "../notfound.toml") cf := &Prest{}🧰 Tools
🪛 golangci-lint (1.62.2)
338-338: func
unsetEnvis unused(unused)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
config/config.go(6 hunks)config/config_test.go(11 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
config/config_test.go
111-111: Error return value of w.Write is not checked
(errcheck)
338-338: func unsetEnv is unused
(unused)
🪛 GitHub Actions: test code
config/config_test.go
[error] 44-44: TestParse failed: Not equal: expected: false, actual: true
🔇 Additional comments (5)
config/config.go (5)
157-158: LGTM!Setting the default value for
access.restricttofalseis a sensible default.
181-183: Security concern: Default SSL mode set to "disable".Setting
pg.ssl.modeto "disable" by default is a security risk. PostgreSQL recommends using at least "prefer" as the default SSL mode to ensure secure communication when possible.Apply this diff to improve security:
- viper.SetDefault("pg.ssl.mode", "disable") + viper.SetDefault("pg.ssl.mode", "prefer")
240-240: Security concern: SSL mode fallback set to "disable".When the config file is not found, falling back to "disable" for SSL mode is a security risk. The fallback should maintain secure defaults.
Apply this diff to improve security:
- cfg.PGSSLMode = "disable" + cfg.PGSSLMode = "prefer"
428-451: LGTM!The
parseDBConfigfunction is well-structured and correctly handles all database configuration fields, including the new PostgreSQL-specific SSL fields.
453-466: LGTM!The
loadCacheConfigfunction is well-structured and correctly handles all cache configuration fields.
0d08f00 to
bc442c6
Compare
bc442c6 to
09f0187
Compare
09f0187 to
5d5429f
Compare
5d5429f to
e61647c
Compare
There was a problem hiding this 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
♻️ Duplicate comments (2)
config/config.go (2)
179-181:⚠️ Potential issueSecurity concern: Default SSL mode set to "disable".
Setting
pg.ssl.modeto "disable" by default is a security risk. PostgreSQL recommends using at least "prefer" as the default SSL mode to ensure secure communication when possible.While the TODO comment indicates a plan to replace this with "prefer" after switching to
pgx, this should be prioritized as it affects the security of database connections.
238-238:⚠️ Potential issueSecurity concern: SSL mode fallback set to "disable".
When the config file is not found, falling back to "disable" for SSL mode is a security risk. The fallback should maintain secure defaults.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.github/workflows/test.yml(1 hunks)config/config.go(5 hunks)config/config_test.go(7 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
config/config_test.go
108-108: Error return value of w.Write is not checked
(errcheck)
🔇 Additional comments (8)
config/config.go (5)
243-246: LGTM! Good refactoring of configuration parsing.Breaking down the configuration parsing into smaller, focused functions improves code organization and maintainability.
425-448: LGTM! Well-structured database configuration parsing.The function properly handles all PostgreSQL-related configurations, including the new SSL fields. The cloud factor support for
DATABASE_URLis a good addition.
450-463: LGTM! Clean cache configuration handling.The function effectively manages cache settings and endpoint configurations.
465-474: LGTM! Clear authentication configuration parsing.The function cleanly handles all authentication-related settings.
476-480: LGTM! Concise HTTP configuration parsing.The function effectively handles HTTP-related settings.
config/config_test.go (2)
29-41: LGTM! Updated test assertions for new configuration structure.The test cases properly verify the default values for the new PostgreSQL SSL fields.
204-205: LGTM! Proper test environment cleanup.Good practice to unset environment variables before each test to ensure a clean state.
Also applies to: 213-214, 224-225
.github/workflows/test.yml (1)
84-84: LGTM! Added verbose test output.Adding the
-vflag improves test debugging by providing detailed output for each test case.
Summary by CodeRabbit