-
Notifications
You must be signed in to change notification settings - Fork 186
Develop #1725
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
base: develop
Are you sure you want to change the base?
Develop #1725
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,32 +8,32 @@ if [[ $# -ne 3 ]]; then | |
| fi | ||
|
|
||
| ## set variables | ||
| oldDB=$1; ## mosip_ida | ||
| newDB=$2; ## mosip_ida_1 | ||
| oldDB=$1; ## :mosipdbname | ||
| newDB=$2; ## :mosipdbname_1 | ||
| dbPwd=$3 | ||
|
|
||
| ## create new DB directory | ||
| rm -rf $newDB | ||
| cp -r $oldDB $newDB | ||
|
Comment on lines
16
to
17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard and quote destructive filesystem operations. Line 16 can delete unintended paths ( Suggested fix+set -euo pipefail
+
+if [[ -z "${oldDB}" || -z "${newDB}" || "${newDB}" == "/" || "${newDB}" == "." ]]; then
+ echo "Refusing unsafe path values for oldDB/newDB; EXITING"
+ exit 1
+fi
+
-rm -rf $newDB
-cp -r $oldDB $newDB
+rm -rf -- "$newDB"
+cp -r -- "$oldDB" "$newDB"🧰 Tools🪛 Shellcheck (0.11.0)[info] 16-16: Double quote to prevent globbing and word splitting. (SC2086) [info] 17-17: Double quote to prevent globbing and word splitting. (SC2086) [info] 17-17: Double quote to prevent globbing and word splitting. (SC2086) 🤖 Prompt for AI Agents |
||
|
|
||
| ## update DB | ||
| sed -i "s/$oldDB\>/$newDB/g" $newDB/mosip_ida_deploy.properties; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/mosip_ida_db.sql; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/mosip_ida_ddl_deploy.sql; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/mosip_ida_dml_deploy.sql; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/mosip_ida_grants.sql; | ||
| sed -i "s/$oldDB\>/$newDB/g" $newDB/:mosipdbname_deploy.properties; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/:mosipdbname_db.sql; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/:mosipdbname_ddl_deploy.sql; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/:mosipdbname_dml_deploy.sql; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/:mosipdbname_grants.sql; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/mosip_role_common.sql; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/mosip_role_idauser.sql; | ||
| sed -i "s/$oldDB/$newDB/g" $newDB/mosip_role_:dbuname.sql; | ||
|
Comment on lines
+20
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Escape sed search/replacement inputs before interpolation. Lines 20-26 and 31-37 inject raw variables into Suggested fix+escape_sed_pattern() { printf '%s' "$1" | sed 's/[.[\*^$()+?{|\\]/\\&/g'; }
+escape_sed_repl() { printf '%s' "$1" | sed 's/[&/\\]/\\&/g'; }
+
+oldDB_pat="$(escape_sed_pattern "$oldDB")"
+newDB_repl="$(escape_sed_repl "$newDB")"
+dbPwd_repl="$(escape_sed_repl "$dbPwd")"
+
-sed -i "s/$oldDB\>/$newDB/g" $newDB/:mosipdbname_deploy.properties;
+sed -i "s/${oldDB_pat}\>/${newDB_repl}/g" "$newDB/:mosipdbname_deploy.properties"
...
-sed -i "s/SYSADMIN_PWD=.*/SYSADMIN_PWD=$dbPwd/g" $newDB/:mosipdbname_deploy.properties;
+sed -i "s/SYSADMIN_PWD=.*/SYSADMIN_PWD=${dbPwd_repl}/g" "$newDB/:mosipdbname_deploy.properties"Also applies to: 31-37 🧰 Tools🪛 Shellcheck (0.11.0)[info] 20-20: Double quote to prevent globbing and word splitting. (SC2086) [info] 21-21: Double quote to prevent globbing and word splitting. (SC2086) [info] 22-22: Double quote to prevent globbing and word splitting. (SC2086) [info] 23-23: Double quote to prevent globbing and word splitting. (SC2086) [info] 24-24: Double quote to prevent globbing and word splitting. (SC2086) [info] 25-25: Double quote to prevent globbing and word splitting. (SC2086) [info] 26-26: Double quote to prevent globbing and word splitting. (SC2086) 🤖 Prompt for AI Agents |
||
|
|
||
| ## update DB properties | ||
| sed -i "s/DB_SERVERIP=.*/DB_SERVERIP=mzworker0.sb/g" $newDB/mosip_ida_deploy.properties; | ||
| sed -i "s/DB_PORT=.*/DB_PORT=30090/g" $newDB/mosip_ida_deploy.properties; | ||
| sed -i "s/SYSADMIN_PWD=.*/SYSADMIN_PWD=$dbPwd/g" $newDB/mosip_ida_deploy.properties; | ||
| sed -i "s/DBADMIN_PWD=.*/DBADMIN_PWD=$dbPwd/g" $newDB/mosip_ida_deploy.properties; | ||
| sed -i "s/APPADMIN_PWD=.*/APPADMIN_PWD=$dbPwd/g" $newDB/mosip_ida_deploy.properties; | ||
| sed -i "s/DBUSER_PWD=.*/DBUSER_PWD=$dbPwd/g" $newDB/mosip_ida_deploy.properties; | ||
| sed -i "s:BASEPATH=.*:BASEPATH=$PWD:g" $newDB/mosip_ida_deploy.properties; | ||
| sed -i "s/LOG_PATH=.*/LOG_PATH=..\/..\/..\/logs\//g" $newDB/mosip_ida_deploy.properties; | ||
| sed -i "s/DML_FLAG=.*/DML_FLAG=1/g" $newDB/mosip_ida_deploy.properties; | ||
| sed -i "s/DB_SERVERIP=.*/DB_SERVERIP=mzworker0.sb/g" $newDB/:mosipdbname_deploy.properties; | ||
| sed -i "s/DB_PORT=.*/DB_PORT=30090/g" $newDB/:mosipdbname_deploy.properties; | ||
| sed -i "s/SYSADMIN_PWD=.*/SYSADMIN_PWD=$dbPwd/g" $newDB/:mosipdbname_deploy.properties; | ||
| sed -i "s/DBADMIN_PWD=.*/DBADMIN_PWD=$dbPwd/g" $newDB/:mosipdbname_deploy.properties; | ||
| sed -i "s/APPADMIN_PWD=.*/APPADMIN_PWD=$dbPwd/g" $newDB/:mosipdbname_deploy.properties; | ||
| sed -i "s/DBUSER_PWD=.*/DBUSER_PWD=$dbPwd/g" $newDB/:mosipdbname_deploy.properties; | ||
| sed -i "s:BASEPATH=.*:BASEPATH=$PWD:g" $newDB/:mosipdbname_deploy.properties; | ||
| sed -i "s/LOG_PATH=.*/LOG_PATH=..\/..\/..\/logs\//g" $newDB/:mosipdbname_deploy.properties; | ||
| sed -i "s/DML_FLAG=.*/DML_FLAG=1/g" $newDB/:mosipdbname_deploy.properties; | ||
|
|
||
| echo "success"; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| CREATE DATABASE mosip_ida | ||
| CREATE DATABASE :mosipdbname | ||
| ENCODING = 'UTF8' | ||
| LC_COLLATE = 'en_US.UTF-8' | ||
| LC_CTYPE = 'en_US.UTF-8' | ||
| TABLESPACE = pg_default | ||
| OWNER = postgres | ||
| TEMPLATE = template0; | ||
| COMMENT ON DATABASE mosip_ida IS 'ID Authorization related requests, transactions and mapping related data like virtual ids, tokens, etc. will be stored in this database'; | ||
| COMMENT ON DATABASE :mosipdbname IS 'ID Authorization related requests, transactions and mapping related data like virtual ids, tokens, etc. will be stored in this database'; | ||
|
|
||
| \c mosip_ida | ||
| \c :mosipdbname | ||
|
|
||
| DROP SCHEMA IF EXISTS ida CASCADE; | ||
| CREATE SCHEMA ida; | ||
| ALTER SCHEMA ida OWNER TO postgres; | ||
| ALTER DATABASE mosip_ida SET search_path TO ida,pg_catalog,public; | ||
| ALTER DATABASE :mosipdbname SET search_path TO ida,pg_catalog,public; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| \c mosip_ida | ||
| \c :mosipdbname | ||
|
|
||
| \ir ddl/ida-auth_transaction.sql | ||
| \ir ddl/ida-uin_auth_lock.sql | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ DB_PORT=5432 | |
| SU_USER=postgres | ||
| DEFAULT_DB_NAME=postgres | ||
| MOSIP_DB_NAME=mosip_ida | ||
| DB_UNAME=idauser | ||
| DML_FLAG=1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,27 +22,26 @@ echo "Terminated connections" | |
|
|
||
| ## Drop db and role | ||
| echo "Dropping DB" | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f drop_db.sql | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f drop_db.sql -v mosipdbname=$MOSIP_DB_NAME | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify unquoted variable expansions in changed psql invocation lines.
nl -ba db_scripts/mosip_ida/deploy.sh | sed -n '20,50p'
rg -nP 'psql .*--(username|host|port|dbname)=\$| -v [a-zA-Z_]+=\\?\$' db_scripts/mosip_ida/deploy.shRepository: mosip/id-authentication Length of output: 1722 Quote all shell expansions in Multiple psql invocations pass unquoted variables to arguments and the PGPASSWORD environment variable, risking word splitting and globbing failures. Line 32 uses a fragile escaped-quote pattern that is error-prone. Suggested fix (pattern)-PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f drop_db.sql -v mosipdbname=$MOSIP_DB_NAME
+PGPASSWORD="$SU_USER_PWD" psql -v ON_ERROR_STOP=1 --username="$SU_USER" --host="$DB_SERVERIP" --port="$DB_PORT" --dbname="$DEFAULT_DB_NAME" -f drop_db.sql -v "mosipdbname=$MOSIP_DB_NAME"
-PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f role_dbuser.sql -v dbuserpwd=\'$DBUSER_PWD\' -v dbuname=$DB_UNAME
+PGPASSWORD="$SU_USER_PWD" psql -v ON_ERROR_STOP=1 --username="$SU_USER" --host="$DB_SERVERIP" --port="$DB_PORT" --dbname="$DEFAULT_DB_NAME" -f role_dbuser.sql -v "dbuserpwd=$DBUSER_PWD" -v "dbuname=$DB_UNAME"Also applies to: 28-28, 36-36, 37-37, 40-40, 46-46 🧰 Tools🪛 Shellcheck (0.11.0)[info] 25-25: Double quote to prevent globbing and word splitting. (SC2086) [info] 25-25: Double quote to prevent globbing and word splitting. (SC2086) [info] 25-25: Double quote to prevent globbing and word splitting. (SC2086) [info] 25-25: Double quote to prevent globbing and word splitting. (SC2086) [info] 25-25: Double quote to prevent globbing and word splitting. (SC2086) 🤖 Prompt for AI Agents |
||
|
|
||
| echo "Dropping user" | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f drop_role.sql | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f drop_role.sql -v dbuname=$DB_UNAME | ||
|
|
||
| ## Create users | ||
| echo `date "+%m/%d/%Y %H:%M:%S"` ": Creating database users" | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f role_dbuser.sql -v dbuserpwd=\'$DBUSER_PWD\' | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f role_dbuser.sql -v dbuserpwd=\'$DBUSER_PWD\' -v dbuname=$DB_UNAME | ||
|
|
||
| ## Create DB | ||
| echo "Creating DB" | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f db.sql | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f ddl.sql | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f db.sql -v mosipdbname=$MOSIP_DB_NAME | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f ddl.sql -v mosipdbname=$MOSIP_DB_NAME -v dbuname=$DB_UNAME | ||
|
|
||
| ## Grants | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f grants.sql | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -f grants.sql -v mosipdbname=$MOSIP_DB_NAME -v dbuname=$DB_UNAME | ||
|
|
||
| ## Populate tables | ||
| if [ ${DML_FLAG} == 1 ] | ||
| then | ||
| echo `date "+%m/%d/%Y %H:%M:%S"` ": Deploying DML for ${MOSIP_DB_NAME} database" | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -a -b -f dml.sql | ||
| PGPASSWORD=$SU_USER_PWD psql -v ON_ERROR_STOP=1 --username=$SU_USER --host=$DB_SERVERIP --port=$DB_PORT --dbname=$DEFAULT_DB_NAME -a -b -f dml.sql -v mosipdbname=$MOSIP_DB_NAME | ||
| fi | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| \c mosip_ida | ||
| \c :mosipdbname | ||
|
|
||
| TRUNCATE TABLE ida.key_policy_def cascade ; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| DROP DATABASE IF EXISTS mosip_ida; | ||
| DROP DATABASE IF EXISTS :mosipdbname; | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1 +1 @@ | ||||||
| drop role if exists idauser; | ||||||
| drop role if exists :dbuname; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify identifier interpolation style for db/user placeholders in SQL scripts.
rg -nP '(:dbuname|:mosipdbname)\b' db_scripts/mosip_ida/*.sql db_scripts/mosip_ida/ddl/*.sql
rg -nP ':"(dbuname|mosipdbname)"' db_scripts/mosip_ida/*.sql db_scripts/mosip_ida/ddl/*.sqlRepository: mosip/id-authentication Length of output: 2590 Use identifier-safe psql interpolation for role name. Line 1 interpolates Suggested fix-drop role if exists :dbuname;
+drop role if exists :"dbuname";📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,17 +1,17 @@ | ||||||
| \c mosip_ida | ||||||
| \c :mosipdbname | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Verification inconclusiveScript executed: find . -name "grants.sql" -path "*/mosip_ida/*" -type fRepository: mosip/id-authentication Repository: mosip/id-authentication stdout: Script executed: cat -n db_scripts/mosip_ida/grants.sql | head -30Repository: mosip/id-authentication Repository: mosip/id-authentication stdout: psql identifier quoting :"variable" interpolation best practices In psql, use variable interpolation with specific quoting syntax for identifiers and literals to ensure safe substitution. For identifiers (table/column names needing double quotes), use:"varname" which applies proper double-quoting [1][2][3][4]. For SQL literals (string values), use:'varname' which applies single-quoting [1][5][3]. Example: \set table_name 'MyTable' \set col_name 'UserId' SELECT * FROM:"table_name" WHERE:"col_name" = 123; -- becomes SELECT * FROM "MyTable" WHERE "UserId" = 123; [3] This handles case sensitivity, keywords, and special characters automatically, equivalent to quote_ident and quote_literal [6][4]. Unquoted:varname substitutes raw value, suitable only for simple identifiers without specials [1]. Best practices: - Always use:"var" for identifiers to avoid parse errors with keywords/case [6][7][3]. - Use:'var' for values to prevent SQL injection-like issues [5][8]. - Avoid mixed-case or keyword identifiers; use lowercase unquoted for portability [6][9][10]. - Set variables with \set var 'value' or psql -v var=value [5][3]. - Interpolation is syntax-aware and skips strings/blocks [11][3]. For \f (field separator), it sets output formatting, unrelated to identifier quoting [1]. Citations:
Use identifier-quoted psql variables consistently in grants script. Raw Suggested fix-\c :mosipdbname
+\c :"mosipdbname"- ON DATABASE :mosipdbname
- TO :dbuname;
+ ON DATABASE :"mosipdbname"
+ TO :"dbuname";- TO :dbuname;
+ TO :"dbuname";- TO :dbuname;
+ TO :"dbuname";- GRANT SELECT,INSERT,UPDATE,DELETE,REFERENCES ON TABLES TO :dbuname;
+ GRANT SELECT,INSERT,UPDATE,DELETE,REFERENCES ON TABLES TO :"dbuname";📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| GRANT CONNECT | ||||||
| ON DATABASE mosip_ida | ||||||
| TO idauser; | ||||||
| ON DATABASE :mosipdbname | ||||||
| TO :dbuname; | ||||||
|
|
||||||
| GRANT USAGE | ||||||
| ON SCHEMA ida | ||||||
| TO idauser; | ||||||
| TO :dbuname; | ||||||
|
|
||||||
| GRANT SELECT,INSERT,UPDATE,DELETE,TRUNCATE,REFERENCES | ||||||
| ON ALL TABLES IN SCHEMA ida | ||||||
| TO idauser; | ||||||
| TO :dbuname; | ||||||
|
|
||||||
| ALTER DEFAULT PRIVILEGES IN SCHEMA ida | ||||||
| GRANT SELECT,INSERT,UPDATE,DELETE,REFERENCES ON TABLES TO idauser; | ||||||
| GRANT SELECT,INSERT,UPDATE,DELETE,REFERENCES ON TABLES TO :dbuname; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| CREATE ROLE idauser WITH | ||
| CREATE ROLE :dbuname WITH | ||
| INHERIT | ||
| LOGIN | ||
| PASSWORD :dbuserpwd; |
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.
Clarify the distinction between psql variables and filesystem paths.
The example path uses
:mosipdbnameas if it were an actual directory name, but this is a psql variable placeholder used within SQL scripts, not a filesystem directory. The actual directory on disk is stilldb_scripts/mosip_ida. This creates confusion between the parameterized database name (used at runtime) and the physical script location.Consider revising to clarify: "the id-authentication module script folder is
db_scripts/mosip_idawhere scripts for the:mosipdbnamedatabase are available."🤖 Prompt for AI Agents