Skip to content

enterprise: allow deletion/modification of users when in read-only mode #12289

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

Merged
merged 3 commits into from
Dec 10, 2024
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
4 changes: 4 additions & 0 deletions authentik/enterprise/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.urls import resolve
from structlog.stdlib import BoundLogger, get_logger

from authentik.core.api.users import UserViewSet
from authentik.enterprise.api import LicenseViewSet
from authentik.enterprise.license import LicenseKey
from authentik.enterprise.models import LicenseUsageStatus
Expand Down Expand Up @@ -59,6 +60,9 @@
# Flow executor is mounted as an API path but explicitly allowed
if request.resolver_match._func_path == class_to_path(FlowExecutorView):
return True
# Always allow making changes to users, even in case the license has ben exceeded
if request.resolver_match._func_path == class_to_path(UserViewSet):
return True

Check warning on line 65 in authentik/enterprise/middleware.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/middleware.py#L65

Added line #L65 was not covered by tests
# Only apply these restrictions to the API
if "authentik_api" not in request.resolver_match.app_names:
return True
Expand Down
46 changes: 46 additions & 0 deletions authentik/enterprise/tests/test_read_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,49 @@
{"detail": "Request denied due to expired/invalid license.", "code": "denied_license"},
)
self.assertEqual(response.status_code, 400)

@patch(

Check warning on line 219 in authentik/enterprise/tests/test_read_only.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_read_only.py#L219

Added line #L219 was not covered by tests
"authentik.enterprise.license.LicenseKey.validate",
MagicMock(
return_value=LicenseKey(
aud="",
exp=expiry_valid,
name=generate_id(),
internal_users=100,
external_users=100,
)
),
)
@patch(

Check warning on line 231 in authentik/enterprise/tests/test_read_only.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_read_only.py#L231

Added line #L231 was not covered by tests
"authentik.enterprise.license.LicenseKey.get_internal_user_count",
MagicMock(return_value=1000),
)
@patch(

Check warning on line 235 in authentik/enterprise/tests/test_read_only.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_read_only.py#L235

Added line #L235 was not covered by tests
"authentik.enterprise.license.LicenseKey.get_external_user_count",
MagicMock(return_value=1000),
)
@patch(

Check warning on line 239 in authentik/enterprise/tests/test_read_only.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_read_only.py#L239

Added line #L239 was not covered by tests
"authentik.enterprise.license.LicenseKey.record_usage",
MagicMock(),
)
def test_manage_users(self):

Check warning on line 243 in authentik/enterprise/tests/test_read_only.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_read_only.py#L243

Added line #L243 was not covered by tests
"""Test that managing users is still possible"""
License.objects.create(key=generate_id())
usage = LicenseUsage.objects.create(

Check warning on line 246 in authentik/enterprise/tests/test_read_only.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_read_only.py#L245-L246

Added lines #L245 - L246 were not covered by tests
internal_user_count=100,
external_user_count=100,
status=LicenseUsageStatus.VALID,
)
usage.record_date = now() - timedelta(weeks=THRESHOLD_READ_ONLY_WEEKS + 1)
usage.save(update_fields=["record_date"])

Check warning on line 252 in authentik/enterprise/tests/test_read_only.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_read_only.py#L251-L252

Added lines #L251 - L252 were not covered by tests

admin = create_test_admin_user()
self.client.force_login(admin)

Check warning on line 255 in authentik/enterprise/tests/test_read_only.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_read_only.py#L254-L255

Added lines #L254 - L255 were not covered by tests

# Reading is always allowed
response = self.client.get(reverse("authentik_api:user-list"))
self.assertEqual(response.status_code, 200)

Check warning on line 259 in authentik/enterprise/tests/test_read_only.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_read_only.py#L258-L259

Added lines #L258 - L259 were not covered by tests

# Writing should also be allowed
response = self.client.patch(reverse("authentik_api:user-detail", kwargs={"pk": admin.pk}))
self.assertEqual(response.status_code, 200)

Check warning on line 263 in authentik/enterprise/tests/test_read_only.py

View check run for this annotation

Codecov / codecov/patch

authentik/enterprise/tests/test_read_only.py#L262-L263

Added lines #L262 - L263 were not covered by tests
10 changes: 9 additions & 1 deletion website/docs/enterprise/manage-enterprise.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,15 @@ The following events occur when a license expires or the internal/external user

- After another 2 weeks, users get a warning banner

- After another 2 weeks, the authentik Enterprise instance becomes “read-only”
- After another 2 weeks, the authentik Enterprise instance becomes "read-only"
Copy link
Contributor

@tanberry tanberry Dec 9, 2024

Choose a reason for hiding this comment

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

Suggested change
- After another 2 weeks, the authentik Enterprise instance becomes "read-only"
- After another 2 weeks (six weeks after the initial violation), the authentik Enterprise instance becomes "read-only".


When an authentik instance is in read-only mode, the following actions are still possible:

- Users can authenticate and authorize applications
- Licenses can be modified
- Users can be modified/deleted <span class="badge badge--version">authentik 2024.10.5+</span>

After the violation is corrected (either the user count returns to be within the limits of the license or the license is renewed), authentik will return to the standard read-write mode and the notification will disappear.

### About users and licenses

Expand Down
Loading