fix: harden shell scripts and fix db_copy loop bug#3159
Open
rhdh-bot wants to merge 4 commits into
Open
Conversation
Correct a logic error in hack/db_copy.sh that caused every database migration to target backstage_plugin_app, and apply shellcheck-driven hardening across plugin-infra setup scripts and Tekton inline scripts. Assisted-by: cursor Co-authored-by: Cursor <cursoragent@cursor.com>
Address SonarCloud warnings about camelCase function names introduced during shell script hardening. Assisted-by: cursor Co-authored-by: Cursor <cursoragent@cursor.com>
Use snake_case function names and bash [[ ]] conditionals throughout gitops-secret-setup.sh; align plugin-infra.sh file test with [[ ]]. Assisted-by: cursor Co-authored-by: Cursor <cursoragent@cursor.com>
|
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.



Summary
ShellCheck audit of repository shell scripts found no parse errors (including no "trailing ] outside test" issues), but manual review surfaced one functional bug and several hardening opportunities. This PR addresses all of them.
Critical fix:
hack/db_copy.shThe migration loop contained:
allDBis a regular indexed array. Using a string likebackstage_plugin_authas a subscript causes bash to fall back to index0, so every iteration copiedbackstage_plugin_appinstead of the intended six Backstage plugin databases.Fix: remove the erroneous reassignment; the
forloop variable already holds the correct name.Hardening:
config/profile/rhdh/plugin-infra/plugin-infra.shset -euo pipefail(wasset -eonly).[ ... == ... ]with[[ ... ]]for bash-native string/boolean comparisons.Hardening:
config/profile/rhdh/plugin-infra/gitops-secret-setup.shset -euo pipefail.selected_instance=""soset -uis safe when no ArgoCD instance exists.eval "$cmd"increateBackstageSecretwith a command array — avoids shell metacharacter injection if secret values contain special characters.${VAR:-}for optional variables; quoteARGOCD_URL.name()function style (consistent with other scripts).Hardening:
config/profile/rhdh/plugin-deps/tekton.yamlEmbedded Tekton step scripts updated:
flattenerROOT/TARGETvars; add shebang +set -eu; fix[ ... == ... ]→[ ... = ... ]build-manifestsset -eubuild-gitopsset -eu; quote paths/args;cd kustomize || exitAnalysis for reviewers
hack/db_copy.shgitops-secret-setup.shevalcould break or inject on unusual secret valuesplugin-infra.shtekton.yamlcdfailureScope: shell scripts and Tekton inline scripts only — no Go operator logic, CRDs, or bundle changes.
Validation run locally:
shellcheck -x -aon all changed.shfiles — cleanbash -nsyntax check — cleanTest plan
shellcheck -x -a hack/db_copy.sh config/profile/rhdh/plugin-infra/*.shgitops-secret-setup.sharray-based secret creation (no behavior change for normal values)hack/db_copy.shloop logic — verify six distinct DB names are iteratedMade with Cursor