-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
strip newline from all passed variables #613
base: master
Are you sure you want to change the base?
strip newline from all passed variables #613
Conversation
this prevents weird errors whem attributes get shifted to newline and executed by docker-entrypoint.sh When newline is stripped a 'Warning' is printed
Seems to be related to these issues: MariaDB/mariadb-docker#183 and #571 While this is one possible way to handle "bad" characters and is targeted at fixing the "Option File" created by I see two main alternatives to address escaping (passwords specifically*): fail on bad values or escape everything. Escaping everything will probably lead us to things like implementing ⬆️ WDYT @tianon and @ltangvald? Maybe something like wordpress uses when escaping things for Side note: MariaDB/mariadb-docker#183 discussed * I say passwords specifically since most other environment variables like user or database are unlikely to contain characters that need escaping (and have accidental "features" #338). |
Hi @yosifkit, Thanks for feedback.
For simplicity I would suggest 'failing on bad values' and letting the user know what bad values are. If the container fails to start and last message in its logs looks like |
I was going to suggest printf %q (we used it in e.g. the upstream debian packages to escape input during the installation), but if you give it a multiline input it wraps it in $'', which causes a syntax error in SQL |
I like the idea of doing input validation, i.e. fail as it does now, but with a more helpful error message. |
That sounds like fun -- is there somewhere we can reference for what the "canonically supported" set of characters / restrictions are? 😄 |
There is a list of special characters here https://dev.mysql.com/doc/refman/8.0/en/string-literals.html |
This prevents weird errors when attributes get shifted to newline and are executed by docker-entrypoint.sh. This PR removes the newline and when newline is stripped a 'Warning' is printed.
Short version:
docker-entrypoint.sh
scripts breaks (as seen later in examples of this PR) when 'newline' is present with rather ugly error that is hard to analyze without checking the code of script.Better error message or automated removal of 'newline' would be more desirable. This PR proposes automated 'newline' removal.
Long version:
I have run into this when trying to get image working with kubernetes and erroneously generated 'kubernetes secret' that contained the newline at the end. From looking at the logs the error that I have made required me to do debugging of image as there was no good message on what is going on. I believe there is no practical use case for having 'newline' in any of variables (if this is not true please correct me).
After the change proposed here the mysql image would progress with only printing warning when 'newline' is included which would make this work in most cases. With kubernetes the newline is preserved at the end of string which makes this invisible to user if such mistake is done.
Alternative approach to this would be to "hard fail" with error that 'newline' was encountered in some variable as that will most probably never be desired and user should be aware of it.
Main idea for creating this PR is to avoid unnecessary image debugging when 'newline' is accidentally included in any of the variables.
Please let me know what you think about this change and also let me know there are any changes needed for this to be merged. Thank you!
How to reproduce issue:
mysql:5.6
mysql:5.7
mysql:8.0
After fix the mysql can start properly and following can be seen in logs if there was any newline stripped (including the name of variable from which it was stripped so user can fix it):