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

docs: add multitenancy keycloak integration tutorials #793

Merged
merged 49 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
73b3c5f
docs: multitenancy phase 2 doc wip
Nov 17, 2023
ea82a57
docs: complete onboarding tut
Nov 17, 2023
52a7f2b
docs: minor adjustment
Nov 20, 2023
43e5dd3
docs: self-service doc wip
Nov 20, 2023
f0c9437
docs: self-service onboarding docs
Nov 20, 2023
fb21e91
docs: keycloak jwt migration tutorial
Nov 20, 2023
3b34172
docs: fix script to make tut work
Nov 20, 2023
8b24d18
docs: clean up
Nov 20, 2023
5ac5558
docs: fix typo in script
Nov 20, 2023
d32a9a2
docs: no ci commit [skip ci]
Nov 20, 2023
6632bdd
Merge branch 'main' into docs/mt-keycloak-tuts
Nov 20, 2023
cbdfa4d
docs: no ci commit [skip ci]
Nov 20, 2023
84cc78b
docs: correct http method
Nov 20, 2023
f17fa6a
docs: add keycloak convention
Nov 20, 2023
a078a06
docs: link tutorials to glossary
Nov 20, 2023
02cc1f7
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
petevielhaber Nov 20, 2023
aa21943
Update docs/docusaurus/multitenancy/tenant-migration.md
petevielhaber Nov 20, 2023
8ee3d04
docs: reference UMA in glossary
Nov 20, 2023
e9d59ce
Update docs/docusaurus/multitenancy/tenant-migration.md
Nov 20, 2023
354d059
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
4d84dfa
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
208ba3f
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
4bf45ed
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
25dfc7a
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
7f0844f
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
ef79aff
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
c1b5944
Update docs/docusaurus/multitenancy/tenant-migration.md
Nov 20, 2023
16e0a93
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
a61a4fc
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
c0a1abe
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
411bb4d
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
9272e2e
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
841c5f4
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
ba43863
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
8aabde3
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
3aa0035
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
acd27e9
Update docs/docusaurus/multitenancy/tenant-onboarding-self-service.md
Nov 20, 2023
ee69483
Apply suggestions from code review
Nov 20, 2023
835faa3
Update docs/docusaurus/multitenancy/tenant-onboarding-ext-iam.md
Nov 20, 2023
dffbe69
docs: reference RPT in glossary
Nov 20, 2023
92f2a02
Update docs/docusaurus/multitenancy/tenant-migration.md
petevielhaber Nov 21, 2023
70f0d24
Update docs/docusaurus/multitenancy/tenant-migration.md
petevielhaber Nov 21, 2023
a258118
Update docs/docusaurus/multitenancy/tenant-migration.md
petevielhaber Nov 21, 2023
e1ba578
Update docs/docusaurus/multitenancy/tenant-migration.md
petevielhaber Nov 21, 2023
13a31fa
Update docs/docusaurus/multitenancy/tenant-migration.md
petevielhaber Nov 21, 2023
493b06f
Update docs/docusaurus/multitenancy/tenant-migration.md
petevielhaber Nov 21, 2023
32f90b7
Update docs/docusaurus/multitenancy/tenant-migration.md
petevielhaber Nov 21, 2023
e404e9b
Update docs/docusaurus/multitenancy/tenant-migration.md
petevielhaber Nov 21, 2023
9d6c712
Merge branch 'main' into docs/mt-keycloak-tuts
yshyn-iohk Nov 22, 2023
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ As a result, you can concentrate on crafting self-sovereign identity solutions u
* HTTP events notification
* Cardano as a distributed ledger
* Secrets management with Hashicorp vault
* Multi-tenancy (coming soon)
* Multi-tenancy

## Example use cases

Expand Down
1 change: 1 addition & 0 deletions docs/docusaurus/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Whether you are new to [self-sovereign identity (SSI)](/docs/concepts/glossary#s


Throughout all code examples in tutorials, the following conventions are in use:
* Issuer Keycloak is hosted at `http://localhost:9980/`
* Issuer Agent is hosted at `http://localhost:8080/prism-agent/`
* Holder Agent is hosted at `http://localhost:8090/prism-agent/`
* Verifier Agent is hosted at `http://localhost:8100/prism-agent/`
Expand Down
175 changes: 175 additions & 0 deletions docs/docusaurus/multitenancy/tenant-migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Migration from `apikey` to `JWT` authentication

PRISM Agent authentication supports multiple authentication methods simultaneously, which means the user can seamlessly use any available credentials including `apikey` or `JWT` to access the wallet.
The agent's [UMA](/docs/concepts/glossary#uma) permission resource also exposes self-service permission endpoint, allowing users to manage the permissions for their wallets.
It allows users to transition from `apikey` to `JWT` authentication without admin intervention.intervention.

## Roles

In the migration process from `apikey` to `JWT`, there is only one role:

1. Tenant

## Prerequisites

1. Keycloak up and running
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
1. Keycloak up and running
1. Keycloak is up and running

2. Keycloak is configured the same as in [Tenant Onboarding Self-Service](./tenant-onboarding-self-service.md)
3. PRISM Agent up and running
4. PRISM Agent is configured the same as in [Tenant Onboarding Self-Service](./tenant-onboarding-self-service.md)
5. The user has access to the wallet using `apikey`. (See [Tenant Onboarding](./tenant-onboarding.md))
6. The user has an account registered on Keycloak

## Overview

This tutorial outlines the steps to transition from `apikey` to `JWT` authentication.
Initially, users have wallet access through the `apikey` method.
To migrate to `JWT` authentication, users can create a new UMA permission for their wallet and grant permission to their Keycloak account.

## Endpoints

### Agent endpoints
| Endpoint | Description | Role |
|--------------------------------------------|--------------------------------------|--------|
| `GET /wallets` | List the wallets on PRISM Agent | Tenant |
| `POST /wallets` | Create a new wallet on PRISM Agent | Tenant |
| `POST /wallets/{walletId}/uma-permissions` | Create a uma-permission for a wallet | Tenant |
| `GET /did-registrar/dids` | List the DIDs inside the wallet | Tenant |

### Keycloak endpoints
| Endpoint | Description | Role |
|------------------------------------------------------|-----------------------|--------|
| `POST /realms/{realm}/protocol/openid-connect/token` | Issue a new JWT token | Tenant |

## Tenant interactions

### 1. Check the existing wallets using `apikey`

This tutorial assumes the tenant can access the wallet using `apikey`.
Before granting more permission to the wallet, the `walletId` must be identified.
To find the wallet, list them using `apikey`.

```bash
curl -X 'GET' \
'http://localhost:8080/prism-agent/wallets' \
-H 'accept: application/json' \
-H "apikey: my-tenant-token"
```

Make sure to use the correct `apikey` from the pre-requisite.

Response Example:

```json
{
"self": "/wallets",
"kind": "WalletPage",
"pageOf": "/wallets",
"contents": [
{
"id": "99734c87-5c9d-4697-b5fd-dea4e9590ba7",
"name": "my-wallet",
"createdAt": "2023-01-01T00:00:00Z",
"updatedAt": "2023-01-01T00:00:00Z"
}
]
}
```

### 2. Get the access token on keycloak

Run this command to log in and get the access token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Run this command to log in and get the access token
Run this command to log in and get the access token:


```bash
curl -X 'POST' \
'http://localhost:9980/realms/my-realm/protocol/openid-connect/token' \
-d "grant_type=password" \
-d "client_id=admin-cli" \
-d "username=alice" \
-d "password=1234"
```

Make sure to use the correct username and password.
Special attention on the `client_id`; this should be the actual `client_id` of the frontend application that logs the user in.
For this tutorial, it is OK to use `admin-cli`

Example token response (some fields omitted for readability)

```json
{
"access_token": "eyJhbGciOi...7ocDHofUDQ",
"refresh_token": "eyJhbGciOi...otsEEi4eQA",
...
}
```

### 3. Extract the subject ID from JWT

When creating a UMA permission, it is important to provide the subject ID to grant permission.
To get the subject ID of the tenant, one can inspect the JWT payload `sub` claim.

Run this command to extract the `sub` claim of the token from previous step.

```bash
echo 'eyJhbGciOi...7ocDHofUDQ' | cut --delimiter='.' --fields=2 | base64 --decode | jq -r '.sub'
```

Example result

```log
4a5c6ac9-12f5-4d1e-b8f2-667525c083fd
```

### 4. Grant the user permission to the wallet

UMA permission can be added to the current wallet, giving Keycloak users access.
To do this, invoke the `POST /wallets/{walletId}/uma-permissions` endpoint on the agent.

```bash
curl -X 'POST' \
'http://localhost:8080/prism-agent/wallets/99734c87-5c9d-4697-b5fd-dea4e9590ba7/uma-permissions' \
-v \
-H 'accept: */*' \
-H "apikey: my-tenant-token" \
-H 'Content-Type: application/json' \
-d '{
"subject": "205e04b7-0158-41b0-89c3-f91c3a09f89b"
}'
```

Make sure to use the correct `subject` for the user and the correct `walletId` from the step earlier.

The response should return the status `200 OK` in case of successful permission creation.

### 5. Perform a simple action to verify access to PRISM Agent

After successful UMA permission creation, the user should be able to use the `JWT` token to authenticate the wallet.
List the wallet using a new `Authorization` header. The listed wallets should contain the wallet with the same ID in step 1.

```bash
curl -X 'GET' \
'http://localhost:8080/prism-agent/wallets' \
-H 'accept: application/json' \
-H 'Authorization: Bearer eyJhbGciOi...7ocDHofUDQ'
```

Make sure to use the correct `JWT` from step 2.

Response Example:

```json
{
"self": "/wallets",
"kind": "WalletPage",
"pageOf": "/wallets",
"contents": [
{
"id": "99734c87-5c9d-4697-b5fd-dea4e9590ba7",
"name": "my-wallet",
"createdAt": "2023-01-01T00:00:00Z",
"updatedAt": "2023-01-01T00:00:00Z"
}
]
}
```

This response indicates that the user should be able to perform any wallet interaction with the `JWT` and `apikey` interchangeably.
Loading
Loading