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

Disable auditing anonymous sessions #304

Merged
merged 7 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Features
- Login with AppleID (#293, PLUM Sprint 230908, @filipmelik)
- Webauthn authenticator metadata (#256, PLUM Sprint 230908)
- Configurably disable auditing of anonymous sessions (#304, PLUM Sprint 231006)

---

Expand Down
13 changes: 13 additions & 0 deletions seacatauth/audit/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

#

asab.Config.add_defaults({
"seacatauth:audit": {
# Enable or disable the auditing of anonymous sessions.
# Disabling may be desirable for database performance reasons.
"log_anonymous_sessions": True,
},
})


class AuditService(asab.Service):

Expand All @@ -26,6 +34,7 @@ class AuditService(asab.Service):
def __init__(self, app, service_name="seacatauth.AuditService"):
super().__init__(app, service_name)
self.StorageService = app.get_service("asab.StorageService")
self.IsAnonymousLoggingEnabled = asab.Config.getboolean("seacatauth:audit", "log_anonymous_sessions")


async def append(
Expand All @@ -41,6 +50,10 @@ async def append(
"""
assert (isinstance(code, AuditCode))

# Do not audit anonymous sessions if desired (performance reasons)
if not self.IsAnonymousLoggingEnabled and code == AuditCode.ANONYMOUS_SESSION_CREATED:
return

# Do not use upsertor because it can trigger webhook
now = datetime.datetime.now(datetime.timezone.utc)
entry = {
Expand Down
Loading