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

Add ACL proxy #32

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add ACL proxy #32

wants to merge 2 commits into from

Conversation

jmaupetit
Copy link
Contributor

@jmaupetit jmaupetit commented Jan 19, 2022

Purpose

As grafana has no fine-grained control over variable template values, we need a proxy app that will look for such permissions to allow or deny user requests.

Proposal

  • add Caddy reverse proxy using x-accel-redirect endpoints
  • add acl fastapi application
  • implement a generic application view that checks ACL based on HTTP query parameters
  • add tests
  • integrate project in the CI (lint/test/release)
  • write documentation postponed
  • implement application tray postponed
  • remove nginx draft implementation

Edited to postpone docs and tray.

@jmaupetit jmaupetit self-assigned this Jan 19, 2022
@jmaupetit jmaupetit marked this pull request as draft January 19, 2022 17:43
docker-compose.yml Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
docker/files/etc/nginx/conf.d/default.conf Outdated Show resolved Hide resolved
src/acl/acl/exceptions.py Outdated Show resolved Hide resolved
src/acl/acl/exceptions.py Outdated Show resolved Hide resolved
@jmaupetit jmaupetit force-pushed the add-acl-proxy branch 2 times, most recently from 8921649 to eb86f34 Compare January 28, 2022 16:02
We need fine-grained control over dashboard permissions to ensure users
cannot access variable values they are not expected to.

As it appears that we cannot forbid dashboard input variable values
passed via a GET request, we've designed a FastAPI-based application
that proxy dashboards requests and check input values given grafana
logged user.

The acl-proxy application is used as a companion of our grafana instance
along with the Caddy2 web proxy using an x-accel-redirect workflow.
@jmaupetit jmaupetit force-pushed the add-acl-proxy branch 2 times, most recently from af82846 to 5a59b8a Compare January 28, 2022 17:04
CircleCI now automatically checks the acl-proxy application compliance
with our standards for a python application. It also handles docker
image build and publication.
@jmaupetit
Copy link
Contributor Author

I think I'll postpone the documentation and tray implementations in a separated PR so that the review will be easier.

@jmaupetit jmaupetit marked this pull request as ready for review January 28, 2022 17:18
Comment on lines +92 to +96
if (
all((school, course, session))
and f"course-v1:{school}+{course}+{session}" not in user_course_keys
):
return forbidden
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 think we can be more pedantic on this and check for school | course | session in user_course_keys instead of considering the triplet only.

and f"course-v1:{school}+{course}+{session}" not in user_course_keys
):
return forbidden

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, maybe we should write "rules" instead of series of conditions. Suggestions are welcome on this.

Copy link
Member

@quitterie-lcs quitterie-lcs left a comment

Choose a reason for hiding this comment

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

Makefile Show resolved Hide resolved
try:
valid = validate_email(email)
except EmailNotValidError as error:
raise EdxException(f"Invalid input email {email}") from error
Copy link
Member

Choose a reason for hiding this comment

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

It's a very tiny detail...

Suggested change
raise EdxException(f"Invalid input email {email}") from error
raise EdxException(f"Invalid input email: {email}") from error

Copy link
Contributor

@SergioSim SergioSim left a comment

Choose a reason for hiding this comment

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

This is awesome! So many new tools/packages to discover) Thank you)
Have only one minor comment regarding the query)
Also some delicate grafana routes might be /api/ds/query and /api/datasources/proxy/1/_msearch (they seem to accept any kind of user input).

Comment on lines +23 to +32
edx_course_keys_sql_request = ( # nosec
"SELECT DISTINCT `student_courseaccessrole`.`course_id` "
"FROM `student_courseaccessrole` WHERE ("
" `student_courseaccessrole`.`user_id` = ("
" SELECT id from auth_user "
f' WHERE email="{valid.email}" '
' AND `student_courseaccessrole`.`role` IN ("staff", "instructor")'
" )"
")"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Email validation is good but maybe we could use in addition the sqlachemy query builder or Textual SQL with Bound Parameters ?
Apropos, the seemingly invalid email: \[email protected] is considered valid by validate_email but I'm not sure if it is possible to submit such an email.

Copy link
Contributor Author

@jmaupetit jmaupetit Feb 23, 2022

Choose a reason for hiding this comment

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

Email validation is good but maybe we could use in addition the sqlachemy query builder or Textual SQL with Bound Parameters ?

I've considered using SQL Alchemy but it seemed a bit convoluted to add such dependency for a single SQL request...

Apropos, the seemingly invalid email: \[email protected] is considered valid by validate_email but I'm not sure if it is possible to submit such an email.

Using unicode characters in email addresses is invalid?

Copy link
Contributor

Choose a reason for hiding this comment

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

Having a second look, indeed the \[email protected] is not a threat.
Python does a good job by escaping this kind of input and the validation fails way before the query - at the pydantic email validation step.
However, there is one more edge case - case sensitivity. Grafana treats emails in a case-sensitive manner. We can have a teacher with "[email protected]" and a student changing his email to "[email protected]".

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