Skip to content
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

installation: fix database password escaping #2846

Closed

Conversation

eamonnmag
Copy link
Contributor

Signed-off-by: @eamonnmag
Reviewed-by: Jiri Kuncar [email protected]

Updated database.py to wrap password for init script in quotes
@eamonnmag eamonnmag changed the title BaseScripts: updated database.py to wrap password for init script in quotes BaseScripts: updated database.py to wrap password in init Mar 4, 2015
@jirikuncar
Copy link
Member

@eamonnmag could you please amend the commit message according to Invenio standards.

Example:

installation: fix database password escaping

* FIX Wraps password in quotes.  (closes #2844)

Signed-off-by: you
Reviewed-by: Jiri Kuncar <[email protected]>

@jirikuncar jirikuncar added this to the v2.0.0 milestone Mar 4, 2015
@jirikuncar jirikuncar changed the title BaseScripts: updated database.py to wrap password in init installation: fix database password escaping Mar 4, 2015
@@ -85,7 +85,7 @@ def init(user='root', password='', yes_i_know=False):
# Create user and grant access to database.
(cmd_prefix + '-e "GRANT ALL PRIVILEGES ON '
'{CFG_DATABASE_NAME}.* TO {CFG_DATABASE_USER}@localhost '
'IDENTIFIED BY {CFG_DATABASE_PASS}"'),
'IDENTIFIED BY \'{CFG_DATABASE_PASS}\'"'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eamonnmag actually this highlights the issue of proper escaping of the password. What if the password has a quotation sign? You should probably protect the CFG_DATABASE_PASS variable within args, so that any single quote is properly escaped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@kaplun
Copy link
Member

kaplun commented Mar 4, 2015

@eamonnmag could you please amend the commit message according to Invenio standards.

Yep. For reference these are detailed in https://github.com/inveniosoftware/invenio/blob/pu/CONTRIBUTING.rst (point 6)

@jirikuncar
Copy link
Member

@kaplun can you test the PR? It looks useful for 2.0.0.

@jirikuncar jirikuncar modified the milestones: v2.0.x, v2.0.0 Mar 4, 2015
I checked how say the password 'pass\'\'word' was rendering and if it could be escaped.
Python is automatically escaping this and actually creating this, pass'"'"''"'"'word.
Given that developers will see that this password is clearly not what they intended from the log message, this is probably ok, they can just change it.
Passwords such as 'pass''word' are rendered as 'password' due to python and it's concatenation.

So, for me, I think this function does what it is supposed to do. The small fix at least removes any ambiguity for developers.
@eamonnmag eamonnmag closed this Mar 4, 2015
@eamonnmag eamonnmag reopened this Mar 4, 2015
@kaplun
Copy link
Member

kaplun commented Mar 5, 2015

Hi @eamonnmag, in Invenio we try to keep history as clean as possible (since it is then used to compile the change logs). Could you squash this commits into one clean commit (since it's implementing one functionality and it has not yet been merged)? Additionally you can happily just keep this PR. No need to close it or re-open it. Just push-force an updated branch. As soon as your branch will be integrated it will be automatically closed.

@eamonnmag
Copy link
Contributor Author

Yeah, I sort of messed it up. Was the first time I tried it across forks :) I will look at the behaviour of the quotes function above my edits and modify it as discussed today.

@jirikuncar
Copy link
Member

@eamonnmag please remove all extra newlines you have added outside init function. If you see that file doesn't follow PEP8/257 standard please create separate commit first. Thank you!

@jirikuncar
Copy link
Member

Squash and rebase your branch:

$ git fetch upstream
$ git rebase -i upstream/maint-2.0
# in your favorite editor edit commits:
rework a1b2c3e foo: description
f b2c4d7d ...
# change first commit message squash or fixup commits
# see https://github.com/inveniosoftware/invenio/pull/2846#issuecomment-77166257
$ git push origin eamonnmag-dbinit-patch -f

@@ -77,17 +77,25 @@ def init(user='root', password='', yes_i_know=False):
cmd_admin_prefix = prefix.format(cmd='mysqladmin', user=user,
password=password,
**args)

# we can't wrap all keys in quotes since the table name for instance is not quotable'
keys_to_wrap =['CFG_DATABASE_PASS', 'CFG_DATABASE_USER']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps should it be in config @jirikuncar ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine as it is, however @hachreak is working on some improvements https://github.com/hachreak/invenio/commits/refactor_database_init.

@hachreak
Copy link
Member

the PR #2897 for my branch.

@jirikuncar jirikuncar modified the milestones: v2.0.1, 2.0.x Mar 20, 2015
hachreak pushed a commit to hachreak/invenio that referenced this pull request Mar 20, 2015
* BETTER Uses SQLAlchemy to init the database instead of execute mysql
  in a python subshell.
  (closes inveniosoftware#2846) (closes inveniosoftware#2844)

* NEW Adds support for PostgreSQL database initialization.

Signed-off-by: Leonardo Rossi <[email protected]>
Reviewed-by: Jiri Kuncar <[email protected]>
hachreak pushed a commit to hachreak/invenio that referenced this pull request Mar 20, 2015
* BETTER Uses SQLAlchemy and SQLAlchemy-Utils to init the database
  instead of execute mysql in a python subshell.
  (closes inveniosoftware#2846) (closes inveniosoftware#2844)

* NEW Adds support for PostgreSQL database initialization.

Signed-off-by: Leonardo Rossi <[email protected]>
Reviewed-by: Jiri Kuncar <[email protected]>
hachreak pushed a commit to hachreak/invenio that referenced this pull request Mar 20, 2015
* BETTER Uses SQLAlchemy and SQLAlchemy-Utils to init the database
  instead of execute mysql in a python subshell.
  (closes inveniosoftware#2846) (closes inveniosoftware#2844)

* NEW Adds support for PostgreSQL database initialization.

Signed-off-by: Leonardo Rossi <[email protected]>
Reviewed-by: Jiri Kuncar <[email protected]>
@jirikuncar jirikuncar modified the milestones: v2.1, v2.0.2 Mar 25, 2015
hachreak pushed a commit to hachreak/invenio that referenced this pull request Mar 27, 2015
* BETTER Uses SQLAlchemy and SQLAlchemy-Utils to init the database
  instead of execute mysql in a python subshell.
  (closes inveniosoftware#2846) (closes inveniosoftware#2844)

* NEW Adds support for PostgreSQL database initialization.

Signed-off-by: Leonardo Rossi <[email protected]>
Reviewed-by: Jiri Kuncar <[email protected]>
hachreak pushed a commit to hachreak/invenio that referenced this pull request Mar 30, 2015
* BETTER Uses SQLAlchemy and SQLAlchemy-Utils to init the database
  instead of execute mysql in a python subshell.
  (closes inveniosoftware#2846) (closes inveniosoftware#2844)

* NEW Adds support for PostgreSQL database initialization.

Signed-off-by: Leonardo Rossi <[email protected]>
Reviewed-by: Jiri Kuncar <[email protected]>
hachreak pushed a commit to hachreak/invenio that referenced this pull request Mar 31, 2015
* BETTER Uses SQLAlchemy and SQLAlchemy-Utils to init the database
  instead of execute mysql in a python subshell.
  (closes inveniosoftware#2846) (closes inveniosoftware#2844)

* NEW Adds support for PostgreSQL database initialization.

Signed-off-by: Leonardo Rossi <[email protected]>
Reviewed-by: Jiri Kuncar <[email protected]>
hachreak pushed a commit to hachreak/invenio that referenced this pull request Apr 2, 2015
* BETTER Uses SQLAlchemy and SQLAlchemy-Utils to init the database
  instead of executing mysql in a python subshell.
  (closes inveniosoftware#2846) (closes inveniosoftware#2844)

* NEW Adds support for PostgreSQL database initialization.

Signed-off-by: Leonardo Rossi <[email protected]>
Reviewed-by: Jiri Kuncar <[email protected]>
Signed-off-by: Leonardo Rossi <[email protected]>
hachreak pushed a commit to hachreak/invenio that referenced this pull request Apr 2, 2015
* BETTER Uses SQLAlchemy and SQLAlchemy-Utils to init the database
  instead of executing mysql in a python subshell.
  (closes inveniosoftware#2846) (closes inveniosoftware#2844)

* NEW Adds support for PostgreSQL database initialization.

Signed-off-by: Leonardo Rossi <[email protected]>
Reviewed-by: Jiri Kuncar <[email protected]>
hachreak pushed a commit to hachreak/invenio that referenced this pull request Apr 2, 2015
* BETTER Uses SQLAlchemy and SQLAlchemy-Utils to init the database
  instead of executing mysql in a python subshell.
  (closes inveniosoftware#2846) (closes inveniosoftware#2844)

* NEW Adds support for PostgreSQL database initialization.

Signed-off-by: Leonardo Rossi <[email protected]>
Reviewed-by: Jiri Kuncar <[email protected]>
@jirikuncar jirikuncar closed this in 09cc403 Apr 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants