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

Wrong environment variable value can be saved to Sites\{TenantName}\appsettings.json during tenant creation #15275

Closed
rjpowers10 opened this issue Feb 7, 2024 · 3 comments
Labels

Comments

@rjpowers10
Copy link
Contributor

Describe the bug

Reproduced in plain old Orchard Core 1.8.2

I have two environment variables set in launchSettings.json.

  1. OrchardCore__Default__MyEnvVar: DefaultTenantValue
  2. OrchardCore__MyEnvVar: OtherTenantValue

In a multitenant scenario, I want the default tenant to use one value, and all the other tenants to use another.

The key to reproducing this is to make sure these environment variables are set before the default tenant is created. Create a new site from scratch. I don't think the recipe matters, but I used the Blog recipe.

To Reproduce

  1. Set the environment variables in launchSettings.json
  2. Create a new OC 1.8.2 site from scratch using the Blog recipe

The problem is, after the Default tenant is created I'm actually getting the value "OtherTenantValue" back, when I expected "DefaultTenantValue". The problem seems to be that "OtherTenantValue" got saved to Sites\Default\appsettings.json

Screenshots

In Sites\Default\appsettings.json, I see that the wrong value was saved. Since Sites\Default\appsettings.json takes precedence over launchSettings.json, I end up using the wrong value for the Default tenant. Furthermore, it was confusing why changing the value in launchSettings.json wasn't taking effect, and that's because appsettings.json was winning.

image

Admittedly, I think the scope of this bug is somewhat narrow, as it requires these variables to be set prior to tenant creation. If I go through the tenant setup first and add my environment variables later, everything works as I expect and the value is never stored in appsettings.json.

@ns8482e
Copy link
Contributor

ns8482e commented Feb 14, 2024

Values in Sites\Default\appsettings.json is settings and it always takes precedence over configuration. How are you using in recipe or reading in code?

@MikeAlhayek
Copy link
Member

@rjpowers10 I have not looked at the code. But i trust that the docs are still valid "as they should" https://docs.orchardcore.net/en/latest/docs/reference/core/Configuration/#config-sources

The important part is this

The Configuration Sources are loaded in the above order, and settings lower in the hierarchy will override values configured higher up, i.e. an Global Tenant value will always be overridden by an Environment Variable.

This means that you will need to flip variable and test so the order should be like this

- OrchardCore__MyEnvVar: OtherTenantValue
- OrchardCore__Default__MyEnvVar: DefaultTenantValue

With this, the first line will apply to app tenants including the default. But then, we override the configuration for the default tenant using the second variable. "last one wins"

Also, I would not expect these variables to be written to the appsettings file. These settings are loaded into memory and kept that way. So if you are looking to see which settings were loaded and is used, then maybe you should log them somewhere so you can test it out. But these settings should never be written directly to the appsettings file of the tenant.

@Piedone
Copy link
Member

Piedone commented Apr 15, 2024

Closing due to no reply from the author.

@Piedone Piedone closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants