-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Override config.php values through ENV variables #26570
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
Conversation
|
@PhilippSchaffrath, thanks for your PR! By analyzing the history of the files in this pull request, we identified @MorrisJobke, @nickvergessen and @LukasReschke to be potential reviewers. |
lib/private/Config.php
Outdated
| * @return mixed the value or $default | ||
| */ | ||
| public function getValue($key, $default = null) { | ||
| $envKey = self::ENV_PREFIX . $key; |
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.
use getenv()? makes it case insensitive and searches $_SERVER and $_ENV (which might not be populated). See http://stackoverflow.com/a/27077452
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.
You are right! Fixed that and the tests.
Seems like environment variables set by Apache are case insensitive, those set by putenv are not. Just php things...
|
I guess this is only ever used for testing purposes ? I don't see any use case for this in a productive environment. |
|
actually deployment becomes easier when the credentials don't have to be added to the config.php I think @felixboehm may have more experience with cases like that. It also allows us to pass weird security constraints where the password should not be written in plaintext in the config.php (which only prevents exposing the password when the php handler is disabled but otherwise does not increase security IMO). |
|
Perfect for production systems, using .env files and having different environments. |
|
We have to make sure that cronjobs and occ commands still work. |
this is the biggest problem I see. We are using different environments for web, cli and cron execution. I guess you get my point. Simple overwritting is not sufficient. I suggest to have this exclusive to make sure that in case a value is missing the process throws an exception and fails. |
|
Note: AWS encrypts keys and values: https://aws.amazon.com/de/blogs/aws/new-for-aws-lambda-environment-variables-and-serverless-application-model/ |
|
@butonic i would ignore AWS for now. @DeepDiver1975 I don't see this change happening because of the cron / occ problems. The advantage behind the idea was not setting credentials in the config.php but through environment variables. Doing so will make the occ and cron scripts not work anymore. You could do some tricks to get them to work, but that would mean adding credentials in crontab and every time you run an occ command, which is a very bad user experience and behavior. I would close this PR if you guys don't see another solution for this! |
yes - let's close this - THX |
|
Deleting branch tomorrow unless someone has some more feedback. |
|
we could define the environment variables in /etc/owncloud/env.php: <?php
putenv('OC_dbuser=owncloud');
putenv('OC_dbpass=secret');
putenv('OC_dbhost=10.7.23.42');
// or whatever, eg oracle stuff
putenv('ORACLE_HOME=/opt/instantclient_11_2');
putenv('LD_LIBRARY_PATH=/opt/instantclient_11_2');
getenv('TNS_ADMIN=/opt/tnsadmin');Then in eg It works like including a php file ... AND works for cron, occ and mod_php / php-fpm because phpenmod takes care of that. It's still not exactly the same as having the env in the apache config because then only root would be able to read the file ... duh. |
|
Reopening this, as it is still a requested feature and the discussion came up again. As long as we document how to overwrite config values through environment variables for cronjobs (which is possible), there should be nothing against this. |
d23c2f3 to
d755908
Compare
|
rebased |
|
I don't think we can improve this any further. At least this enables users to configure through environment variables.
@DeepDiver1975 can you poke jenkins? |
|
👍 |
… environment variables
…ENV variables, fixed test
d755908 to
7b0e6b9
Compare
|
rebased again, hoping jenkins will finally not randomly fail |
|
is a backport required ? (green ticket, etc...) |
|
@PVince81 hmm, maybe 😅 i'll check and create them if necessary. edit: backport for 9.1 needed |
* added functionality to override config.php values with 'OC_' prefixed environment variables * use getenv to read environment variables since apache does not set $_ENV variables, fixed test
|
Question: is there a documentation update to describe the changes? Else this stays hidden and gets forgotten... |
|
@PhilippSchaffrath please open a documentation ticket and describe how to use it. CC @settermjd |
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
This enables you to override configuration values with a corresponding environment variable.
Environment variables need to be prefixed with
OC_. For example to override thedbnamevalue, simply set the environment variableOC_dbname.Related Issue
Motivation and Context
It is very convenient to be able to store sensitive data like database or mail credentials in an environment variable.
How Has This Been Tested?
Has been tested manually by using php-webserver like this:
and with PhpUnit, tests included.
Types of changes
Checklist: