-
Notifications
You must be signed in to change notification settings - Fork 164
Account for ASP.NET Core changes around proxy header handling #1525
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
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks for diving into this. I haven't tested the changes, assuming you did.
src/Security/src/Authorization.Certificate/CertificateAuthorizationBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Security/src/Authorization.Certificate/CertificateAuthorizationBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
Yes, but also because SteeltoeOSS/Samples#391 works with the same set of sample apps and I was hitting weird probably-environment issues during my first round of testing, I was already planning to leave this PR draft/open while wrapping up the other effort |
9f1e858
to
020bf64
Compare
80a4e65
to
e4ad593
Compare
src/Common/test/Hosting.Test/ServiceCollectionExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Common/test/Hosting.Test/ServiceCollectionExtensionsTest.cs
Outdated
Show resolved
Hide resolved
src/Common/test/Hosting.Test/ServiceCollectionExtensionsTest.cs
Outdated
Show resolved
Hide resolved
- Move reverse proxy configuration to Common - When present, add networks for CF_INSTANCE IP vars to KnownNetworks - Parameter-less UseCertificateAuthorization now tries to retrieve ForwardedHeadersOptions from DI container before falling back on creating a new instance
- Move new ServiceCollectionExtension to Configuration.CloudFoundry - Use IConfigureOptions<ForwardedHeadersOptions> - add missing using on ServiceProviders, true in BuildServiceProvider - more consistent usage of EnvironmentVariableScope - remove CF_INSTANCE var parsing option
e4ad593
to
9c0da20
Compare
internal const string ConfigurationKey = "Steeltoe:ForwardedHeaders"; | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether to trust all networks (adds 0.0.0.0/0). WARNING: Use only behind a trusted ingress. |
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.
/// Gets or sets a value indicating whether to trust all networks (adds 0.0.0.0/0). WARNING: Use only behind a trusted ingress. | |
/// Gets or sets a value indicating whether to trust all networks (adds 0.0.0.0/0). WARNING: Use only behind a trusted ingress. Default value: true. |
/// <summary> | ||
/// Gets or sets known networks to trust, in CIDR notation. Example: "10.0.0.0/8,192.168.0.0/16". | ||
/// </summary> | ||
public string? KnownNetworks { get; set; } |
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.
According to https://nestenius.se/net/configuring-asp-net-core-forwarded-headers-middleware, KnownNetworks
can already be specified in appsettings and is bound automatically (when using a non-empty host builder, see here and here). So I don't think we need to introduce our own option for that. Based on ASPNETCORE_FORWARDEDHEADERS_ENABLED
, the middleware is added automatically using a startup filter (when using a non-empty host builder, it defaults to true
).
I verified that the following appsettings.json
properly binds in a sample:
"ForwardedHeaders": {
"ForwardedHeaders": "XForwardedFor,XForwardedHost,XForwardedProto",
"ForwardLimit": 1,
"RequireHeaderSymmetry": true,
"KnownProxies": [ "::1" ],
"KnownNetworks": [ "127.0.0.1/8" ],
"AllowedHosts": [ "nestenius.se" ]
}
|
||
namespace Steeltoe.Configuration.CloudFoundry; | ||
|
||
public sealed class ForwardedHeadersSettings |
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.
The name *Settings is misleading, because Aspire uses that to indicate it's not an IOptions
.
If this type is going to stay, it should be added to the configuration schema.
@@ -49,4 +54,285 @@ public async Task ConfigureCloudFoundryOptions_ConfiguresCloudFoundryOptions() | |||
Assert.Equal(16384, appOptions.Value.Limits?.FileDescriptor); | |||
Assert.Equal("playground", appOptions.Value.SpaceName); | |||
} | |||
|
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.
We should have a test using TestWebApplicationBuilderFactory.CreateDefault()
to verify settings are bound from configuration (using both our own configurer, and the one from ASP.NET), and that the startup filter adds the middleware.
Description
Provides a fix for #1524 that is automatically implemented for certificate auth
Quality checklist
If your change affects other repositories, such as Documentation, Samples and/or MainSite, add linked PRs here.