[Autofix] Make Metabase sample DB GUEST credentials env-configurable - #1
Open
Apiiro-Guardian-AutoFix wants to merge 1 commit into
Open
[Autofix] Make Metabase sample DB GUEST credentials env-configurable#1Apiiro-Guardian-AutoFix wants to merge 1 commit into
Apiiro-Guardian-AutoFix wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✅ Fixed
Secrets · View in Apiiro
Summary:
Removed the hardcoded
;USER=GUEST;PASSWORD=guestliteral fromsrc/metabase/sample_data.cljand routed the bundled Sample Database credentials through the existingmetabase.config/config-strenv-var loader (newMB_SAMPLE_DATABASE_USER/MB_SAMPLE_DATABASE_PASSWORDkeys, registered inapp-defaults).What Changed:
Added two new entries to the
app-defaultsmap insrc/metabase/config.clj(:mb-sample-database-user→ "GUEST",:mb-sample-database-password→ "guest") so the values are resolved through Metabase's standard env-var/JVM-prop/default precedence (MB_SAMPLE_DATABASE_USER,MB_SAMPLE_DATABASE_PASSWORD). Insrc/metabase/sample_data.cljthe inlined(str ";USER=GUEST;PASSWORD=guest")call insideprocess-sample-db-pathwas replaced with a new private helpersample-db-credentials-suffixthat builds the suffix from those config keys at runtime;metabase.configwas added to the namespace's:requirelist.Why This Fix:
The risk's original file (
sample_dataset/metabase/sample_dataset/generate.clj, which used the long-removedk/exec-rawkorma API) no longer exists in the repository — the sample H2 database is now shipped pre-built — but the same hardcoded GUEST password still appears insrc/metabase/sample_data.clj, which is the file production code uses to connect to that bundled DB. The Secrets overlay says to "replace it with a reference resolved at runtime" and to "use whatever is already wired up"; Metabase already exposesmetabase.config/config-strwithMB_*env-var precedence overapp-defaults(see:mb-jetty-port,:mb-version-info-url, etc.), so I reused that pattern rather than introducing a new secrets library. Defaults were kept at "GUEST"/"guest" because those credentials are baked into the public, read-onlysample-database.db.mv.dbartifact and changing the value in code alone cannot open the DB — operators rotating the credential must also rebuild that H2 file.Files Changed:
src/metabase/config.cljsrc/metabase/sample_data.cljReviewer Notes:
sample-database.db.mv.dbH2 file; changing the value in source alone would break the sample-DB load. The fix's security value is allowing operators who rebuild the artifact with rotated…extracted-db-path-regexintest/metabase/sample_data_test.cljstill matches because runtime defaults preserve the;USER=GUEST;PASSWORD=guestsuffix — no test change was needed.Follow-Ups:
resources/sample-database.db.mv.dbwith rotated credentials and setMB_SAMPLE_DATABASE_USER/MB_SAMPLE_DATABASE_PASSWORDin the runtime environment to match.Potential Impact:
Behavior is unchanged for any deployment that does not set the new env vars — the same
;USER=GUEST;PASSWORD=guestsuffix is still produced at runtime, so the bundled sample DB continues to load and all tests asserting the connection string keep passing. New env varsMB_SAMPLE_DATABASE_USERandMB_SAMPLE_DATABASE_PASSWORDnow influence the sample-DB connection details and are read on everyprocess-sample-db-pathcall; misconfiguring them in production would cause the sample DB sync to fail with an H2 auth error.About Apiiro Autofix
This PR was automatically generated by Apiiro Autofix. Review all changes carefully before merging and run your test suite to verify no regressions.