From 397d13bf8cb009951335fb4d0ff2fb01759bc6fa Mon Sep 17 00:00:00 2001 From: simonredfern Date: Tue, 20 Oct 2026 15:59:09 +0100 Subject: [PATCH 01/16] Related to the git commit --- .github/workflows/build_container_image.yml | 4 ++-- Dockerfiles/Dockerfile_backend | 4 ++++ server/app.ts | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_container_image.yml b/.github/workflows/build_container_image.yml index df85909..942bca5 100644 --- a/.github/workflows/build_container_image.yml +++ b/.github/workflows/build_container_image.yml @@ -19,12 +19,12 @@ jobs: run: | if [ "${{ github.ref }}" == "refs/heads/develop" ]; then echo start building api-explorer-ii containers develop branch with latest tag - docker build . --file Dockerfiles/Dockerfile_backend --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}:$GITHUB_SHA --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ steps.extract_branch.outputs.branch }} --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}:latest + docker build . --file Dockerfiles/Dockerfile_backend --build-arg GIT_COMMIT=$GITHUB_SHA --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}:$GITHUB_SHA --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ steps.extract_branch.outputs.branch }} --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}:latest docker build . --file Dockerfiles/Dockerfile_frontend --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}-nginx:$GITHUB_SHA --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}-nginx:${{ steps.extract_branch.outputs.branch }} --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}-nginx:latest echo building api-explorer-ii containers develop branch with latest tag done else echo start building api-explorer-ii containers non-develop branch without latest tag - docker build . --file Dockerfiles/Dockerfile_backend --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}:$GITHUB_SHA --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ steps.extract_branch.outputs.branch }} + docker build . --file Dockerfiles/Dockerfile_backend --build-arg GIT_COMMIT=$GITHUB_SHA --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}:$GITHUB_SHA --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}:${{ steps.extract_branch.outputs.branch }} docker build . --file Dockerfiles/Dockerfile_frontend --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}-nginx:$GITHUB_SHA --tag docker.io/${{ env.DOCKER_HUB_ORGANIZATION }}/${{ env.DOCKER_HUB_REPOSITORY }}-nginx:${{ steps.extract_branch.outputs.branch }} echo building api-explorer-ii containers non-develop branch without latest tag done fi diff --git a/Dockerfiles/Dockerfile_backend b/Dockerfiles/Dockerfile_backend index 596184c..1c940cf 100644 --- a/Dockerfiles/Dockerfile_backend +++ b/Dockerfiles/Dockerfile_backend @@ -12,6 +12,10 @@ RUN npm run build-server # CMD npm run -d start FROM node:lts-slim +# The commit the image is built from (the image has no .git), reported in Telemetry and on the status page +ARG GIT_COMMIT=unknown +ENV GIT_COMMIT=$GIT_COMMIT + COPY --from=builder /home/node/app/dist-server /home/node/app RUN mkdir /home/node/node_modules COPY --from=builder /home/node/app/node_modules /home/node/node_modules diff --git a/server/app.ts b/server/app.ts index 5ecb1db..21bbfb3 100644 --- a/server/app.ts +++ b/server/app.ts @@ -218,10 +218,13 @@ let instance: any `Backend is running. You can check a status at http://localhost:${port}${routePrefix}/status` ) - // Get commit ID + // Get commit ID: from GIT_COMMIT, set when the Docker image is built, else from the git checkout try { // Try to get the commit ID - commitId = execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim() + commitId = + process.env.GIT_COMMIT && process.env.GIT_COMMIT !== 'unknown' + ? process.env.GIT_COMMIT + : execSync('git rev-parse HEAD', { encoding: 'utf-8' }).trim() console.log('Current Commit ID:', commitId) } catch (error: any) { // Log the error but do not terminate the process From 85316d0b33663e8b6edfeee915dff9ca83812bb1 Mon Sep 17 00:00:00 2001 From: Simon Redfern Date: Tue, 3 Nov 2026 18:01:21 +0100 Subject: [PATCH 02/16] UserXORApplication --- server/test/monitoring.test.ts | 23 ++++++++++++++--------- server/utils/obpRoleCheck.ts | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/server/test/monitoring.test.ts b/server/test/monitoring.test.ts index 70893f9..57ed95b 100644 --- a/server/test/monitoring.test.ts +++ b/server/test/monitoring.test.ts @@ -72,15 +72,20 @@ describe('obpRoleCheck', () => { const answer = (status: number, modes: string[] = []) => Promise.resolve(new Response(JSON.stringify({ allowed_for_auth_modes: modes }), { status })) - it('allows a token OBP-API allows for UserOrApplication, asking at SYS', async () => { - fetchMock.mockReturnValueOnce(answer(200, ['ApplicationOnly', 'UserOrApplication'])) + it('allows a token OBP-API allows for UserXORApplication, asking at SYS', async () => { + fetchMock.mockReturnValueOnce(answer(200, ['ApplicationOnly', 'UserXORApplication'])) expect(await tokenMayUseAnyRole('http://obp', 't', ['CanGetTelemetry'])).toBe('allowed') expect(fetchMock.mock.calls[0][0]).toBe('http://obp/obp/v7.0.0/banks/SYS/my/roles/CanGetTelemetry') expect(fetchMock.mock.calls[0][1].headers.Authorization).toBe('Bearer t') }) + it('refuses a token OBP-API allows only for ApplicationOnly', async () => { + fetchMock.mockReturnValueOnce(answer(200, ['ApplicationOnly'])) + expect(await tokenMayUseAnyRole('http://obp', 't', ['CanGetTelemetry'])).toBe('forbidden') + }) + it('tries the next Role when one is not allowed', async () => { - fetchMock.mockReturnValueOnce(answer(200, ['UserOnly'])).mockReturnValueOnce(answer(200, ['UserOrApplication'])) + fetchMock.mockReturnValueOnce(answer(200, ['UserOnly'])).mockReturnValueOnce(answer(200, ['UserXORApplication'])) expect(await tokenMayUseAnyRole('http://obp', 't', ['CanGetSystemLogCacheError', 'CanGetSystemLogCacheAll'])).toBe('allowed') expect(fetchMock).toHaveBeenCalledTimes(2) }) @@ -93,7 +98,7 @@ describe('obpRoleCheck', () => { }) it('reuses an answer for a minute', async () => { - fetchMock.mockImplementation(() => answer(200, ['UserOrApplication'])) + fetchMock.mockImplementation(() => answer(200, ['UserXORApplication'])) await tokenMayUseAnyRole('http://obp', 't', ['A'], 0) await tokenMayUseAnyRole('http://obp', 't', ['A'], 59_999) expect(fetchMock).toHaveBeenCalledTimes(1) @@ -105,9 +110,9 @@ describe('obpRoleCheck', () => { describe('monitoring endpoints', () => { // A fake OBP-API: what each token may do, as GET /banks/SYS/my/roles/ROLE answers it. const tokens: Record> = { - 'error-reader': { CanGetSystemLogCacheError: ['UserOrApplication'] }, - 'all-reader': { CanGetSystemLogCacheAll: ['UserOrApplication'] }, - 'telemetry-reader': { CanGetTelemetry: ['UserOrApplication'] }, + 'error-reader': { CanGetSystemLogCacheError: ['UserXORApplication'] }, + 'all-reader': { CanGetSystemLogCacheAll: ['UserXORApplication'] }, + 'telemetry-reader': { CanGetTelemetry: ['UserXORApplication'] }, 'user-only': { CanGetSystemLogCacheAll: ['UserOnly'], CanGetTelemetry: ['UserOnly'] }, 'no-roles': {} } @@ -151,7 +156,7 @@ describe('monitoring endpoints', () => { const capitalised = (level: string) => level.charAt(0).toUpperCase() + level.slice(1) it.each(levels)('returns the %s log cache to a token allowed its level Role or the All Role', async (level) => { - tokens[`${level}-only`] = { [`CanGetSystemLogCache${capitalised(level)}`]: ['UserOrApplication'] } + tokens[`${level}-only`] = { [`CanGetSystemLogCache${capitalised(level)}`]: ['UserXORApplication'] } for (const token of [`${level}-only`, 'all-reader']) { const res = await get(`/api/monitoring/log-cache/${level}`, token) expect(res.status).toBe(200) @@ -161,7 +166,7 @@ describe('monitoring endpoints', () => { it.each(levels)('refuses the %s log cache to tokens without its Roles, returning no lines', async (level) => { for (const token of ['no-roles', 'telemetry-reader', 'user-only', level === 'error' ? 'all-but-error' : 'error-reader']) { - tokens['all-but-error'] = { CanGetSystemLogCacheInfo: ['UserOrApplication'] } + tokens['all-but-error'] = { CanGetSystemLogCacheInfo: ['UserXORApplication'] } const res = await get(`/api/monitoring/log-cache/${level}`, token) expect(res.status).toBe(403) expect(res.body.entries).toBeUndefined() diff --git a/server/utils/obpRoleCheck.ts b/server/utils/obpRoleCheck.ts index 83a43c0..71e643f 100644 --- a/server/utils/obpRoleCheck.ts +++ b/server/utils/obpRoleCheck.ts @@ -30,7 +30,7 @@ import type { NextFunction, Request, Response } from 'express' // Whether an OBP-API token may see what this server guards with an OBP Role. OBP-API answers, through // GET /obp/v7.0.0/banks/SYS/my/roles/ROLE_NAME, with the same rules its own endpoints use: the token's -// User holds the Role, or its Consumer holds it as a Scope (auth mode UserOrApplication). +// User holds the Role, or its Consumer holds it as a Scope (auth mode UserXORApplication). export type RoleCheck = 'allowed' | 'unauthorized' | 'forbidden' @@ -52,7 +52,7 @@ async function checkRole(obpApiHost: string, token: string, role: string): Promi return 'forbidden' } const body = await response.json() - return body.allowed_for_auth_modes?.includes('UserOrApplication') ? 'allowed' : 'forbidden' + return body.allowed_for_auth_modes?.includes('UserXORApplication') ? 'allowed' : 'forbidden' } /** Allowed if the token may use any one of the Roles, as an endpoint needing any of them would decide. */ From 80256c925fcf85edca4cc1ff75869a071eed98e7 Mon Sep 17 00:00:00 2001 From: Simon Redfern Date: Tue, 10 Nov 2026 10:13:32 +0100 Subject: [PATCH 03/16] Use OBP-API's new yes-or-no answer for monitoring access The monitoring pages check whether a token may use a Role by asking OBP-API, at GET /obp/v7.0.0/banks/SYS/my/roles/ROLE_NAME. OBP-API used to answer with a list of auth modes, and the check looked for UserXORApplication in that list. OBP-API has now removed auth modes. Instead it answers with a single field, allowed, which is true or false. The check now reads that field. Without this change, the monitoring pages would refuse every token once OBP-API is upgraded. --- server/test/monitoring.test.ts | 38 +++++++++++++++++----------------- server/utils/obpRoleCheck.ts | 6 +++--- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/server/test/monitoring.test.ts b/server/test/monitoring.test.ts index 57ed95b..8fd3525 100644 --- a/server/test/monitoring.test.ts +++ b/server/test/monitoring.test.ts @@ -69,36 +69,36 @@ describe('obpRoleCheck', () => { }) afterEach(() => vi.unstubAllGlobals()) - const answer = (status: number, modes: string[] = []) => - Promise.resolve(new Response(JSON.stringify({ allowed_for_auth_modes: modes }), { status })) + const answer = (status: number, allowed = false) => + Promise.resolve(new Response(JSON.stringify({ allowed }), { status })) - it('allows a token OBP-API allows for UserXORApplication, asking at SYS', async () => { - fetchMock.mockReturnValueOnce(answer(200, ['ApplicationOnly', 'UserXORApplication'])) + it('allows a token OBP-API allows, asking at SYS', async () => { + fetchMock.mockReturnValueOnce(answer(200, true)) expect(await tokenMayUseAnyRole('http://obp', 't', ['CanGetTelemetry'])).toBe('allowed') expect(fetchMock.mock.calls[0][0]).toBe('http://obp/obp/v7.0.0/banks/SYS/my/roles/CanGetTelemetry') expect(fetchMock.mock.calls[0][1].headers.Authorization).toBe('Bearer t') }) - it('refuses a token OBP-API allows only for ApplicationOnly', async () => { - fetchMock.mockReturnValueOnce(answer(200, ['ApplicationOnly'])) + it('refuses a token OBP-API does not allow', async () => { + fetchMock.mockReturnValueOnce(answer(200, false)) expect(await tokenMayUseAnyRole('http://obp', 't', ['CanGetTelemetry'])).toBe('forbidden') }) it('tries the next Role when one is not allowed', async () => { - fetchMock.mockReturnValueOnce(answer(200, ['UserOnly'])).mockReturnValueOnce(answer(200, ['UserXORApplication'])) + fetchMock.mockReturnValueOnce(answer(200, false)).mockReturnValueOnce(answer(200, true)) expect(await tokenMayUseAnyRole('http://obp', 't', ['CanGetSystemLogCacheError', 'CanGetSystemLogCacheAll'])).toBe('allowed') expect(fetchMock).toHaveBeenCalledTimes(2) }) it('refuses when no Role is allowed, and says unauthorized when OBP-API rejects the token', async () => { - fetchMock.mockReturnValueOnce(answer(200, [])).mockReturnValueOnce(answer(404)) + fetchMock.mockReturnValueOnce(answer(200, false)).mockReturnValueOnce(answer(404)) expect(await tokenMayUseAnyRole('http://obp', 't', ['A', 'B'])).toBe('forbidden') fetchMock.mockReturnValueOnce(answer(401)) expect(await tokenMayUseAnyRole('http://obp', 'bad', ['A'])).toBe('unauthorized') }) it('reuses an answer for a minute', async () => { - fetchMock.mockImplementation(() => answer(200, ['UserXORApplication'])) + fetchMock.mockImplementation(() => answer(200, true)) await tokenMayUseAnyRole('http://obp', 't', ['A'], 0) await tokenMayUseAnyRole('http://obp', 't', ['A'], 59_999) expect(fetchMock).toHaveBeenCalledTimes(1) @@ -109,11 +109,11 @@ describe('obpRoleCheck', () => { describe('monitoring endpoints', () => { // A fake OBP-API: what each token may do, as GET /banks/SYS/my/roles/ROLE answers it. - const tokens: Record> = { - 'error-reader': { CanGetSystemLogCacheError: ['UserXORApplication'] }, - 'all-reader': { CanGetSystemLogCacheAll: ['UserXORApplication'] }, - 'telemetry-reader': { CanGetTelemetry: ['UserXORApplication'] }, - 'user-only': { CanGetSystemLogCacheAll: ['UserOnly'], CanGetTelemetry: ['UserOnly'] }, + const tokens: Record> = { + 'error-reader': { CanGetSystemLogCacheError: true }, + 'all-reader': { CanGetSystemLogCacheAll: true }, + 'telemetry-reader': { CanGetTelemetry: true }, + 'not-allowed': { CanGetSystemLogCacheAll: false, CanGetTelemetry: false }, 'no-roles': {} } const fakeObpApi = vi.fn(async (url: string, init: any) => { @@ -121,7 +121,7 @@ describe('monitoring endpoints', () => { if (!url.startsWith('http://obp/obp/v7.0.0/banks/SYS/my/roles/')) return new Response('{}', { status: 404 }) if (!(token in tokens)) return new Response('{}', { status: 401 }) const role = decodeURIComponent(url.split('/').pop()!) - return new Response(JSON.stringify({ allowed_for_auth_modes: tokens[token][role] ?? [] }), { status: 200 }) + return new Response(JSON.stringify({ allowed: tokens[token][role] ?? false }), { status: 200 }) }) // Stands in for the session middleware: a header X-Test-Session-Token puts that token in the session. @@ -156,7 +156,7 @@ describe('monitoring endpoints', () => { const capitalised = (level: string) => level.charAt(0).toUpperCase() + level.slice(1) it.each(levels)('returns the %s log cache to a token allowed its level Role or the All Role', async (level) => { - tokens[`${level}-only`] = { [`CanGetSystemLogCache${capitalised(level)}`]: ['UserXORApplication'] } + tokens[`${level}-only`] = { [`CanGetSystemLogCache${capitalised(level)}`]: true } for (const token of [`${level}-only`, 'all-reader']) { const res = await get(`/api/monitoring/log-cache/${level}`, token) expect(res.status).toBe(200) @@ -165,8 +165,8 @@ describe('monitoring endpoints', () => { }) it.each(levels)('refuses the %s log cache to tokens without its Roles, returning no lines', async (level) => { - for (const token of ['no-roles', 'telemetry-reader', 'user-only', level === 'error' ? 'all-but-error' : 'error-reader']) { - tokens['all-but-error'] = { CanGetSystemLogCacheInfo: ['UserXORApplication'] } + for (const token of ['no-roles', 'telemetry-reader', 'not-allowed', level === 'error' ? 'all-but-error' : 'error-reader']) { + tokens['all-but-error'] = { CanGetSystemLogCacheInfo: true } const res = await get(`/api/monitoring/log-cache/${level}`, token) expect(res.status).toBe(403) expect(res.body.entries).toBeUndefined() @@ -188,7 +188,7 @@ describe('monitoring endpoints', () => { expect(ok.status).toBe(200) expect(ok.body.git_commit).toBe('test-commit') expect(ok.body.meters.length).toBeGreaterThan(0) - for (const token of ['all-reader', 'user-only', 'no-roles']) { + for (const token of ['all-reader', 'not-allowed', 'no-roles']) { const res = await get('/api/monitoring/telemetry', token) expect(res.status).toBe(403) expect(res.body.meters).toBeUndefined() diff --git a/server/utils/obpRoleCheck.ts b/server/utils/obpRoleCheck.ts index 71e643f..3f3ec24 100644 --- a/server/utils/obpRoleCheck.ts +++ b/server/utils/obpRoleCheck.ts @@ -29,8 +29,8 @@ import { createHash } from 'crypto' import type { NextFunction, Request, Response } from 'express' // Whether an OBP-API token may see what this server guards with an OBP Role. OBP-API answers, through -// GET /obp/v7.0.0/banks/SYS/my/roles/ROLE_NAME, with the same rules its own endpoints use: the token's -// User holds the Role, or its Consumer holds it as a Scope (auth mode UserXORApplication). +// GET /obp/v7.0.0/banks/SYS/my/roles/ROLE_NAME, with the same rules its own endpoints use: a person needs the +// Role as an Entitlement, and an application acting as itself (a Platform App) needs it as a Scope. export type RoleCheck = 'allowed' | 'unauthorized' | 'forbidden' @@ -52,7 +52,7 @@ async function checkRole(obpApiHost: string, token: string, role: string): Promi return 'forbidden' } const body = await response.json() - return body.allowed_for_auth_modes?.includes('UserXORApplication') ? 'allowed' : 'forbidden' + return body.allowed === true ? 'allowed' : 'forbidden' } /** Allowed if the token may use any one of the Roles, as an endpoint needing any of them would decide. */ From 573f940b4b3ebfef03354e1ca74d354ffa7efcc1 Mon Sep 17 00:00:00 2001 From: Simon Redfern Date: Thu, 19 Nov 2026 08:41:52 +0100 Subject: [PATCH 04/16] Glossary links better --- src/views/GlossaryView.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/views/GlossaryView.vue b/src/views/GlossaryView.vue index 2bca854..2ab1bba 100644 --- a/src/views/GlossaryView.vue +++ b/src/views/GlossaryView.vue @@ -26,7 +26,8 @@ -->