Skip to content

Add request exclusion to Host Authorization #38829

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

Merged
merged 1 commit into from
Nov 2, 2020

Conversation

cbisnett
Copy link
Contributor

In the same way that requests may need to be excluded from forced SSL,
requests may also need to be excluded from the Host Authorization
checks. By providing this additional flexibility more applications
will be able to enable Host Authorization while excluding requests
that may not conform. For example, AWS Classic Load Balancers don't
provide a Host header and cannot be configured to send one. This means
that Host Authorization must be disabled to use the health check
provided by the load balancer. This change will allow an application
to exclude the health check requests from the Host Authorization
requirements.

I've modified the ActionDispatch::HostAuthorization middleware to
accept arguments in a similar way to ActionDispatch::SSL. The hosts
configuration setting still exists separately as does the
hosts_response_app but I've tried to group the Host Authorization
settings like the ssl_options. It may make sense to deprecate the
global hosts_response_app if it's only used as part of the Host
Authorization failure response. I've also updated the existing tests
as the method signature changed and added new tests to verify the
exclusion functionality.

Summary

Other Information

@cbisnett
Copy link
Contributor Author

It looks like the keyword argument changes in Ruby 2.8 are causing test failures. I haven't checked (installing Ruby master now), but I'm assuming this means the ActionDispatch::SSL middleware fails the same tests as it uses the same invocation.

@cbisnett cbisnett force-pushed the host_authorization_exclude branch from d2c6309 to beeaeac Compare March 27, 2020 03:35
@cbisnett
Copy link
Contributor Author

Nevermind, I found the issue. It should be fixed now.

@cbisnett
Copy link
Contributor Author

@eileencodes can you see any reason this change would cause ActiveRecord PostgreSQL tests to fail? I’m assuming it’s an intermittent test failure but I don’t know how to kick off a re-test.

Copy link
Member

@eugeneius eugeneius left a comment

Choose a reason for hiding this comment

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

I fixed that test in ddaa24a. Don't worry too much about CI yet, let's review the patch first.

🔔 @gsamokovarov in case you want to 👀, since you implemented this feature in #33145.

@@ -34,6 +34,7 @@ def initialize(*)
@filter_redirect = []
@helpers_paths = []
@hosts = Array(([".localhost", IPAddr.new("0.0.0.0/0"), IPAddr.new("::/0")] if Rails.env.development?))
@host_authorization = { response_app: action_dispatch.hosts_response_app }
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 referencing action_dispatch.hosts_response_app too early, which will prevent applications from being able to set it. I think we should continue to pass it to the middleware, but emit a deprecation warning if it's set.

Copy link
Contributor Author

@cbisnett cbisnett Mar 30, 2020

Choose a reason for hiding this comment

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

I tested this and it appeared to work. I thought that action_dispatch would have been created prior to this. Is there a better way to pass the existing setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a deprecation warning and a fallback to using action_dispatch.hosts_response_app if response_app is not supplied in the configuration. Is there anything else that needs to be done for deprecating a configuration setting? Let me know what you think of this solution.

@cbisnett cbisnett force-pushed the host_authorization_exclude branch 3 times, most recently from e5192b6 to 9250bd5 Compare March 30, 2020 17:34
@cbisnett
Copy link
Contributor Author

I've updated the code and added a deprecation warning, squashed and rebased on master, and tests are passing.

@cbisnett
Copy link
Contributor Author

cbisnett commented Apr 6, 2020

@eugeneius Anything else I need to do or change for this?

@cbisnett
Copy link
Contributor Author

@eugeneius Any interest in getting this merged?

@eugeneius
Copy link
Member

I'd like to see how #38888 is addressed first, since your particular use case for this feature could potentially be resolved by default. You're right that there are other possible reasons to exclude requests from the check, but I'm reluctant to merge a feature based on a hypothetical example.

@rails-bot
Copy link

rails-bot bot commented Jul 17, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Jul 17, 2020
@rails-bot rails-bot bot closed this Jul 24, 2020
In the same way that requests may need to be excluded from forced SSL,
requests may also need to be excluded from the Host Authorization
checks. By providing this additional flexibility more applications
will be able to enable Host Authorization while excluding requests
that may not conform. For example, AWS Classic Load Balancers don't
provide a Host header and cannot be configured to send one. This means
that Host Authorization must be disabled to use the health check
provided by the load balancer. This change will allow an application
to exclude the health check requests from the Host Authorization
requirements.

I've modified the `ActionDispatch::HostAuthorization` middleware to
accept arguments in a similar way to `ActionDispatch::SSL`. The hosts
configuration setting still exists separately as does the
hosts_response_app but I've tried to group the Host Authorization
settings like the ssl_options. It may make sense to deprecate the
global hosts_response_app if it's only used as part of the Host
Authorization failure response. I've also updated the existing tests
as the method signature changed and added new tests to verify the
exclusion functionality.
@eugeneius eugeneius reopened this Nov 2, 2020
@rails-bot rails-bot bot removed the stale label Nov 2, 2020
@eugeneius eugeneius force-pushed the host_authorization_exclude branch from a48bae3 to 1f76740 Compare November 2, 2020 20:20
@eugeneius eugeneius merged commit 67e69e8 into rails:master Nov 2, 2020
@eugeneius
Copy link
Member

Sorry I let this go stale - let's go for it.

@cbisnett cbisnett deleted the host_authorization_exclude branch January 26, 2021 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants