Skip to content

Commit f8709db

Browse files
authored
chore(auth, backend): removed unused multi-tenancy features, update env variables (#3699)
* feat(auth): add migration to seed operators api secret * feat(auth): propagate apiSecret during tenant creation * test(auth): update api secret tests & tableManager * chore(localenv): update ADMIN_API_SECRET in docker compose files * chore(bruno): update authApiSignatureSecret in requests * feat(auth): add getTenantFromApiSignature middleware * chore(auth): move tenant signature functions to separate file * feat(auth): update authed tenant middleware, and add tests * test(backend): update tenant test * chore(testenv): add ADMIN_API_SECRET to auth * feat(backend): call the auth service client if apiSecret has been updated * test(auth): update tenant signature test name * feat(auth): update tenant response from auth api to include the apiSecet * test(auth): pull out apolloClient creation from test app * feat(auth): add tenantId to GraphQL schema * feat(auth): add tenant boundaries to resolvers * feat(auth): disconnect from redis on app shutdown * test(auth): add additional tests for tenant signature verification * chore(backend): remove auth service client get method * chore(backend): remove unused apolloClient * chore(auth): remove unused GET route for tenant API * chore(auth): remove unused GetContext * chore(backend): fix peer migration * chore(backend): rename API_SECRET and API_SIGNATURE_VERSION * chore(testenv): rename API_SECRET and API_SIGNATURE_VERSION * chore(localenv): rename API_SECRET and API_SIGNATURE_VERSION * chore(localenv): remove unused AUTH_ADMIN_API_URL env vars * chore(backend): update tenantId backfill migration for incoming payments
1 parent 2596efe commit f8709db

File tree

15 files changed

+18
-225
lines changed

15 files changed

+18
-225
lines changed

localenv/cloud-nine-wallet/docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,10 @@ services:
6767
TIGERBEETLE_REPLICA_ADDRESSES: ${TIGERBEETLE_REPLICA_ADDRESSES-''}
6868
AUTH_SERVER_GRANT_URL: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-http://cloud-nine-wallet-auth:3006}
6969
AUTH_SERVER_INTROSPECTION_URL: http://cloud-nine-wallet-auth:3007
70-
AUTH_ADMIN_API_URL: 'http://cloud-nine-wallet-auth:3003/graphql'
71-
AUTH_ADMIN_API_SECRET: 'rPoZpe9tVyBNCigm05QDco7WLcYa0xMao7lO5KG1XG4='
7270
AUTH_SERVICE_API_URL: 'http://cloud-nine-wallet-auth:3011'
7371
ILP_ADDRESS: ${ILP_ADDRESS:-test.cloud-nine-wallet}
7472
STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU=
75-
API_SECRET: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964=
73+
ADMIN_API_SECRET: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964=
7674
OPEN_PAYMENTS_URL: ${CLOUD_NINE_OPEN_PAYMENTS_URL:-https://cloud-nine-wallet-backend}
7775
WEBHOOK_URL: http://cloud-nine-wallet/webhooks
7876
EXCHANGE_RATES_URL: http://cloud-nine-wallet/rates

localenv/happy-life-bank/docker-compose.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ services:
6363
USE_TIGERBEETLE: false
6464
AUTH_SERVER_GRANT_URL: ${HAPPY_LIFE_BANK_AUTH_SERVER_DOMAIN:-http://happy-life-bank-auth:3006}
6565
AUTH_SERVER_INTROSPECTION_URL: http://happy-life-bank-auth:3007
66-
AUTH_ADMIN_API_URL: 'http://happy-life-bank-auth:4003/graphql'
67-
AUTH_ADMIN_API_SECRET: 'rPoZpe9tVyBNCigm05QDco7WLcYa0xMao7lO5KG1XG4='
6866
AUTH_SERVICE_API_URL: 'http://happy-life-bank-auth:4011'
6967
ILP_ADDRESS: test.happy-life-bank
7068
ILP_CONNECTOR_URL: http://happy-life-bank-backend:4002
7169
STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU=
72-
API_SECRET: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964=
70+
ADMIN_API_SECRET: iyIgCprjb9uL8wFckR+pLEkJWMB7FJhgkvqhTQR/964=
7371
WEBHOOK_URL: http://happy-life-bank/webhooks
7472
EXCHANGE_RATES_URL: http://happy-life-bank/rates
7573
OPEN_PAYMENTS_URL: ${HAPPY_LIFE_BANK_OPEN_PAYMENTS_URL:-https://happy-life-bank-backend}

packages/auth/src/app.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,6 @@ export class App {
511511

512512
const tenantRoutes = await this.container.use('tenantRoutes')
513513

514-
router.get('/tenant/:id', tenantRoutes.get)
515514
router.post('/tenant', tenantRoutes.create)
516515
router.patch('/tenant/:id', tenantRoutes.update)
517516
router.delete('/tenant/:id', tenantRoutes.delete)

packages/auth/src/tenant/routes.test.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import {
1212
UpdateContext,
1313
DeleteContext,
1414
TenantRoutes,
15-
createTenantRoutes,
16-
GetContext
15+
createTenantRoutes
1716
} from './routes'
1817
import { TenantService } from './service'
1918
import { Tenant } from './model'
@@ -44,56 +43,6 @@ describe('Tenant Routes', (): void => {
4443
await appContainer.shutdown()
4544
})
4645

47-
describe('get', (): void => {
48-
test('Gets a tenant', async (): Promise<void> => {
49-
const tenant = await Tenant.query().insert({
50-
id: v4(),
51-
apiSecret: v4(),
52-
idpConsentUrl: 'https://example.com/consent',
53-
idpSecret: 'secret123'
54-
})
55-
56-
const ctx = createContext<GetContext>(
57-
{
58-
headers: {
59-
Accept: 'application/json',
60-
'Content-Type': 'application/json'
61-
}
62-
},
63-
{
64-
id: tenant.id
65-
}
66-
)
67-
68-
await expect(tenantRoutes.get(ctx)).resolves.toBeUndefined()
69-
expect(ctx.status).toBe(200)
70-
expect(ctx.body).toEqual({
71-
id: tenant.id,
72-
apiSecret: tenant.apiSecret,
73-
idpConsentUrl: tenant.idpConsentUrl,
74-
idpSecret: tenant.idpSecret
75-
})
76-
})
77-
78-
test('Returns 404 when getting non-existent tenant', async (): Promise<void> => {
79-
const ctx = createContext<GetContext>(
80-
{
81-
headers: {
82-
Accept: 'application/json',
83-
'Content-Type': 'application/json'
84-
}
85-
},
86-
{
87-
id: v4()
88-
}
89-
)
90-
91-
await expect(tenantRoutes.get(ctx)).resolves.toBeUndefined()
92-
expect(ctx.status).toBe(404)
93-
expect(ctx.body).toBeUndefined()
94-
})
95-
})
96-
9746
describe('create', (): void => {
9847
test('Creates a tenant', async (): Promise<void> => {
9948
const tenantData = {

packages/auth/src/tenant/routes.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ParsedUrlQuery } from 'querystring'
22
import { AppContext } from '../app'
33
import { TenantService } from './service'
44
import { BaseService } from '../shared/baseService'
5-
import { Tenant } from './model'
65
import { isValidDateString } from '../shared/utils'
76

87
type TenantRequest<BodyT = never, QueryT = ParsedUrlQuery> = Exclude<
@@ -33,20 +32,11 @@ interface TenantParams {
3332
id: string
3433
}
3534

36-
interface TenantResponse {
37-
id: string
38-
apiSecret: string
39-
idpConsentUrl?: string
40-
idpSecret?: string
41-
}
42-
43-
export type GetContext = TenantContext<never, TenantParams>
4435
export type CreateContext = TenantContext<CreateTenantBody>
4536
export type UpdateContext = TenantContext<UpdateTenantBody, TenantParams>
4637
export type DeleteContext = TenantContext<{ deletedAt: string }, TenantParams>
4738

4839
export interface TenantRoutes {
49-
get(ctx: GetContext): Promise<void>
5040
create(ctx: CreateContext): Promise<void>
5141
update(ctx: UpdateContext): Promise<void>
5242
delete(ctx: DeleteContext): Promise<void>
@@ -67,7 +57,6 @@ export function createTenantRoutes({
6757
const deps = { tenantService, logger: log }
6858

6959
return {
70-
get: (ctx: GetContext) => getTenant(deps, ctx),
7160
create: (ctx: CreateContext) => createTenant(deps, ctx),
7261
update: (ctx: UpdateContext) => updateTenant(deps, ctx),
7362
delete: (ctx: DeleteContext) => deleteTenant(deps, ctx)
@@ -123,28 +112,3 @@ async function deleteTenant(
123112

124113
ctx.status = 204
125114
}
126-
127-
async function getTenant(
128-
deps: ServiceDependencies,
129-
ctx: GetContext
130-
): Promise<void> {
131-
const { id } = ctx.params
132-
const tenant = await deps.tenantService.get(id)
133-
134-
if (!tenant) {
135-
ctx.status = 404
136-
return
137-
}
138-
139-
ctx.status = 200
140-
ctx.body = toTenantResponse(tenant)
141-
}
142-
143-
function toTenantResponse(tenant: Tenant): TenantResponse {
144-
return {
145-
id: tenant.id,
146-
apiSecret: tenant.apiSecret,
147-
idpConsentUrl: tenant.idpConsentUrl,
148-
idpSecret: tenant.idpSecret
149-
}
150-
}

packages/backend/jest.env.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ process.env.WEBHOOK_URL = 'http://127.0.0.1:4001/webhook'
1111
process.env.STREAM_SECRET = '2/PxuRFV9PAp0yJlnAifJ+1OxujjjI16lN+DBnLNRLA='
1212
process.env.USE_TIGERBEETLE = false
1313
process.env.ENABLE_TELEMETRY = false
14-
process.env.AUTH_ADMIN_API_URL = 'http://127.0.0.1:3003/graphql'
15-
process.env.AUTH_ADMIN_API_SECRET = 'test-secret'
1614
process.env.OPERATOR_TENANT_ID = 'cf5fd7d3-1eb1-4041-8e43-ba45747e9e5d'
17-
process.env.API_SECRET = 'KQEXlZO65jUJXakXnLxGO7dk387mt71G9tZ42rULSNU='
15+
process.env.ADMIN_API_SECRET = 'KQEXlZO65jUJXakXnLxGO7dk387mt71G9tZ42rULSNU='
1816
process.env.EXCHANGE_RATES_URL = 'http://example.com/rates'

packages/backend/migrations/20241205153035_seed_operator_tenant.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
*/
55

66
const OPERATOR_TENANT_ID = process.env['OPERATOR_TENANT_ID']
7-
const OPERATOR_API_SECRET = process.env['API_SECRET']
7+
const OPERATOR_API_SECRET = process.env['ADMIN_API_SECRET']
88

99
exports.up = function (knex) {
1010
if (!OPERATOR_TENANT_ID || !OPERATOR_API_SECRET) {
1111
throw new Error(
12-
'Could not seed operator tenant. Please configure OPERATOR_TENANT_ID and API_SECRET environment variables'
12+
'Could not seed operator tenant. Please configure OPERATOR_TENANT_ID and ADMIN_API_SECRET environment variables'
1313
)
1414
}
1515

packages/backend/migrations/20250120101610_add_tenant_to_incoming_payments.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ exports.up = function (knex) {
99
table.foreign('tenantId').references('id').inTable('tenants')
1010
})
1111
.then(() => {
12-
knex.raw(
12+
return knex.raw(
1313
`UPDATE "incomingPayments" SET "tenantId" = (SELECT id from "tenants" LIMIT 1)`
1414
)
1515
})
1616
.then(() => {
17-
knex.schema.alterTable('incomingPayments', function (table) {
18-
table.uuid('tenantId').notNullable()
17+
return knex.schema.alterTable('incomingPayments', function (table) {
18+
table.uuid('tenantId').notNullable().alter()
1919
})
2020
})
2121
}

packages/backend/migrations/20250214141958_add_tenant_to_peer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ exports.up = function (knex) {
99
table.foreign('tenantId').references('id').inTable('tenants')
1010
})
1111
.then(() => {
12-
knex.raw(
12+
return knex.raw(
1313
`UPDATE "peers" SET "tenantId" = (SELECT id from "tenants" LIMIT 1)`
1414
)
1515
})
1616
.then(() => {
17-
knex.schema.alterTable('peers', function (table) {
18-
table.uuid('tenantId').notNullable()
17+
return knex.schema.alterTable('peers', function (table) {
18+
table.uuid('tenantId').notNullable().alter()
1919
})
2020
})
2121
}

packages/backend/src/auth-service-client/client.test.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,6 @@ describe('AuthServiceClient', () => {
2323
})
2424

2525
describe('tenant', () => {
26-
describe('get', () => {
27-
test('retrieves a tenant', async () => {
28-
const tenantData = createTenantData()
29-
30-
nock(baseUrl).get(`/tenant/${tenantData.id}`).reply(200, tenantData)
31-
32-
const tenant = await client.tenant.get(tenantData.id)
33-
expect(tenant).toEqual(tenantData)
34-
})
35-
36-
test('throws on bad request', async () => {
37-
const id = faker.string.uuid()
38-
39-
nock(baseUrl).get(`/tenant/${id}`).reply(404)
40-
41-
await expect(client.tenant.get(id)).rejects.toThrow(
42-
AuthServiceClientError
43-
)
44-
})
45-
})
46-
4726
describe('create', () => {
4827
test('creates a new tenant', async () => {
4928
const tenantData = createTenantData()

0 commit comments

Comments
 (0)