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

Select LDAP config by extracted attribute #397

Open
wants to merge 1 commit 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
19 changes: 15 additions & 4 deletions example/plugins/microservices/ldap_attribute_store.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,23 @@ config:
# from LDAP. The default is not to redirect.
on_ldap_search_result_empty: https://my.vo.org/please/go/enroll

# The microservice may be configured per entityID.
# The microservice may be configured per entityID or per extracted attribute.
# The configuration key is the entityID of the requesting SP,
# the authenticating IdP, or the entityID of the CO virtual IdP.
# When more than one configured entityID matches during a flow
# the priority ordering is requesting SP, then authenticating IdP, then
# the authenticating IdP, the entityID of the CO virtual IdP, or the
# extracted attribute defined by `global.provider_attribute`.
# When more than one configured key matches during a flow
# the priority ordering is provider attribute, requesting SP, then authenticating IdP, then
# CO virtual IdP. Αny missing parameters are taken from the
# default configuration.
global:
provider_attribute: domain

# domain attribute is extracted in a previous microserver and used as a key
# here.
company.com:
ldap_url: ldaps://ldap.company.com
search_base: ou=group,dc=identity,dc=company,dc=com

https://sp.myserver.edu/shibboleth-sp:
search_base: ou=People,o=MyVO,dc=example,dc=org
search_return_attributes:
Expand All @@ -120,3 +130,4 @@ config:
# The microservice may be configured to ignore a particular entityID.
https://another.sp.myserver.edu:
ignore: true

16 changes: 15 additions & 1 deletion src/satosa/micro_services/ldap_attribute_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ def __init__(self, config, *args, **kwargs):

self.config = {}

# Get provider attribute
self.provider_attribute = None
if "global" in config:
if "provider_attribute" in config["global"]:
self.provider_attribute = config["global"]["provider_attribute"]

# Process the default configuration first then any per-SP overrides.
sp_list = ["default"]
sp_list.extend([key for key in config.keys() if key != "default"])
sp_list.extend([key for key in config.keys() if key != "default" and key != "global"])

connections = {}

Expand Down Expand Up @@ -412,6 +418,14 @@ def process(self, context, data):
co_entity_id = state.get(frontend_name, {}).get(co_entity_id_key)

entity_ids = [requester, issuer, co_entity_id, "default"]
if self.provider_attribute:
try:
entity_ids.insert(
0,
data.attributes[self.provider_attribute][0]
)
except (KeyError, IndexError):
pass

config, entity_id = next((self.config.get(e), e)
for e in entity_ids if self.config.get(e))
Expand Down