Hello everyone,
I’m trying to connect to Azure Cache for Redis (Enterprise tier) using Microsoft Entra ID for cache authentication, but the connection fails.
The error message I receive is:
2025-04-18T23:39:49.653148192Z result = redis.ping()
2025-04-18T23:39:49.653150519Z ^^^^^^^^
2025-04-18T23:39:49.653152887Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/commands/core.py", line 1212, in ping
2025-04-18T23:39:49.653155554Z return self.execute_command("PING", **kwargs)
2025-04-18T23:39:49.653158021Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653160403Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/client.py", line 559, in execute_command
2025-04-18T23:39:49.653162935Z return self._execute_command(*args, **options)
2025-04-18T23:39:49.653165337Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653167785Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/client.py", line 565, in _execute_command
2025-04-18T23:39:49.653181065Z conn = self.connection or pool.get_connection(command_name, **options)
2025-04-18T23:39:49.653183704Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653186168Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/connection.py", line 1422, in get_connection
2025-04-18T23:39:49.653188711Z connection.connect()
2025-04-18T23:39:49.653190998Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/connection.py", line 369, in connect
2025-04-18T23:39:49.653193513Z self.on_connect()
2025-04-18T23:39:49.653195884Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/connection.py", line 434, in on_connect
2025-04-18T23:39:49.653198570Z auth_response = self.read_response()
2025-04-18T23:39:49.653200996Z ^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653203452Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/connection.py", line 592, in read_response
2025-04-18T23:39:49.653211713Z response = self._parser.read_response(disable_decoding=disable_decoding)
2025-04-18T23:39:49.653215219Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653218056Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/_parsers/resp2.py", line 15, in read_response
2025-04-18T23:39:49.653220695Z result = self._read_response(disable_decoding=disable_decoding)
2025-04-18T23:39:49.653223128Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2025-04-18T23:39:49.653225644Z File "/tmp/8d/antenv/lib/python3.12/site-packages/redis/_parsers/resp2.py", line 38, in _read_response
2025-04-18T23:39:49.653228328Z raise error
2025-04-18T23:39:49.653230723Z redis.exceptions.AuthenticationError: invalid username-password pair
Here is the configuration I’ve applied:
- On the Redis Enterprise cluster
- Microsoft Entra Authentication is enabled on the Redis Enterprise cluster.
- On the Web App:
- System-assigned managed identity is enabled.
- The appropriate Azure role to the managed identity via IAM.
Below is the python code I’m using to connect:
cred = DefaultAzureCredential()
token = cred.get_token("https://redis.azure.com/.default").token
redis = redis.Redis(**{
host=