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

Idea: log successful permission checks for debugging / auditing #17

Open
simonw opened this issue Sep 1, 2024 · 1 comment
Open

Idea: log successful permission checks for debugging / auditing #17

simonw opened this issue Sep 1, 2024 · 1 comment
Labels

Comments

@simonw
Copy link
Contributor

simonw commented Sep 1, 2024

I'm not sure how feasible this is, but it struck me that we could have an option to write a record to a database every time one of the permission checks succeeds, here:

@hookimpl
def permission_allowed(datasette, actor, action, resource):
if not resource or len(resource) != 2:
return None
async def inner():
if not actor:
return None
await update_dynamic_groups(
datasette, actor, skip_cache=hasattr(sys, "_pytest_running")
)
db = datasette.get_internal_database()
result = await db.execute(
ACL_RESOURCE_PAIR_SQL,
{
"actor_id": actor["id"],
"database": resource[0],
"resource": resource[1],
"action": action,
},
)
return result.single_value() or None

This could go to a capped in-memory table that deletes after 1,000 records, or it could be configured to log permanently.

Capturing the page that the request came from would be useful too, but is a lot harder because that plugin hook doesn't provide access to the request.

@simonw simonw added the research label Sep 1, 2024
@simonw
Copy link
Contributor Author

simonw commented Sep 1, 2024

Being able to see "user tom was granted update-row on table X because they were a member of group Y" could really help with debugging permissions issues.

Downside: we fire those checks a LOT - we fire update-row check just to see if they should have a visible update row button, for example.

Capping the size of the table would prevent it from absorbing too many resources (other than extra CPU).

Not sure if this feature is worthwhile or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant