Skip to content

Commit 3f031e9

Browse files
committed
Deprecate hash internal attributes configuration option
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 831a8a6 commit 3f031e9

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

doc/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ linking, the `user_id_to_attr` configuration parameter should be set, since that
119119
service will overwrite the user identifier generated by the proxy.
120120

121121

122-
### hash
122+
### hash **DEPRECATED - use the hasher micro-service**
123123
The proxy can hash any attribute value (e.g., for obfuscation) before passing
124124
it on to the client. The `hash` key should contain a list of all attribute names
125125
for which the corresponding attribute values should be hashed before being

example/internal_attributes.yaml.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@ attributes:
4040
orcid: [name.family-name.value]
4141
openid: [family_name]
4242
saml: [sn, surname]
43-
hash: [edupersontargetedid]
4443
user_id_from_attrs: [edupersontargetedid]
4544
user_id_to_attr: edupersontargetedid

src/satosa/base.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
from .routing import ModuleRouter, SATOSANoBoundEndpointError
2323
from .state import cookie_to_state, SATOSAStateError, State, state_to_cookie
2424

25+
from satosa.deprecated import hash_attributes
26+
2527

2628
_warnings.simplefilter("default")
2729

@@ -53,6 +55,14 @@ def __init__(self, config):
5355
).format(opt=option)
5456
_warnings.warn(msg, DeprecationWarning)
5557

58+
for option in ["hash"]:
59+
if option in self.config["INTERNAL_ATTRIBUTES"]:
60+
msg = (
61+
"'{opt}' configuration option is deprecated."
62+
" Use the hasher microservice instead."
63+
).format(opt=option)
64+
_warnings.warn(msg, DeprecationWarning)
65+
5666
logger.info("Loading backend modules...")
5767
backends = load_backends(self.config, self._auth_resp_callback_func,
5868
self.config["INTERNAL_ATTRIBUTES"])
@@ -145,17 +155,11 @@ def _auth_resp_finish(self, context, internal_response):
145155
if user_id_to_attr:
146156
internal_response.attributes[user_id_to_attr] = [internal_response.user_id]
147157

148-
# Hash all attributes specified in INTERNAL_ATTRIBUTES["hash"]
149-
hash_attributes = self.config["INTERNAL_ATTRIBUTES"].get("hash", [])
150-
internal_attributes = internal_response.attributes
151-
for attribute in hash_attributes:
152-
# hash all attribute values individually
153-
if attribute in internal_attributes:
154-
hashed_values = [
155-
util.hash_data(self.config["USER_ID_HASH_SALT"], v)
156-
for v in internal_attributes[attribute]
157-
]
158-
internal_attributes[attribute] = hashed_values
158+
hash_attributes(
159+
self.config["INTERNAL_ATTRIBUTES"].get("hash", []),
160+
internal_response.attributes,
161+
self.config.get("USER_ID_HASH_SALT", ""),
162+
)
159163

160164
# remove all session state
161165
context.request = None

src/satosa/deprecated.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,21 @@ def oidc_subject_type_to_hash_type(subject_type):
184184
return UserIdHashType.public
185185

186186
return UserIdHashType.pairwise
187+
188+
189+
def hash_attributes(hash_attributes, internal_attributes, salt):
190+
# Hash all attributes specified in INTERNAL_ATTRIBUTES["hash"]
191+
for attribute in hash_attributes:
192+
msg = (
193+
"'USER_ID_HASH_SALT' configuration option is deprecated."
194+
" 'hash' configuration option is deprecated."
195+
" Use the hasher microservice instead."
196+
)
197+
_warnings.warn(msg, DeprecationWarning)
198+
199+
# hash all attribute values individually
200+
if attribute in internal_attributes:
201+
hashed_values = [
202+
util.hash_data(salt, v) for v in internal_attributes[attribute]
203+
]
204+
internal_attributes[attribute] = hashed_values

0 commit comments

Comments
 (0)