diff --git a/services/api/src/app.ts b/services/api/src/app.ts index cd2983ebf0..256575e6ad 100644 --- a/services/api/src/app.ts +++ b/services/api/src/app.ts @@ -22,7 +22,15 @@ app.use(json()); app.use( morgan('combined', { skip: (req, res) => { - return req.originalUrl.startsWith('/status'); + if (req.originalUrl.startsWith('/status')) { + return req.originalUrl.startsWith('/status') + } + if (req.originalUrl.startsWith('/favicon.ico')) { + return req.originalUrl.startsWith('/favicon.ico') + } + if (req.originalUrl.startsWith('/.well-known')) { + return req.originalUrl.startsWith('/.well-known') + } }, stream: { write: message => logger.info(message.trim()) diff --git a/services/api/src/authMiddleware.ts b/services/api/src/authMiddleware.ts index 6330551009..79d486e1b0 100644 --- a/services/api/src/authMiddleware.ts +++ b/services/api/src/authMiddleware.ts @@ -44,6 +44,10 @@ const authenticateJWT = async ( if (req.url === '/status') { return next(); } + // Allow access to status without auth. + if (req.url === '/.well-known/appspecific/sh.lagoon.discovery.json') { + return next(); + } // @ts-ignore const token = getBearerTokenFromHeader(req.get('Authorization')); diff --git a/services/api/src/routes/index.ts b/services/api/src/routes/index.ts index bb24954e70..fe14c1c1e4 100644 --- a/services/api/src/routes/index.ts +++ b/services/api/src/routes/index.ts @@ -1,6 +1,7 @@ import express, { Request, Response } from 'express'; import statusRoute from './status'; import keysRoute from './keys'; +import wellKnown from './well-known'; export function createRouter() { const router = express.Router(); @@ -13,6 +14,9 @@ export function createRouter() { // Fetch the current api status. router.get('/status', ...statusRoute); + // Fetch the well-known. + router.get('/.well-known/appspecific/sh.lagoon.discovery.json', ...wellKnown); + // Return keys of all customers router.post('/keys', ...keysRoute); diff --git a/services/api/src/routes/well-known.ts b/services/api/src/routes/well-known.ts new file mode 100644 index 0000000000..afcfc92b74 --- /dev/null +++ b/services/api/src/routes/well-known.ts @@ -0,0 +1,18 @@ +import { Request, Response } from 'express'; +import { envHasConfig, getConfigFromEnv } from '../util/config'; + +const wellKnown = (req: Request, res: Response) => { + let discoverData = { + lagoon_version: getConfigFromEnv('LAGOON_VERSION',''), + authorization_endpoint: getConfigFromEnv('KEYCLOAK_URL', ''), + ssh_token_exchange: { + token_endpoint_host: getConfigFromEnv('SSH_TOKEN_ENDPOINT', ''), + token_endpoint_port: parseInt(getConfigFromEnv('SSH_TOKEN_ENDPOINT_PORT', '22'), 10) + }, + webhook_endpoint: getConfigFromEnv('WEBHOOK_URL', ''), + ui_url: getConfigFromEnv('UI_URL',''), + } + res.json(discoverData); +}; + +export default [wellKnown]; diff --git a/tests/checks/check-api-request.yaml b/tests/checks/check-api-request.yaml index 9c66f09f2e..20f9b025cc 100644 --- a/tests/checks/check-api-request.yaml +++ b/tests/checks/check-api-request.yaml @@ -6,6 +6,6 @@ headers: Authorization: "Bearer {{ bearer_token }}" register: result - until: result.content is match(expected_content) + until: result.content is search(expected_content) retries: 1 delay: 0 diff --git a/tests/tests/features/api-token.yaml b/tests/tests/features/api-token.yaml index d1664bb7e2..e6ef97e052 100644 --- a/tests/tests/features/api-token.yaml +++ b/tests/tests/features/api-token.yaml @@ -10,6 +10,6 @@ vars: url: "{{ lookup('env','API_PROTOCOL') }}://{{ lookup('env','API_HOST') }}:{{ lookup('env','API_PORT') }}/" bearer_token: "{{ token }}" - expected_content: '{"status":"success","data":{}}' + expected_content: 'success' tasks: - ansible.builtin.include_tasks: ../../checks/check-api-request.yaml