RHINENG-22333: fix admin failure in ephemeral - #1953
MichaelMraka wants to merge 5 commits into
Conversation
Reviewer's GuideAdds support for initializing the database and application using either standard or admin DB credentials, updates admin-related entry points to use admin mode, and bumps the kessel SDK dependency version. Sequence diagram for admin API startup using admin DB credentialssequenceDiagram
actor AdminOperator
participant TurnpikeAdminAPI as RunAdminAPI
participant Core as ConfigureAppAdmin
participant Database as ConfigureAdmin
participant DBInit as InitDB
participant Config as loadEnvPostgreSQLConfig
participant Gorm as openPostgreSQL
AdminOperator->>TurnpikeAdminAPI: start admin API process
TurnpikeAdminAPI->>Core: ConfigureAppAdmin(true)
Core->>Database: ConfigureAdmin(true)
Database->>DBInit: InitDB(true)
DBInit->>Config: loadEnvPostgreSQLConfig(true, false)
Config-->>DBInit: PostgreSQLConfig(admin user, admin password)
DBInit->>Gorm: openPostgreSQL(PostgreSQLConfig)
Gorm-->>DBInit: *gorm.DB (DB)
DBInit-->>Database: initialized DB
Database->>Database: loadAdditionalParamsFromDB()
Core->>Core: metrics.Configure()
Core->>Database: DBWait(dbWait)
TurnpikeAdminAPI->>TurnpikeAdminAPI: continue admin HTTP server startup
Class diagram for updated DB and app configuration with admin supportclassDiagram
class CoreConfig {
+string DBUser
+string DBPassword
+string DBAdminUser
+string DBAdminPassword
+string DBHost
+string DBPort
+string DBReadReplicaHost
+string DBReadReplicaPort
+string DBName
+string DBSslMode
+string DBSslRootCert
+bool DBDebug
+bool DBReadReplicaEnabled
}
class PostgreSQLConfig {
+string User
+string Host
+string Port
+string Database
+string Passwd
+string SSLMode
+string SSLRootCert
+bool Debug
}
class DatabaseSetup {
+*gorm.DB DB
+*gorm.DB DBReadReplica
+PostgreSQLConfig globalPgConfig
+InitDB(useAdmin bool)
+ConfigureAdmin(useAdmin bool)
+Configure()
+loadEnvPostgreSQLConfig(useAdmin bool, useReadReplica bool) PostgreSQLConfig
+DBWait(waitMode string)
+openPostgreSQL(config PostgreSQLConfig) *gorm.DB
+loadAdditionalParamsFromDB()
+check(db *gorm.DB)
+ReadReplicaConfigured() bool
}
class ApplicationConfig {
+ConfigureAppAdmin(useAdmin bool)
+ConfigureApp()
+SetupTestEnvironment()
}
class TurnpikeAdminAPI {
+RunAdminAPI()
}
class FeedDBScript {
+main()
}
CoreConfig <.. PostgreSQLConfig : values from
PostgreSQLConfig <.. DatabaseSetup : uses
DatabaseSetup <.. ApplicationConfig : uses
ApplicationConfig <.. TurnpikeAdminAPI : uses
DatabaseSetup <.. FeedDBScript : uses
TurnpikeAdminAPI --> ApplicationConfig : calls ConfigureAppAdmin(true)
ApplicationConfig --> DatabaseSetup : calls ConfigureAdmin(useAdmin)
FeedDBScript --> DatabaseSetup : calls InitDB(true)
DatabaseSetup --> PostgreSQLConfig : constructs via loadEnvPostgreSQLConfig()
PostgreSQLConfig --> CoreConfig : reads DB credentials
Flow diagram for selecting DB credentials and host based on admin and read replica flagsflowchart TD
A["Start InitDB(useAdmin, useReadReplica)"] --> B[Set user = CoreCfg.DBUser]
B --> C[Set passwd = CoreCfg.DBPassword]
C --> D{useAdmin?}
D -- Yes --> E[Set user = CoreCfg.DBAdminUser]
E --> F[Set passwd = CoreCfg.DBAdminPassword]
D -- No --> G[Keep standard user and password]
F --> H
G --> H[Set host = CoreCfg.DBHost, port = CoreCfg.DBPort]
H --> I{useReadReplica?}
I -- Yes --> J[Set host = CoreCfg.DBReadReplicaHost]
J --> K[Set port = CoreCfg.DBReadReplicaPort]
I -- No --> L[Keep primary host and port]
K --> M[Build PostgreSQLConfig with user, host, port, database, passwd]
L --> M
M --> N["Open connections for DB (and DBReadReplica if enabled)"]
N --> O[End]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The addition of
useAdminbooleans throughInitDB,ConfigureAdmin, andConfigureAppAdminmakes the call graph harder to reason about; consider exposing clearly named admin vs non-admin entrypoints (e.g.,InitAdminDB/InitUserDB) instead of a flag that can be accidentally mis-set at call sites. - The
loadEnvPostgreSQLConfig(useAdmin, useReadReplica)signature with two booleans is a bit opaque; using a small config/options struct or separate helper functions for admin vs replica config would make call sites more self-documenting and reduce the chance of argument ordering mistakes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The addition of `useAdmin` booleans through `InitDB`, `ConfigureAdmin`, and `ConfigureAppAdmin` makes the call graph harder to reason about; consider exposing clearly named admin vs non-admin entrypoints (e.g., `InitAdminDB` / `InitUserDB`) instead of a flag that can be accidentally mis-set at call sites.
- The `loadEnvPostgreSQLConfig(useAdmin, useReadReplica)` signature with two booleans is a bit opaque; using a small config/options struct or separate helper functions for admin vs replica config would make call sites more self-documenting and reduce the chance of argument ordering mistakes.
## Individual Comments
### Comment 1
<location> `base/database/setup.go:111-120` </location>
<code_context>
// load database config from environment vars using inserted prefix
-func loadEnvPostgreSQLConfig(useReadReplica bool) *PostgreSQLConfig {
+func loadEnvPostgreSQLConfig(useAdmin bool, useReadReplica bool) *PostgreSQLConfig {
+ user := utils.CoreCfg.DBUser
+ passwd := utils.CoreCfg.DBPassword
</code_context>
<issue_to_address>
**🚨 question (security):** Consider whether admin credentials should ever be used for the read replica connection
Since `useAdmin` is passed into `loadEnvPostgreSQLConfig` and combined with `useReadReplica`, the read replica will also use admin credentials when `InitDB(true)` is called and a replica is configured. For typical setups where replicas are read-only and should use restricted users, this broadens privileges unnecessarily. Consider ignoring `useAdmin` when `useReadReplica` is true, or introducing a separate `useReplicaAdmin` flag if elevated access on the replica is explicitly required.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1953 +/- ##
==========================================
+ Coverage 58.83% 58.93% +0.09%
==========================================
Files 131 131
Lines 8407 8481 +74
==========================================
+ Hits 4946 4998 +52
- Misses 2927 2949 +22
Partials 534 534
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
236b4d0 to
49ec98e
Compare
|
/retest |
fixing /home/michael/rhn/patchman-engine.git/vendor/github.com/ezamriy/gorpm/rpmtag.go:36:36: could not determine what C.RPMTAG_HDRID refers to /home/michael/rhn/patchman-engine.git/vendor/github.com/ezamriy/gorpm/rpmtag.go:30:36: could not determine what C.RPMTAG_PKGID refers to /home/michael/rhn/patchman-engine.git/vendor/github.com/ezamriy/gorpm/rpmtag.go:156:36: could not determine what C.RPMTAG_SOURCEPKGID refers to FAIL app/base/database [build failed]
|
Commits missing Jira IDs: |
Secure Coding Practices Checklist GitHub Link
Secure Coding Checklist
Summary by Sourcery
Allow configuring database connections with either standard or admin credentials and update admin API to use admin configuration.
New Features:
Enhancements: