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

YDA-6198: add all users internal option #553

Open
wants to merge 1 commit into
base: development
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
16 changes: 16 additions & 0 deletions integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import time
import traceback
import uuid
from subprocess import PIPE, Popen

import data_access_token
import folder
Expand Down Expand Up @@ -769,6 +770,12 @@ def _test_folder_secure_func(ctx, func):
{"name": "util.user.usertype.rodsuser",
"test": lambda ctx: user.user_type(ctx, "researcher"),
"check": lambda x: x == "rodsuser"},
{"name": "is_user_external.internal",
"test": lambda ctx: _test_is_user_external(ctx, "[email protected]"),
"check": lambda x: x == 1},
{"name": "is_user_external.external",
"test": lambda ctx: _test_is_user_external(ctx, "[email protected]"),
"check": lambda x: x == 0}
]


Expand Down Expand Up @@ -862,6 +869,15 @@ def _call_dir_list(ctx, dirname, resc_name):
return json.loads(ret['arguments'][2])


def _test_is_user_external(ctx, username):
command = ["/etc/irods/yoda-ruleset/tools/is-user-external.py"]
environment = dict(os.environ)
environment["PAM_USER"] = username
process = Popen(command, stdout=PIPE, env=environment)
process.communicate()
return process.wait()


def _call_dir_list_check_exc(ctx, dirname, resc_name):
try:
msi.dir_list(ctx, dirname, resc_name, "")
Expand Down
18 changes: 18 additions & 0 deletions tools/is-user-external.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
"""This script is used by the PAM stack to verify whether
a user is external, based on the username."""

__copyright__ = 'Copyright (c) 2025, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(os.path.join(os.path.dirname(__file__), "../util"))

from yoda_names import is_internal_user

username = os.environ.get("PAM_USER", "")
exit_code = 1 if is_internal_user(username) else 0
sys.exit(exit_code)
2 changes: 2 additions & 0 deletions unit-tests/test_util_yoda_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ def test_is_internal_user(self):
self.assertEqual(_is_internal_user("[email protected]", ["*.uu.nl"]), True)
self.assertEqual(_is_internal_user("[email protected]", ["*.cs.uu.nl"]), True)
self.assertEqual(_is_internal_user("[email protected]", ["*.cs.uu.nl"]), False)
self.assertEqual(_is_internal_user("[email protected]", ["*"]), True)
self.assertEqual(_is_internal_user("[email protected]", ["*"]), True)
4 changes: 3 additions & 1 deletion util/yoda_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def _is_internal_user(username: str, external_domain_filter: List) -> bool:
return True

for domain in external_domain_filter:
if domain.startswith("*."):
if domain == "*":
return True
elif domain.startswith("*."):
if username.endswith(domain[1:]) or username.endswith("@" + domain[2:]):
return True
else:
Expand Down