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

filter roles not belonging to the project #65

Merged
merged 2 commits into from
Sep 5, 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
1 change: 0 additions & 1 deletion fabric_cm/credmgr/external_apis/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def get_user_and_project_info(self, eppn: str, email: str, sub: str, project_id:
ldap_search_filter = '(mail=' + email + ')'
LOG.debug("ldap_host:%s", self.ldap_host)
LOG.debug("ldap_user:%s", self.ldap_user)
LOG.debug("ldap_password:%s", self.ldap_password)
LOG.debug("ldap_search_base:%s", self.ldap_search_base)
LOG.debug("ldap_search_filter:%s", ldap_search_filter)
try:
Expand Down
10 changes: 10 additions & 0 deletions fabric_cm/credmgr/token/token_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# SOFTWARE.
#
# Author Komal Thareja ([email protected])
import re
from datetime import datetime
from dateutil import tz
from fss_utils.jwt_manager import JWTManager, ValidateCode
Expand Down Expand Up @@ -122,6 +123,14 @@ def _validate_lifetime(self, *, validity: int, roles: dict, project_id: str):

return False

# Function to exclude roles with name containing UUIDs
@staticmethod
def exclude_uuid_roles(*, claims):
if "roles" in claims:
claims["roles"] = [role for role in claims["roles"] if not re.search(
r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}', role["name"])]
return claims

def _add_fabric_claims(self):
"""
Set the claims for the Token by adding membership, project and scope
Expand Down Expand Up @@ -157,6 +166,7 @@ def _add_fabric_claims(self):
self.claims[self.UUID] = uuid
if self.claims.get(self.EMAIL) is None:
self.claims[self.EMAIL] = email
self.exclude_uuid_roles(claims=self.claims)
LOG.debug("Claims %s", self.claims)
self.unset = False

Expand Down