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

Allow to set trusted proxies in the environment variables #68

Merged
merged 2 commits into from
Jun 25, 2018

Conversation

aschempp
Copy link
Member

fixes #63

@aschempp aschempp added this to the 4.6.0 milestone Apr 19, 2018
@aschempp aschempp self-assigned this Apr 19, 2018
@@ -21,6 +22,19 @@
/** @var Composer\Autoload\ClassLoader */
$loader = require __DIR__.'/../vendor/autoload.php';

if (file_exists(__DIR__.'/../.env')) {
(new Dotenv())->load(__DIR__.'/../.env');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that needed in the app.php?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, #69, got it ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really related to #69, but we need it if people want to configure production using .env files. I agree it's not Symfony best practice, but 90% of our people don't have real server variables.

Copy link
Member

Choose a reason for hiding this comment

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

I don't like this at all. There are valid reasons why Symfony recommends not to use the Dotenv component in production.

}

// see https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/3.3/public/index.php#L27
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
Copy link
Member

Choose a reason for hiding this comment

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

This is a rather unconventional piece of code. 😄 I guess we should at least use ?? null instead of ?? false, shouldn't we?

Copy link
Member

Choose a reason for hiding this comment

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

I see you have copied it from Symfony …

Copy link
Member

@leofeyer leofeyer left a comment

Choose a reason for hiding this comment

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

Besides the coding style this PR looks good to me.

@@ -21,6 +22,19 @@
/** @var Composer\Autoload\ClassLoader */
$loader = require __DIR__.'/../vendor/autoload.php';

if (file_exists(__DIR__.'/../.env')) {
(new Dotenv())->load(__DIR__.'/../.env');
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't like this at all. There are valid reasons why Symfony recommends not to use the Dotenv component in production.

@aschempp
Copy link
Member Author

aschempp commented Jun 15, 2018

There are valid reasons why Symfony recommends not to use the Dotenv component in production.

Yes, the don't recommend it, because you should use environment variables. Unfortunately, as we know, 95% of Contao setups on shared hosting don't support environment variables. That's what the DotEnv component is for. If your server does support ENV variables, don't create the file and use it to adjust your setup, and then this will work as well. Obviously not through the Contao Manager, but if you have and use environment variables, you probably don't need the Contao Manager.

@leofeyer
Copy link
Member

Correct me if I'm wrong, but environment variables can easily be set in e.g. a .htaccesfile.

<IfModule mod_env.c>
    SetEnv SYMFONY_ENV prod
</IfModule>

But nevertheless, this kind of configuration should go into the parameters.yml file in production!

@aschempp
Copy link
Member Author

But nevertheless, this kind of configuration should go into the parameters.yml file in production!

No they don't, because this is application configuration that is loaded before the kernel is booted or the container is available.

@leofeyer leofeyer merged commit 38ff9d8 into master Jun 25, 2018
@leofeyer
Copy link
Member

Thank you @aschempp.

@leofeyer leofeyer deleted the feature/trusted-proxies branch June 25, 2018 15:02
leofeyer pushed a commit that referenced this pull request Jun 27, 2018
Description
-----------

This allows the Contao Manager (and other API tools) to write all environment variables. Necessary to be able to e.g. add trusted proxies (#68).

FYI, changing/removing existing commands is intended and that's what the API version is for.

Commits
-------

b09f472 Replace the access-key API command with generic dot-env commands
34c743a Added unit tests for DotEnv commands
699183d Fix the coding style.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to set trusted proxy settings using an env variable
4 participants