feat: four super-admin keys and production customer API security
Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 1m18s
CI/CD Pipeline / Security Scanning (push) Successful in 2m34s
CI/CD Pipeline / Lint and Format (push) Failing after 54s
CI/CD Pipeline / Terraform Validation (push) Failing after 27s
CI/CD Pipeline / Kubernetes Validation (push) Successful in 28s
Deploy ChainID 138 / Deploy ChainID 138 (push) Failing after 39s
HYBX OMNL TypeScript & anchor / token-aggregation build + reconcile artifact (push) Failing after 31s
Validation / validate-genesis (push) Successful in 28s
Validation / validate-terraform (push) Failing after 31s
Validation / validate-kubernetes (push) Failing after 11s
Validation / validate-smart-contracts (push) Failing after 11s
Validation / validate-security (push) Failing after 1m27s
Validation / validate-documentation (push) Failing after 21s
Verify Deployment / Verify Deployment (push) Has been cancelled
Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 1m18s
CI/CD Pipeline / Security Scanning (push) Successful in 2m34s
CI/CD Pipeline / Lint and Format (push) Failing after 54s
CI/CD Pipeline / Terraform Validation (push) Failing after 27s
CI/CD Pipeline / Kubernetes Validation (push) Successful in 28s
Deploy ChainID 138 / Deploy ChainID 138 (push) Failing after 39s
HYBX OMNL TypeScript & anchor / token-aggregation build + reconcile artifact (push) Failing after 31s
Validation / validate-genesis (push) Successful in 28s
Validation / validate-terraform (push) Failing after 31s
Validation / validate-kubernetes (push) Failing after 11s
Validation / validate-smart-contracts (push) Failing after 11s
Validation / validate-security (push) Failing after 1m27s
Validation / validate-documentation (push) Failing after 21s
Verify Deployment / Verify Deployment (push) Has been cancelled
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
18
services/settlement-middleware/src/middleware/auth.ts
Normal file
18
services/settlement-middleware/src/middleware/auth.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { Request, Response } from 'express';
|
||||
import { resolveOmnlPrincipal } from '@dbis/integration-foundation';
|
||||
import { loadConfig } from '../config';
|
||||
|
||||
export function requireApiKey(req: Request, res: Response): boolean {
|
||||
const cfg = loadConfig();
|
||||
if (!cfg.production.requireApiKey) return true;
|
||||
const principal = resolveOmnlPrincipal(req);
|
||||
if (!principal) {
|
||||
res.status(401).json({ error: 'Unauthorized' });
|
||||
return false;
|
||||
}
|
||||
if (principal.role === 'customer') {
|
||||
res.status(403).json({ error: 'Forbidden', hint: 'Settlement APIs require super-admin credentials' });
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
24
services/settlement-middleware/src/middleware/rate-limit.ts
Normal file
24
services/settlement-middleware/src/middleware/rate-limit.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import rateLimit from 'express-rate-limit';
|
||||
import type { RequestHandler } from 'express';
|
||||
import { isProductionSecurityMode, loadCustomerSecurityPolicy, resolveOmnlPrincipal } from '@dbis/integration-foundation';
|
||||
|
||||
function asHandler(h: ReturnType<typeof rateLimit>): RequestHandler {
|
||||
return h as unknown as RequestHandler;
|
||||
}
|
||||
|
||||
export const settlementRateLimiter = asHandler(
|
||||
rateLimit({
|
||||
windowMs: 60_000,
|
||||
max: (req) => {
|
||||
if (!isProductionSecurityMode()) return 200;
|
||||
const policy = loadCustomerSecurityPolicy();
|
||||
const principal = resolveOmnlPrincipal(req);
|
||||
if (!principal) return policy.rateLimits.anonymousPerMinute;
|
||||
if (principal.role === 'customer') return policy.rateLimits.customerPerMinute;
|
||||
return policy.rateLimits.superAdminPerMinute;
|
||||
},
|
||||
message: { error: 'Too many requests — rate limit exceeded' },
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
}),
|
||||
);
|
||||
Reference in New Issue
Block a user