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

Enforce authentication #2

Merged
merged 2 commits into from
Jan 31, 2022
Merged

Enforce authentication #2

merged 2 commits into from
Jan 31, 2022

Conversation

oneiros
Copy link
Collaborator

@oneiros oneiros commented Jan 26, 2022

OK, this one is embarrassing.

Up until now, hdm never actually restricted access to hiera data from anonymous users. If you were not logged in, you could still access "internal" pages if you knew the URL.

This was due to a combination of reasons:

1.) Authorization is performed with the help of the cancancan gem. The rules live in app/models/abilities.rb. If no user was signed in, the following line simply created one:

user ||= User.new # guest user (not logged in)

So anonymous users had the same rights a regular user.

This PR changes that line, so anonymous (i.e. non-existent) users have no rights.

2.) It is customary in rails applications to check for signed in users in a so called before_action as the very first step when a request hits the application. This is so there is no need to query the authorization layer or waste other resources in these cases at all.

Such a before_action was missing from hdm.

This PR adds a before_action checking the authentication in ApplicationController, so all controllers inherit it. In the few places where login is not required, exceptions to that rule have been added.

I am really sorry that I did not catch this earlier. I guess there were so many familiar patterns already in place that I just expected this to work ☹️

This adds a `before_action` to `ApplicationController`
(with carefully selected exceptions in a few places) and
fixes abilities to actually restrict access to signed in
users.
@oneiros
Copy link
Collaborator Author

oneiros commented Jan 31, 2022

I added some simple tests to make sure this does not happen again.

@tuxmea tuxmea merged commit d7c75ac into main Jan 31, 2022
@tuxmea tuxmea deleted the enforce_authentication branch April 13, 2022 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants