AwsAuthManager.deserialize_user() mutates input token dictionary
Under which category would you file this issue?
Providers
Apache Airflow version
main (Airflow 3.0+)
Apache Airflow Provider(s)
amazon
What happened and how to reproduce it?
In AwsAuthManager.deserialize_user() (providers/amazon/src/airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py):
def deserialize_user(self, token: dict[str, Any]) -> AwsAuthManagerUser:
return AwsAuthManagerUser(
user_id=token.pop("sub"),
groups=token.get("groups", []),
username=token.get("username"),
email=token.get("email"),
)
Notice that token.pop("sub") mutates the caller's input dictionary in-place by removing the "sub" key.
If deserialize_user() is called multiple times on the same claims dictionary, or if the decoded JWT dictionary is accessed by downstream authentication handlers or middleware that expect "sub" to remain intact, the in-place mutation can lead to unexpected KeyError: 'sub' or lost claims.
In contrast, other auth managers access "sub" non-destructively:
SimpleAuthManager:username=token["sub"]FabAuthManager:user_id=int(token["sub"])KeycloakAuthManager:user_id=token["user_id"]
What you think should happen instead?
AwsAuthManager.deserialize_user() should access "sub" without mutating the input dictionary in place (i.e. user_id=token["sub"]).
Additionally, unit tests should cover both deserialize_user() and serialize_user() in test_aws_auth_manager.py, asserting that the input dictionary is not modified in-place.
Operating System
Linux
Deployment
Other
Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct