-
Notifications
You must be signed in to change notification settings - Fork 1
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
Chore/365 django rls #2558
base: develop
Are you sure you want to change the base?
Chore/365 django rls #2558
Conversation
with connection.cursor() as cursor: | ||
cursor.execute("select current_setting('my.guid', true)") | ||
x = cursor.fetchone() | ||
print("GUID: ", x) |
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.
Is this print and the one after it for debugging purposes?
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 keeping this middleware in the RLS app would be better.
bc_obps/rls/models.py
Outdated
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 can remove this.
bc_obps/rls/admin.py
Outdated
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 can remove this.
bc_obps/rls/utils.py
Outdated
class RlsRoles: | ||
INDUSTRY_USER = "industry_user" | ||
CAS_DIRECTOR = "cas_director" | ||
CAS_ADMIN = "cas_admin" | ||
CAS_ANALYST = "cas_analyst" | ||
CAS_PENDING = "cas_pending" | ||
CAS_VIEW_ONLY = "cas_view_only" | ||
ALL_ROLES = 'industry_user, cas_director, cas_admin, cas_analyst, cas_pending, cas_view_only' | ||
|
||
|
||
class RlsOperations: | ||
SELECT = "select" | ||
UPDATE = "update" | ||
INSERT = "insert" | ||
DELETE = "delete" |
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.
nit: suggest moving these to an enums.py and make them Enum
if auth_header: | ||
user_guid = UUID(json.loads(auth_header).get('user_guid'), version=4) | ||
with connection.cursor() as cursor: | ||
cursor.execute(f'SET my.guid = "{user_guid}" ') |
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.
Based on this statement it would be better to use placeholders to prevent SQL injection.
cursor.execute('SET my.guid = %s', [str(user_guid)])
def revoke_all_privileges(self): | ||
with connection.cursor() as cursor: | ||
cursor.execute(f'drop owned by {RlsRoles.ALL_ROLES}') | ||
cursor.execute(f'grant usage on schema erc to {RlsRoles.ALL_ROLES}') |
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.
add usage on schema common as well
bc_obps/rls/utils.py
Outdated
self.schema = schema | ||
|
||
def apply_policy(self, cursor): # type: ignore | ||
execute_string = ( |
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.
use parameterized queries for all "execute string" calls
Signed-off-by: SeSo <[email protected]>
Not to be merged, for example only
Django - RLS proof of concept work.
Instructions in docs/rls_demo_instructions.md file