-
Notifications
You must be signed in to change notification settings - Fork 178
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
DOC-4816 added Jedis AMR connection page #1166
Open
andy-stark-redis
wants to merge
5
commits into
main
Choose a base branch
from
DOC-4816-amr-jedis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+203
−0
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b5bd3a2
DOC-4816 added Jedis AMR connection page
andy-stark-redis de79a8e
DOC-4816 added suggested link and removed TLS requirement
andy-stark-redis 8e03e26
DOC-4816 minor fixes
andy-stark-redis 70cb277
DOC-4816 added advanced config options
andy-stark-redis 4b953b9
Apply suggestions from code review
andy-stark-redis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Loading status checks…
DOC-4816 added Jedis AMR connection page
commit b5bd3a277ae9cf926fe4a1cbd075d97e082d7b1a
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
--- | ||
categories: | ||
- docs | ||
- develop | ||
- stack | ||
- oss | ||
- rs | ||
- rc | ||
- oss | ||
- kubernetes | ||
- clients | ||
description: Learn how to authenticate to an Azure Managed Redis (AMR) database | ||
linkTitle: Connect to AMR | ||
title: Connect to Azure Managed Redis | ||
weight: 2 | ||
--- | ||
|
||
The [`redis-authx-entraid`](https://github.com/redis/jvm-redis-authx-entraid) package | ||
lets you authenticate your app to | ||
[Azure Managed Redis (AMR)](https://azure.microsoft.com/en-us/products/managed-redis) | ||
using [Microsoft Entra ID](https://learn.microsoft.com/en-us/entra/identity/). | ||
You can authenticate using a system-assigned or user-assigned | ||
[managed identity](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview) | ||
or a [service principal](https://learn.microsoft.com/en-us/entra/identity-platform/app-objects-and-service-principals), | ||
letting `redis-authx-entraid` fetch and renew the authentication tokens for you automatically. | ||
|
||
## Install | ||
|
||
Install [`jedis`]({{< relref "/develop/clients/jedis" >}}) first, | ||
if you have not already done so. | ||
|
||
If you are using Maven, add | ||
the following dependency to your `pom.xml` file: | ||
|
||
```xml | ||
<dependency> | ||
<groupId>redis.clients.authentication</groupId> | ||
<artifactId>redis-authx-entraid</artifactId> | ||
<version>0.1.1-beta1</version> | ||
</dependency> | ||
``` | ||
|
||
If you are using Gradle, add the following dependency to your | ||
`build.gradle` file: | ||
|
||
```bash | ||
implementation 'redis.clients.authentication:redis-authx-entraid:0.1.1-beta1' | ||
``` | ||
|
||
## Create a `TokenAuthConfig` instance | ||
|
||
The `TokenAuthConfig` class contains the authentication details that you | ||
must supply when you connect to Redis. Chain the methods of the | ||
`EntraIDTokenAuthConfigBuilder` class together (starting with the `builder()` | ||
method) to include the details you need, as shown in the following example: | ||
|
||
```java | ||
TokenAuthConfig authConfig = EntraIDTokenAuthConfigBuilder.builder() | ||
.secret("<secret>") | ||
.authority("<authority>") | ||
// Other options... | ||
.build(); | ||
``` | ||
|
||
Some of the details you can supply are common to different use cases: | ||
|
||
- `secret()`: A string containing the [authentication secret](https://learn.microsoft.com/en-us/purview/sit-defn-azure-ad-client-secret). | ||
- `authority()`: A string containing the [authority](https://learn.microsoft.com/en-us/entra/identity-platform/msal-client-application-configuration#authority) | ||
URL. | ||
- `scopes()`: A set of strings defining the [scopes](https://learn.microsoft.com/en-us/entra/identity-platform/scopes-oidc) | ||
you want to apply. | ||
|
||
You can also add configuration to authenticate with a [service principal](#serv-principal) | ||
or a [managed identity](#mgd-identity) as described in the sections below. | ||
|
||
### Configuration for a service principal {#serv-principal} | ||
|
||
Add `clientId()` to the `EntraIDTokenAuthConfigBuilder` chain to specify | ||
authentication via a service principal, passing the ID token string as | ||
a parameter. (See the | ||
[Microsoft EntraID docs](https://learn.microsoft.com/en-us/entra/identity-platform/app-objects-and-service-principals) | ||
for more information about service principals.) | ||
|
||
```java | ||
TokenAuthConfig authConfig = EntraIDTokenAuthConfigBuilder.builder() | ||
.clientId("<CLIENT-ID>") | ||
// ... | ||
.build(); | ||
``` | ||
|
||
### Configuration for a managed identity {#mgd-identity} | ||
|
||
You can also authenticate to AMR using a managed identity (see the | ||
[Microsoft documentation](https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/overview) to learn more about managed identities). | ||
|
||
For a system assigned managed identity, simply add the `systemAssignedManagedIdentity()` | ||
method to the `EntraIDTokenAuthConfigBuilder` chain: | ||
|
||
```java | ||
TokenAuthConfig authConfig = EntraIDTokenAuthConfigBuilder.builder() | ||
.systemAssignedManagedIdentity() | ||
// ... | ||
.build(); | ||
``` | ||
|
||
For a user assigned managed identity, add `userAssignedManagedIdentity()`. This | ||
requires a member of the `UserManagedIdentityType` enum (to select a | ||
`CLIENT_ID`, `OBJECT_ID`, or `RESOURCE_ID`) as well as the `id` string itself: | ||
|
||
```java | ||
TokenAuthConfig authConfig = EntraIDTokenAuthConfigBuilder.builder() | ||
.userAssignedManagedIdentity( | ||
UserManagedIdentityType.CLIENT_ID, | ||
"<ID>" | ||
) | ||
// ... | ||
.build(); | ||
|
||
``` | ||
|
||
## Connect using `DefaultJedisClientConfig` | ||
|
||
When you have created your `TokenAuthConfig` instance, you are ready to | ||
connect to AMR. | ||
The example below shows how to include the `TokenAuthConfig` details in a | ||
`JedisClientConfig` instance and use it with the `UnifiedJedis` connection. | ||
|
||
{{< note >}} Azure requires you to use | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not so sure if this is correct info. AFAIK it s just TLS is suggested and enabled by default with new managed instances. |
||
[Transport Layer Security (TLS)](https://en.wikipedia.org/wiki/Transport_Layer_Security) | ||
when you connect. See | ||
[Connect to your production Redis with TLS]({{< relref "/develop/clients/jedis/connect#connect-to-your-production-redis-with-tls" >}}) for more information about | ||
TLS connections, including the implementation of the `createSslSocketFactory()` | ||
method used in the example. | ||
{{< /note >}} | ||
|
||
```java | ||
TokenAuthConfig authConfig = EntraIDTokenAuthConfigBuilder.builder() | ||
// Chain of options... | ||
.build(); | ||
|
||
SSLSocketFactory sslFactory = createSslSocketFactory( | ||
"./truststore.jks", | ||
"secret!", // Use the password you specified for `keytool` | ||
"./redis-user-keystore.p12", | ||
"secret!" // Use the password you specified for `openssl` | ||
); | ||
|
||
JedisClientConfig config = DefaultJedisClientConfig.builder() | ||
// Include the `TokenAuthConfig` details. | ||
.authXManager(new AuthXManager(authConfig)) | ||
.ssl(true).sslSocketFactory(sslFactory) | ||
.build(); | ||
|
||
UnifiedJedis jedis = new UnifiedJedis( | ||
new HostAndPort("<host>", <port>), | ||
config | ||
); | ||
|
||
// Test the connection. | ||
System.out.println(String.format("Database size is %d", jedis.dbSize())); | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe it also worth to mention this link; these resources more direct when your focus is on working with EntraID enabled AMR. https://learn.microsoft.com/en-us/azure/azure-cache-for-redis/cache-azure-active-directory-for-authentication