Skip to content

Saml group mapping v2 #2489

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions mobsf/MobSF/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,9 @@
IDP_SSO_URL = os.getenv('MOBSF_IDP_SSO_URL')
IDP_X509CERT = os.getenv('MOBSF_IDP_X509CERT')
IDP_IS_ADFS = os.getenv('MOBSF_IDP_IS_ADFS', '0')
IDP_MAINTAINER_GROUP = os.getenv('MOBSF_IDP_MAINTAINER_GROUP', 'Maintainer')
IDP_VIEWER_GROUP = os.getenv('MOBSF_IDP_VIEWER_GROUP', 'Viewer')
IDP_MAINTAINER_GROUP = os.getenv('MOBSF_IDP_MAINTAINER_GROUP', 'Maintainer').split(',')
IDP_VIEWER_GROUP = os.getenv('MOBSF_IDP_VIEWER_GROUP', 'Viewer').split(',')
IDP_MOBSF_DEFAULT_GROUP = os.getenv('MOBSF_IDP_DEFAULT_GROUP')
# SP Configuration
SP_HOST = os.getenv('MOBSF_SP_HOST')
SP_ALLOW_PASSWORD = os.getenv('MOBSF_SP_ALLOW_PASSWORD', '0')
Expand Down
4 changes: 2 additions & 2 deletions mobsf/MobSF/views/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class Permissions(Enum):
DELETE = f'StaticAnalyzer.{PERM_CAN_DELETE}'


MAINTAINER_GROUP = settings.IDP_MAINTAINER_GROUP
VIEWER_GROUP = settings.IDP_VIEWER_GROUP
MAINTAINER_GROUP = 'Maintainer'
VIEWER_GROUP = 'Viewer'


def permission_required(perm):
Expand Down
18 changes: 15 additions & 3 deletions mobsf/MobSF/views/saml2.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,19 @@ def get_redirect_url(req):

def get_user_role(roles):
"""Get user role."""
mrole = any(MAINTAINER_GROUP.lower() in gp.lower() for gp in roles)
if mrole:
maintainer_groups = [g.lower() for g in settings.IDP_MAINTAINER_GROUP]
viewer_groups = [g.lower() for g in settings.IDP_VIEWER_GROUP]
user_roles = [gp.lower() for gp in roles]
mrole = any(gp in maintainer_groups for gp in user_roles)
vrole = any(gp in viewer_groups for gp in user_roles)
if mrole or settings.IDP_MOBSF_DEFAULT_GROUP == 'Maintainer':
logger.info('User assigned to %s group.', MAINTAINER_GROUP)
return MAINTAINER_GROUP
return VIEWER_GROUP
elif vrole or settings.IDP_MOBSF_DEFAULT_GROUP == 'Viewer':
logger.info('User assigned to %s group.', VIEWER_GROUP)
return VIEWER_GROUP
logger.warning('User does not have an authorized SSO group.')
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to support this? We do not want to over complicate SSO roles. MobSF only has two role privileges a read-only default role for everyone and a read-write maintainer role for maintainer group.

return None


@require_http_methods(['GET'])
Expand Down Expand Up @@ -174,6 +183,9 @@ def saml_acs(request):
'role attribute not found in SAML response.')
email = attributes['email'][0]
role = get_user_role(attributes['role'])
if not role:
raise Exception(
Copy link
Member

Choose a reason for hiding this comment

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

Users/Groups that doesn't need MobSF access shouldn't be added in the MobSF SAML app.
https://mobsf.github.io/docs/#/sso

'You do not have an authorized SSO group.')
if User.objects.filter(username=email).exists():
user = User.objects.get(username=email)
user.groups.clear()
Expand Down
Loading