Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24fb8cdc56 | ||
|
|
710dcfc7c9 | ||
|
|
c50ef814e2 | ||
|
|
30001062d4 | ||
|
|
92f0314a20 | ||
|
|
fa75f8317d | ||
|
|
90b6c509c0 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ipwhitelist",
|
||||
"version": "0.5.147",
|
||||
"version": "0.5.150",
|
||||
"description": "IP WhiteList microservice for cloud provider",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
// ── IAM API ───────────────────────────────────────────────────────────────────
|
||||
// URL IAM-сервиса для получения профилей пользователя (GET /api/v1/auth/user)
|
||||
// и переключения активной компании (POST /api/v1/user/switch-profile).
|
||||
const IAM_API_URL = (process.env.IAM_API_URL || 'https://auth-api-dev.ngcloud.ru').replace(/\/$/, '');
|
||||
const IAM_API_URL = (process.env.IAM_API_URL || 'https://auth-api.ngcloud.ru').replace(/\/$/, '');
|
||||
|
||||
// ── Мок-пользователи (только dev/staging) ─────────────────────────────────────
|
||||
// В продакшене этот список не используется — вход через Keycloak.
|
||||
|
||||
+43
-15
@@ -69,7 +69,7 @@ function createV2Router() {
|
||||
const token = req.session && req.session.token;
|
||||
if (!token) return res.send('<h2>Нет токена</h2><p><a href="/v2/login">Войти</a></p>');
|
||||
try {
|
||||
const raw = await iamFetch(token, 'https://auth-api-test.ngcloud.ru/api/v1/auth/user');
|
||||
const raw = await iamFetch(token, config.iamApiBase + '/auth/user');
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
res.send(rawPage('IAM TEST', raw));
|
||||
} catch (e) {
|
||||
@@ -82,7 +82,7 @@ function createV2Router() {
|
||||
const token = req.session && req.session.token;
|
||||
if (!token) return res.send('<h2>Нет токена</h2><p><a href="/v2/login">Войти</a></p>');
|
||||
try {
|
||||
const raw = await iamFetch(token, 'https://auth-api-dev.ngcloud.ru/api/v1/auth/user');
|
||||
const raw = await iamFetch(token, config.iamApiBase + '/auth/user');
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
res.send(rawPage('IAM DEV', raw));
|
||||
} catch (e) {
|
||||
@@ -90,29 +90,39 @@ function createV2Router() {
|
||||
}
|
||||
});
|
||||
|
||||
// ── GET /v2/impersonation-check — IAM impersonation: 3 GET эндпоинта ──
|
||||
router.get('/impersonation-check', async (req, res) => {
|
||||
// ── GET /v2/iam-gateway-test — сравнение auth-api vs lk-api-gateway ──
|
||||
router.get('/iam-gateway-test', async (req, res) => {
|
||||
const token = req.session && req.session.token;
|
||||
if (!token) return res.send('<h2>Нет токена</h2><p><a href="/v2/login">Войти</a></p>');
|
||||
|
||||
const endpoints = [
|
||||
{ name: 'status', url: 'https://auth-api.ngcloud.ru/api/v1/impersonation/status' },
|
||||
{ name: 'history', url: 'https://auth-api.ngcloud.ru/api/v1/impersonation/history' },
|
||||
{ name: 'history/all', url: 'https://auth-api.ngcloud.ru/api/v1/impersonation/history/all' },
|
||||
const base = config.iamApiBase;
|
||||
const tests = [
|
||||
{
|
||||
name: 'auth-api /auth/user',
|
||||
url: base + '/auth/user',
|
||||
},
|
||||
{
|
||||
name: 'lk-api-gateway /iam/auth/user',
|
||||
url: 'https://lk-api-gateway.ngcloud.ru/api/v1/iam/auth/user',
|
||||
},
|
||||
{
|
||||
name: 'auth-api /impersonation/status',
|
||||
url: base + '/impersonation/status',
|
||||
},
|
||||
];
|
||||
|
||||
const results = {};
|
||||
for (const ep of endpoints) {
|
||||
for (const t of tests) {
|
||||
try {
|
||||
const data = await iamFetch(token, ep.url);
|
||||
results[ep.name] = { ok: true, data };
|
||||
const data = await iamFetch(token, t.url);
|
||||
results[t.name] = { ok: true, data };
|
||||
} catch (e) {
|
||||
results[ep.name] = { ok: false, error: e.message };
|
||||
results[t.name] = { ok: false, error: e.message };
|
||||
}
|
||||
}
|
||||
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
res.send(iamStatPage(results));
|
||||
res.send(iamComparePage(results));
|
||||
});
|
||||
|
||||
// ── /v2/app — пользовательский CRUD (только с сессией) ──────────────
|
||||
@@ -136,7 +146,25 @@ function createV2Router() {
|
||||
router.use('/export', createExportRouter());
|
||||
|
||||
// ── GET /v2/logout — редирект на основной выход ─────────────────────
|
||||
router.get('/logout', (req, res) => res.redirect('/logout'));
|
||||
router.get('/logout', (req, res) => {
|
||||
const ua = (req.headers['user-agent'] || '').toLowerCase();
|
||||
const isBrowser = ua.includes('mozilla') || ua.includes('chrome') || ua.includes('safari');
|
||||
if (isBrowser) {
|
||||
res.set('Content-Type', 'text/html; charset=utf-8');
|
||||
return res.send('<!DOCTYPE html><html><head><meta charset="utf-8"><title>Выход</title>'
|
||||
+ '<style>body{font-family:sans-serif;background:#111;color:#eee;padding:40px;text-align:center}'
|
||||
+ 'h2{color:#4fc3f7}p{font-size:16px;margin:20px 0}'
|
||||
+ '.btn{display:inline-block;padding:12px 24px;margin:0 10px;border-radius:6px;text-decoration:none;font-size:16px}'
|
||||
+ '.btn-yes{background:#ef5350;color:#fff}.btn-no{background:#333;color:#eee}'
|
||||
+ '</style></head><body>'
|
||||
+ '<h2>Выход из приложения</h2>'
|
||||
+ '<p>Выход завершит сессию во всех сервисах Nubes (Keycloak SSO).<br>Вы уверены?</p>'
|
||||
+ '<a href="/logout" class="btn btn-yes">Да, выйти</a>'
|
||||
+ '<a href="/v2/app" class="btn btn-no">Отмена</a>'
|
||||
+ '</body></html>');
|
||||
}
|
||||
res.redirect('/logout');
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
@@ -187,7 +215,7 @@ function debugPage(u, version) {
|
||||
</body></html>`;
|
||||
}
|
||||
|
||||
function iamStatPage(results) {
|
||||
function iamComparePage(results) {
|
||||
function fmt(data, depth) {
|
||||
if (data === null || data === undefined) return '<span style="color:#888">null</span>';
|
||||
if (typeof data === 'string') return '<span style="color:#ce93d8">"' + data.replace(/</g, '<') + '"</span>';
|
||||
|
||||
@@ -4,18 +4,18 @@
|
||||
// ЭТО: все настройки в одном месте.
|
||||
// ЗАЧЕМ: всё что может поменяться между средами — здесь, не размазано по коду.
|
||||
//
|
||||
// ПРИОРИТЕТ: process.env (V2_*) → хардкод-умолчания.
|
||||
// Умолчания — для тестовой среды (VM KC на italo.kube5s.ru:8080).
|
||||
// ПРИОРИТЕТ: process.env → хардкод-умолчания.
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
module.exports = {
|
||||
version: '0.5.146',
|
||||
version: '0.5.149',
|
||||
|
||||
// ── IAM ──────────────────────────────────────────────────────────────────
|
||||
iamUrl: process.env.V2_IAM_URL || 'https://auth-api.ngcloud.ru/api/v1/auth/user',
|
||||
iamApiBase: process.env.IAM_API_BASE || 'https://auth-api.ngcloud.ru/api/v1',
|
||||
|
||||
// ── OIDC (Keycloak) ──────────────────────────────────────────────────────
|
||||
kcBaseUrl: process.env.V2_KC_BASE_URL || 'https://italo.kube5s.ru:8080/realms/ipwhitelist',
|
||||
kcBaseUrl: process.env.V2_KC_BASE_URL || 'https://login.ngcloud.ru/realms/ipwhitelist',
|
||||
kcClientId: process.env.V2_KC_CLIENT_ID || 'ipwhitelist-app',
|
||||
kcClientSecret: process.env.V2_KC_CLIENT_SECRET || '',
|
||||
appUrl: process.env.V2_APP_URL || 'https://whitelist.nodejsk8s.services.ngcloud.ru',
|
||||
|
||||
Reference in New Issue
Block a user