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

Dojo_Group: Support for "RemoteUser" in model #9405

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 18 additions & 0 deletions dojo/db_migrations/0201_alter_dojo_group_social_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1.13 on 2024-01-25 00:07

Check warning on line 1 in dojo/db_migrations/0201_alter_dojo_group_social_provider.py

View check run for this annotation

DryRunSecurity / Configured Sensitive Files Check

Sensitive File Edit

This file edit was detected to be sensitive according to the DryRun Security Configuration for this repository. Any edit to this file by an Author not in the allowedAuthors list will be considered sensitive.

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dojo', '0200_finding_sla_expiration_date_product_async_updating_and_more'),
]

operations = [
migrations.AlterField(
model_name='dojo_group',
name='social_provider',
field=models.CharField(blank=True, choices=[('AzureAD', 'AzureAD'), ('Remote', 'Remote')], help_text='Group imported from a social provider.', max_length=10, null=True, verbose_name='Social Authentication Provider'),
),
]
4 changes: 3 additions & 1 deletion dojo/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import base64

Check warning on line 1 in dojo/models.py

View check run for this annotation

DryRunSecurity / Configured Sensitive Files Check

Sensitive File Edit

This file edit was detected to be sensitive according to the DryRun Security Configuration for this repository. Any edit to this file by an Author not in the allowedAuthors list will be considered sensitive.
import hashlib
import logging
import os
Expand Down Expand Up @@ -246,14 +246,16 @@

class Dojo_Group(models.Model):
AZURE = 'AzureAD'
REMOTE = 'Remote'
SOCIAL_CHOICES = (
(AZURE, _('AzureAD')),
(REMOTE, _('Remote')),
)
name = models.CharField(max_length=255, unique=True)
description = models.CharField(max_length=4000, null=True, blank=True)
users = models.ManyToManyField(Dojo_User, through='Dojo_Group_Member', related_name='users', blank=True)
auth_group = models.ForeignKey(Group, null=True, blank=True, on_delete=models.CASCADE)
social_provider = models.CharField(max_length=10, choices=SOCIAL_CHOICES, blank=True, null=True, help_text='Group imported from a social provider.', verbose_name='Social Authentication Provider')
social_provider = models.CharField(max_length=10, choices=SOCIAL_CHOICES, blank=True, null=True, help_text=_('Group imported from a social provider.'), verbose_name=_('Social Authentication Provider'))

def __str__(self):
return self.name
Expand Down
2 changes: 1 addition & 1 deletion dojo/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gitlab

Check warning on line 1 in dojo/pipeline.py

View check run for this annotation

DryRunSecurity / Configured Sensitive Files Check

Sensitive File Edit

This file edit was detected to be sensitive according to the DryRun Security Configuration for this repository. Any edit to this file by an Author not in the allowedAuthors list will be considered sensitive.
import re
import logging
import requests
Expand Down Expand Up @@ -98,7 +98,7 @@
except Exception as e:
logger.error(f"Could not call microsoft graph API or save groups to member: {e}")
if len(group_names) > 0:
assign_user_to_groups(user, group_names, 'AzureAD')
assign_user_to_groups(user, group_names, Dojo_Group.AZURE)
if settings.AZUREAD_TENANT_OAUTH2_CLEANUP_GROUPS:
cleanup_old_groups_for_user(user, group_names)

Expand Down
3 changes: 2 additions & 1 deletion dojo/remote_user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import logging

Check warning on line 1 in dojo/remote_user.py

View check run for this annotation

DryRunSecurity / Configured Sensitive Files Check

Sensitive File Edit

This file edit was detected to be sensitive according to the DryRun Security Configuration for this repository. Any edit to this file by an Author not in the allowedAuthors list will be considered sensitive.
from django.contrib.auth.middleware import RemoteUserMiddleware as OriginalRemoteUserMiddleware
from django.contrib.auth.backends import RemoteUserBackend as OriginalRemoteUserBackend
from drf_spectacular.extensions import OpenApiAuthenticationExtension
Expand All @@ -6,6 +6,7 @@
from netaddr import IPAddress
from django.conf import settings
from dojo.pipeline import assign_user_to_groups, cleanup_old_groups_for_user
from dojo.models import Dojo_Group

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,7 +78,7 @@

if settings.AUTH_REMOTEUSER_GROUPS_HEADER and \
settings.AUTH_REMOTEUSER_GROUPS_HEADER in request.META:
assign_user_to_groups(user, request.META[settings.AUTH_REMOTEUSER_GROUPS_HEADER].split(','), 'Remote')
assign_user_to_groups(user, request.META[settings.AUTH_REMOTEUSER_GROUPS_HEADER].split(','), Dojo_Group.REMOTE)

if settings.AUTH_REMOTEUSER_GROUPS_CLEANUP and \
settings.AUTH_REMOTEUSER_GROUPS_HEADER and \
Expand Down
4 changes: 2 additions & 2 deletions unittests/test_remote_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def setUp(self):
last_name='original_last',
email='[email protected]',
)
self.group1, _ = Dojo_Group.objects.get_or_create(name="group1", social_provider="Remote")
self.group2, _ = Dojo_Group.objects.get_or_create(name="group2", social_provider="Remote")
self.group1, _ = Dojo_Group.objects.get_or_create(name="group1", social_provider=Dojo_Group.REMOTE)
self.group2, _ = Dojo_Group.objects.get_or_create(name="group2", social_provider=Dojo_Group.REMOTE)

@override_settings(AUTH_REMOTEUSER_ENABLED=False)
def test_disabled(self):
Expand Down
Loading