-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Add ACL proxy #32
Conversation
8921649
to
eb86f34
Compare
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.
af82846
to
5a59b8a
Compare
CircleCI now automatically checks the acl-proxy application compliance with our standards for a python application. It also handles docker image build and publication.
5a59b8a
to
215fbd2
Compare
I think I'll postpone the documentation and tray implementations in a separated PR so that the review will be easier. |
if ( | ||
all((school, course, session)) | ||
and f"course-v1:{school}+{course}+{session}" not in user_course_keys | ||
): | ||
return forbidden |
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.
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 | ||
|
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.
Also, maybe we should write "rules" instead of series of conditions. Suggestions are welcome on this.
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.
try: | ||
valid = validate_email(email) | ||
except EmailNotValidError as error: | ||
raise EdxException(f"Invalid input email {email}") from error |
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.
It's a very tiny detail...
raise EdxException(f"Invalid input email {email}") from error | |
raise EdxException(f"Invalid input email: {email}") from error |
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.
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).
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")' | ||
" )" | ||
")" | ||
) |
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.
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: \u0074eacher@example.org
is considered valid by validate_email
but I'm not sure if it is possible to submit such an email.
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.
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: \u0074eacher@example.org 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?
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.
Having a second look, indeed the \u0074eacher@example.org
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 "teacher@example.org" and a student changing his email to "Teacher@example.org".
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
x-accel-redirect
endpointswrite documentationpostponedimplement application traypostponednginx
draft implementationEdited to postpone docs and tray.