v0.5.147: add /v2/impersonation-check page with IAM GET endpoints

This commit is contained in:
2026-06-17 08:54:39 +04:00
parent e68e1a483c
commit 9f44281f9f
3 changed files with 168 additions and 1 deletions
+83
View File
@@ -0,0 +1,83 @@
# IAM Impersonation API
> Источник: Swagger `https://auth-api-dev.ngcloud.ru/api/v1/documentation/`
> Дата: 2026-06-16
## Все эндпоинты имперсонации
| Метод | Путь | Описание |
|-------|------|----------|
| `POST` | `/api/v1/impersonation/start` | Начать имперсонацию |
| `POST` | `/api/v1/impersonation/end` | Завершить имперсонацию |
| `POST` | `/api/v1/impersonation/extend` | Продлить сессию имперсонации |
| `GET` | `/api/v1/impersonation/status` | Статус текущей имперсонации |
| `GET` | `/api/v1/impersonation/history` | История своих имперсонаций |
| `GET` | `/api/v1/impersonation/history/all` | История имперсонаций всех админов |
## Формат ImpersonationStartRequest
```json
{
"type": "user",
"entity_id": "UUID контакта (contactId из userInfo)",
"reason": "описание причины"
}
```
- `entity_id`**UUID таргета** (кого имперсонируем), не свой
- `type` — всегда `"user"`
## curl-команды
### Начать имперсонацию
```bash
curl --http2 -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
"https://auth-api.ngcloud.ru/api/v1/impersonation/start" \
-d '{"type":"user","entity_id":"UUID_таргета","reason":"тест"}'
```
### Статус
```bash
curl --http2 \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json" \
"https://auth-api.ngcloud.ru/api/v1/impersonation/status"
```
### История
```bash
curl --http2 \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json" \
"https://auth-api.ngcloud.ru/api/v1/impersonation/history"
```
### Продлить
```bash
curl --http2 -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json" \
"https://auth-api.ngcloud.ru/api/v1/impersonation/extend"
```
### Завершить
```bash
curl --http2 -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/json" \
"https://auth-api.ngcloud.ru/api/v1/impersonation/end"
```
## Примечания
- Требуется роль IAM-админа или право на объект `impersonation`
- `--http2` обязателен для обхода ddos-guard
- Стенды: `auth-api.ngcloud.ru` (prod), `auth-api-test.ngcloud.ru` (test), `auth-api-dev.ngcloud.ru` (dev)
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "ipwhitelist", "name": "ipwhitelist",
"version": "0.5.146", "version": "0.5.147",
"description": "IP WhiteList microservice for cloud provider", "description": "IP WhiteList microservice for cloud provider",
"main": "server.js", "main": "server.js",
"scripts": { "scripts": {
+84
View File
@@ -90,6 +90,31 @@ function createV2Router() {
} }
}); });
// ── GET /v2/impersonation-check — IAM impersonation: все GET эндпоинты ─
router.get('/impersonation-check', 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 results = {};
for (const ep of endpoints) {
try {
const data = await iamFetch(token, ep.url);
results[ep.name] = { ok: true, data };
} catch (e) {
results[ep.name] = { ok: false, error: e.message };
}
}
res.set('Content-Type', 'text/html; charset=utf-8');
res.send(iamStatPage(results));
});
// ── /v2/app — пользовательский CRUD (только с сессией) ────────────── // ── /v2/app — пользовательский CRUD (только с сессией) ──────────────
router.use('/app', enhanceImpersonation, resolveContext, createUserRouter()); router.use('/app', enhanceImpersonation, resolveContext, createUserRouter());
@@ -162,4 +187,63 @@ function debugPage(u, version) {
</body></html>`; </body></html>`;
} }
function iamStatPage(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, '&lt;') + '"</span>';
if (typeof data === 'number' || typeof data === 'boolean') return '<span style="color:#81c784">' + data + '</span>';
if (Array.isArray(data)) {
if (data.length === 0) return '<span style="color:#888">[]</span>';
let html = '<span style="color:#888">[</span><div style="padding-left:20px">';
for (const item of data) html += '<div>' + fmt(item, depth + 1) + ',</div>';
html += '</div><span style="color:#888">]</span>';
return html;
}
if (typeof data === 'object') {
let html = '<span style="color:#888">{</span><div style="padding-left:20px">';
for (const [k, v] of Object.entries(data)) {
html += '<div><span style="color:#82aaff">"' + k + '"</span>: ' + fmt(v, depth + 1) + '</div>';
}
html += '</div><span style="color:#888">}</span>';
return html;
}
return String(data).replace(/</g, '&lt;');
}
let html = '<!DOCTYPE html><html><head><meta charset="utf-8"><title>IAM Impersonation</title>';
html += '<style>body{font-family:monospace;background:#111;color:#eee;padding:20px;font-size:14px}';
html += 'h2{color:#4fc3f7}.ok{color:#81c784}.err{color:#ef5350}';
html += '.card{background:#1a1a2e;border-radius:8px;padding:15px;margin-bottom:15px;overflow-x:auto}';
html += '.card-title{color:#b39ddb;font-size:18px;font-weight:bold;margin-bottom:10px}';
html += 'a{color:#80cbc4;text-decoration:none}a:hover{text-decoration:underline}';
html += '.nav{display:flex;gap:15px;margin-bottom:20px;flex-wrap:wrap}';
html += '.nav a{background:#1a1a2e;padding:8px 16px;border-radius:6px;font-size:14px}';
html += '</style></head><body>';
html += '<h2>🧪 IAM Impersonation — GET эндпоинты</h2>';
html += '<div class="nav">';
html += '<a href="/v2/iam">← Сессия</a>';
html += '<a href="/v2/app">CRUD</a>';
html += '<a href="/v2/admin">Админка</a>';
html += '<a href="/v2/iam_response">IAM PROD</a>';
html += '<a href="/v2/iam_response_test">IAM TEST</a>';
html += '<a href="/v2/iam_response_dev">IAM DEV</a>';
html += '</div>';
for (const [name, r] of Object.entries(results)) {
html += '<div class="card">';
html += '<div class="card-title">GET /impersonation/' + name + '</div>';
if (r.ok) {
html += '<div style="font-family:monospace;white-space:pre-wrap;tab-size:2">';
html += fmt(r.data, 0);
html += '</div>';
} else {
html += '<div class="err">❌ ' + r.error.replace(/</g, '&lt;') + '</div>';
}
html += '</div>';
}
html += '</body></html>';
return html;
}
module.exports = { createV2Router }; module.exports = { createV2Router };