Skip to content

v2.0.0-beta

Choose a tag to compare

@github-actions github-actions released this 16 Oct 19:41
· 36 commits to main since this release
f8709db

🚀 Multi-tenancy support added

Overview

In this release, we have added support for multi-tenancy in Rafiki. This allows single Rafiki instance to service multiple account servicing entities (ASEs).

There is no "opt out" of multi-tenancy, Rafiki is multi-tenant by default.

Migration guide

The entity responsible for managing a Rafiki instance that serves multiple ASEs is called an operator. When upgrading from v1-beta version of Rafiki to v2-beta, an operator tenant is seeded automatically (given the environment variables below) and all of the existing resources are backfilled to reference the operator tenant.

An operator is then able to create individual tenants, and create, manage resources & liquidity for them. This is done through the backend Admin API. The tenant details/settings (and the updates to those details) are propagated to the auth service with a new "tenant" auth API.

At a high level, the main changes require:

  1. Generating a V4 UUID to set as the operator id
  2. Start signing Admin API requests to both backend and auth APIs, if not done so already. This is necessary to determine which tenant is making a request to the APIs.
  3. Expose the tenant API in auth to listen to any tenant information changes propagated from backend.
Necessary auth changes
  1. Set OPERATOR_TENANT_ID to a V4 UUID.
  2. ADMIN_API_SECRET to a strong, random secret.
  3. Expose the tenant service API port (by default it is 3011). This is to listen to any changes to the tenant information from backend.
Necessary backend changes
  1. Set OPERATOR_TENANT_ID to a V4 UUID (the same as the auth).
  2. Set ADMIN_API_SECRET to a strong, random secret. (for ease of use when signing requests, set it to same as the auth).
    Please note, if you were already signing the Admin API requests to backend, API_SECRET was renamed to ADMIN_API_SECRET, and API_SIGNATURE_VERSION was renamed to API_SIGNATURE_VERSION.
  3. Set AUTH_SERVICE_API_URL to the full URL of new exposed tenant auth service.
Necessary frontend changes
  1. When first interacting with frontend, the tenant (or operator) credentials must be entered akin to a login screen.
Necessary changes to your integration server
  1. Update createWalletAddress mutation input. Now, instead of a full url path, the mutation takes in address, which could be a full URL or just a path. If a path is entered, it will act as a suffix to the defined OPEN_PAYMENTS_URL if the request is on behalf of an operator, or a suffix to the defined wallet address URL tenant setting, if the request is from a non-operator tenant.
  2. Update walletAddress resolver to fetch address instead of url.
  3. Start signing requests to the backend and auth Admin APIs. An example of signing requests with the Apollo GraphQL client can be found in our mock-ase here.
    Example code:
const httpLink = new HttpLink({
  uri: process.env.ADMIN_API_URL,
  enhancedClientAwareness: { transport: false } // necessary to avoid adding additional properties into request object
});

const createAuthLink = (args: { tenantId: string, apiSecret: string, signatureVersion: number }) => {
  return setContext((request, { headers }) => {
    
    const timestamp = Date.now()

    const { query, variables, operationName } = request
    const formattedRequest = {
      variables,
      operationName,
      query: print(query)
    }

    const payload = `${timestamp}.${canonicalize(formattedRequest)}`
    
    const digest = createHmac('sha256', args.apiSecret)
      .update(payload)
      .digest('hex')

    return {
      headers: {
        ...headers,
        signature: `t=${timestamp}, v${args.signatureVersion}=${digest}`,
        ['tenant-id']: args.tenantId
      }
    };
  })
}

✨ New Features

🐛 Bug Fixes

🔧 Chores