SHADOW AI

A secure AI platform requires more than individual security controls.
Authentication, encryption, network segmentation, AI safety, database security, monitoring, backup, and governance must work together as one architecture.
This chapter combines the major security concepts developed throughout the previous chapters into a single end-to-end reference architecture.
The objective is to establish a practical blueprint for a production-grade AI platform that can support:
web and mobile clients,
AI inference,
RAG,
agents,
media processing,
user accounts,
subscriptions,
object storage,
databases,
queues,
external providers,
observability,
security operations,
governance,
disaster recovery.
The architecture follows one fundamental principle:
Every request, identity, dataset, model, tool, service, and external dependency should have an explicit trust boundary and appropriate security controls.
A high-level architecture can be represented as:
USERS
│
┌────────────┴────────────┐
│ │
Web Client Mobile Client
│ │
└────────────┬────────────┘
↓
CDN / Edge Layer
↓
WAF / DDoS Layer
↓
API Gateway
↓
┌────────────┴────────────┐
│ │
Authentication Rate Limiting
│ │
└────────────┬────────────┘
↓
Application Layer
│
┌───────────────────┼────────────────────┐
↓ ↓ ↓
User Service AI Service Media Service
│ │ │
↓ ↓ ↓
PostgreSQL AI Policy Engine Job Queue
│ │
↓ ↓
AI Router Workers
│ │
┌────────────┼────────────┐ ↓
↓ ↓ ↓ Object Storage
Provider A Provider B Local AI
│ │
└────────────┴────────────┘
│
↓
External Services
Supporting layers:
Cache ─ Queue ─ Search ─ Vector DB ─ Secrets ─ KMS
│
↓
Logging / Metrics / Tracing
│
↓
SIEM / SOC
│
↓
Detection / Incident Response
The platform should be viewed as multiple cooperating layers.
Controls include:
secure authentication,
session protection,
client-side validation,
secure storage,
CSP,
safe file handling.
Controls include:
TLS,
CDN,
WAF,
DDoS protection,
request filtering.
Controls include:
authentication,
authorization,
rate limiting,
input validation,
schema validation,
API monitoring.
Controls include:
business authorization,
policy enforcement,
tenant isolation,
secure workflows.
Controls include:
model routing,
prompt validation,
output validation,
AI safety policies,
tool permissions,
agent isolation.
Controls include:
encryption,
access control,
classification,
retention,
backups,
deletion.
Controls include:
network segmentation,
workload identity,
container security,
runtime protection,
infrastructure policy.
Controls include:
monitoring,
detection,
incident response,
recovery,
governance.
A trust boundary identifies where assumptions about security change.
Important boundaries include:
Internet
│
▼
Edge
│
▼
API Gateway
│
▼
Application
│
├── Database
├── Object Storage
├── Queue
└── AI Layer
│
├── External Models
└── Tools
Each boundary should have explicit controls.
The platform should not automatically trust:
users,
devices,
internal services,
AI models,
agents,
plugins,
external APIs,
network locations.
Instead, access should be based on:
Identity + Authentication + Authorization + Context + Policy
The identity plane manages:
users,
service identities,
administrators,
AI agents,
workloads.
Each identity should have a defined purpose.
Example:
User Identity
Service Identity
Worker Identity
Agent Identity
Administrator Identity
Identities should not be casually interchangeable.
Authentication establishes:
Who or what is making this request?
Possible mechanisms include:
password authentication,
passkeys,
MFA,
OAuth/OIDC,
service credentials,
workload identity.
The strongest available authentication should be applied according to risk.
Authentication alone is insufficient.
Authorization determines:
What is this identity allowed to do?
A secure platform should enforce authorization at the server side.
A centralized policy layer can provide consistent security decisions.
Request
↓
Identity
↓
Policy Engine
↓
Allow / Deny / Require Approval
Policies can consider:
user role,
tenant,
resource,
operation,
data classification,
risk level.
Multi-tenant systems must prevent cross-tenant access.
Tenant boundaries should be enforced across:
database records,
object storage,
caches,
vector databases,
search indexes,
queues,
logs,
AI memory.
The tenant identifier should never be treated as sufficient authorization by itself.
The application layer coordinates business functionality.
Important services may include:
User Service
Project Service
AI Service
Media Service
Billing Service
Notification Service
Search Service
Administration Service
Each service should have a clearly defined responsibility.
The gateway provides the first major application security boundary.
Possible responsibilities:
TLS termination,
authentication enforcement,
rate limiting,
request-size limits,
API routing,
abuse detection,
request logging.
Business authorization should still occur within the appropriate application service.
All externally supplied data should be treated as untrusted.
Validation should cover:
type,
length,
format,
allowed values,
file type,
request size,
schema.
Validation should occur before sensitive processing.
Application outputs should also be validated.
This is particularly important for AI systems.
Model Output
↓
Schema Validation
↓
Safety Validation
↓
Business Validation
↓
Application
AI output should not automatically become trusted application instructions.
The AI layer should have its own security boundary.
It should contain:
provider routing,
model policies,
prompt handling,
output validation,
token controls,
safety filters,
tool authorization,
AI telemetry.
The provider router abstracts external and internal models.
AI Request
↓
AI Policy
↓
Provider Router
├── Provider A
├── Provider B
├── Provider C
└── Local Model
Routing decisions may consider:
task,
privacy requirements,
model capability,
cost,
latency,
availability.
Before sending data to a model, determine:
What data is being transmitted?
Is the provider approved?
Is the data allowed to leave the platform?
Does the provider retain it?
Is redaction required?
Prompts should not be treated as inherently trusted.
AI applications should defend against:
prompt injection,
indirect prompt injection,
malicious retrieved content,
instruction conflicts,
unsafe tool requests.
The application should maintain the authoritative security policy outside the model.
The RAG pipeline should enforce:
Query
↓
Identity
↓
Tenant Filter
↓
Authorization
↓
Retrieval
↓
Content Validation
↓
Context Construction
↓
Model
Retrieval should never bypass normal authorization.
AI memory should be treated as sensitive application data.
Controls should include:
tenant isolation,
access control,
retention,
deletion,
provenance,
memory poisoning defenses.
Users should be able to understand and control appropriate memory behavior.
Agents should have:
unique identity,
explicit permissions,
limited tools,
resource limits,
action logging,
approval controls.
An agent should not automatically inherit all permissions of the person who created it.
Tool calls should pass through authorization.
Agent
↓
Tool Request
↓
Policy Engine
↓
Permission Check
↓
Tool
Sensitive tools should require stronger controls.
Where agents execute code or untrusted operations, use isolation appropriate to the risk.
Possible controls include:
isolated workers,
restricted filesystem access,
network restrictions,
CPU limits,
memory limits,
execution timeouts.
High-impact agent operations should support human approval.
Examples:
destructive operations,
privileged configuration changes,
external publication,
sensitive data transfer.
The approval workflow should be auditable.
AI media systems must treat uploaded files as untrusted.
The pipeline should include:
Upload
↓
Quarantine
↓
Validation
↓
Malware Scanning
↓
Metadata Analysis
↓
Sandbox Processing
↓
Output Validation
↓
Trusted Storage
Object storage should use:
private buckets/containers,
scoped access,
signed URLs where appropriate,
encryption,
lifecycle policies,
malware scanning,
tenant isolation.
Public access should not be the default.
The database layer should implement:
least-privilege accounts,
encrypted connections,
access controls,
tenant isolation,
backup protection,
audit logging,
schema migration controls.
Application users should not receive direct database access.
Caches can contain sensitive information.
Security considerations include:
namespace isolation,
tenant-aware keys,
expiration,
encryption where appropriate,
restricted network access.
A cache key should never accidentally expose another user's data.
Queues should enforce:
authenticated producers,
authenticated consumers,
message validation,
retry limits,
dead-letter handling,
tenant isolation,
sensitive-data controls.
Secrets should be stored separately from source code.
Examples:
API credentials,
database passwords,
signing keys,
encryption keys,
provider credentials.
The application should retrieve secrets through an approved secret-management mechanism.
Encryption should protect:
Use appropriately secured TLS connections.
Use storage/database encryption.
Use appropriate cryptographic protection.
Keys should be managed separately from the data they protect.
A mature key architecture includes:
Key Management System
│
├── Encryption Keys
├── Signing Keys
├── Rotation
├── Access Policies
└── Audit Logs
Keys should have lifecycle management.
Network segmentation can separate:
Internet Zone
↓
Edge Zone
↓
Application Zone
↓
Data Zone
↓
Management Zone
The exact implementation depends on infrastructure.
Internal communication should use authenticated service identities.
Do not assume:
Internal network = trusted network.
Service authorization should remain explicit.
If Kubernetes is used, important controls include:
namespace isolation,
RBAC,
workload identity,
admission controls,
image verification,
network policies,
resource limits,
pod security controls,
secret management.
Containers should use:
minimal images,
pinned dependencies,
non-root execution where practical,
vulnerability scanning,
read-only filesystems where appropriate,
restricted capabilities.
The build pipeline should verify:
Source
↓
Code Review
↓
Dependency Scan
↓
SAST
↓
Tests
↓
Build
↓
Artifact Verification
↓
Security Gates
↓
Deployment
Production deployment should not depend on an uncontrolled developer workstation.
Supply-chain security should cover:
source repositories,
package registries,
dependencies,
build systems,
container images,
AI models,
plugins.
Maintain provenance for production artifacts.
Maintain an inventory of software components.
The SBOM should support:
vulnerability response,
dependency visibility,
license management,
incident investigation.
The platform should collect:
Performance and availability.
Security and application events.
Distributed request flow.
Authentication, authorization, policy, and suspicious behavior.
Applications
│
├── Logs
├── Metrics
├── Traces
└── Security Events
↓
Telemetry Layer
↓
SIEM
↓
Detection Engineering
↓
SOC
AI-specific telemetry may include:
prompt-injection detections,
policy violations,
abnormal tool calls,
unusual token consumption,
unexpected provider routing,
suspicious retrieval patterns,
agent action anomalies.
Logging should respect privacy and data-minimization requirements.
Detection engineering should transform telemetry into actionable signals.
Example:
Event
↓
Normalization
↓
Correlation
↓
Risk Assessment
↓
Detection
↓
Alert
↓
Triage
A security operations center can coordinate:
monitoring,
alert triage,
threat hunting,
incident response,
detection engineering,
security investigations.
Not every organization needs a large internal SOC; managed services may provide some functions.
A standard lifecycle is:
Prepare
↓
Detect
↓
Analyze
↓
Contain
↓
Eradicate
↓
Recover
↓
Learn
AI incidents should be incorporated into the same operational model.
Potential events include:
unauthorized data exposure,
compromised AI provider credential,
agent executing an unauthorized action,
malicious document entering a RAG corpus,
model artifact compromise,
cross-tenant retrieval,
unsafe automated workflow.
Critical data should have appropriate backups.
Backup domains may include:
database,
object storage,
configuration,
infrastructure,
security logs,
model metadata.
Backups should themselves be protected.
A compromised production environment should not automatically be able to destroy every backup.
Where practical, use:
separate credentials,
access controls,
retention protections,
isolated backup environments.
The platform should define:
How quickly service should be restored.
How much data loss is acceptable.
These values should be based on business requirements.
Critical services can use redundancy across:
instances,
zones,
regions,
providers,
where justified by risk and cost.
High availability should not be confused with backup.
Governance provides organizational control over the architecture.
It should define:
policies,
standards,
risk ownership,
control ownership,
exceptions,
evidence,
review cycles.
Controls should be mapped to:
Risk
↓
Control Objective
↓
Security Control
↓
Implementation
↓
Evidence
↓
Validation
This makes security measurable.
Useful executive metrics may include:
critical vulnerabilities,
mean time to remediate,
incident frequency,
authentication attacks,
security-control coverage,
backup recovery success,
third-party risk exposure.
Metrics should support decisions rather than simply generate dashboards.
Security architecture should be tested continuously.
Testing may include:
unit tests,
integration tests,
security tests,
penetration testing,
AI red teaming,
configuration validation,
disaster recovery exercises.
A production release should satisfy appropriate conditions:
Code Complete
↓
Tests Passed
↓
Security Checks
↓
AI Evaluation
↓
Dependency Review
↓
Deployment Approval
↓
Canary / Progressive Release
↓
Monitoring
↓
Full Deployment
Production configuration should be:
version-controlled,
validated,
reviewed,
protected,
monitored for drift.
Security policies should not depend on undocumented manual changes.
Where practical, security requirements can be encoded into automated policy.
Examples:
disallow public storage,
require encryption,
restrict privileged workloads,
prevent unapproved container images,
require specific deployment conditions.
Automation reduces human configuration errors.
Security architecture must also consider economics.
Controls should be prioritized based on:
Risk Reduction / Cost / Operational Impact
Expensive controls are not automatically better.
The objective is appropriate protection for the actual risk.
Security controls should be designed with performance in mind.
Examples:
caching policy decisions where safe,
asynchronous malware scanning,
efficient authorization,
appropriate queueing,
controlled model routing.
Performance optimization must not silently remove important security controls.
A secure AI request can follow:
1. User sends request
↓
2. TLS protects transport
↓
3. CDN / WAF evaluates traffic
↓
4. API Gateway receives request
↓
5. Authentication verifies identity
↓
6. Authorization verifies permission
↓
7. Tenant boundary is established
↓
8. Input is validated
↓
9. Policy Engine evaluates operation
↓
10. AI Service processes request
↓
11. RAG retrieves authorized context
↓
12. Model Router selects approved model
↓
13. Model generates output
↓
14. Output is validated
↓
15. Tool actions require authorization
↓
16. Result is returned
↓
17. Security telemetry is recorded
↓
18. Monitoring evaluates behavior
For uploaded media:
Upload
↓
Authentication
↓
Authorization
↓
Tenant Validation
↓
Quarantine Storage
↓
File Validation
↓
Malware Scan
↓
Metadata Inspection
↓
Sandbox Processing
↓
AI Processing
↓
Output Validation
↓
Trusted Storage
↓
Signed Access
↓
Audit Logging
User Request
↓
Authentication
↓
Authorization
↓
Agent Policy
↓
Planning
↓
Tool Selection
↓
Tool Authorization
↓
Execution Sandbox
↓
Output Validation
↓
Human Approval if Required
↓
Action
↓
Audit Log
↓
Monitoring
Document
↓
Upload
↓
Validation
↓
Malware Scan
↓
Text Extraction
↓
Classification
↓
Chunking
↓
Embedding
↓
Vector Storage
↓
Tenant / ACL Metadata
↓
User Query
↓
Authorization
↓
Filtered Retrieval
↓
Context Validation
↓
Model
↓
Output Validation
Developer
↓
Source Repository
↓
Pull Request
↓
Code Review
↓
Automated Tests
↓
Security Scanning
↓
Dependency Verification
↓
Build
↓
Artifact Verification
↓
Staging
↓
AI Evaluation
↓
Security Approval
↓
Canary
↓
Production
↓
Monitoring
↓
Rollback if Required
Telemetry
↓
Detection
↓
Alert
↓
Triage
↓
Severity Assessment
↓
Containment
↓
Investigation
↓
Eradication
↓
Recovery
↓
Validation
↓
Post-Incident Review
↓
Control Improvement
Business Requirement
↓
Risk Assessment
↓
Security Requirement
↓
Control Design
↓
Implementation
↓
Testing
↓
Evidence
↓
Monitoring
↓
Audit
↓
Risk Review
↓
Improvement
| Domain | Primary Controls |
|---|---|
| Identity | MFA, sessions, workload identity |
| Authorization | RBAC/ABAC, policy engine |
| Network | TLS, segmentation, WAF |
| API | validation, rate limits, gateway |
| AI | routing, policy, output validation |
| Agents | least privilege, sandboxing, approvals |
| RAG | ACL filtering, tenant isolation |
| Media | quarantine, scanning, sandbox |
| Database | encryption, access control |
| Storage | private access, signed URLs |
| Secrets | secret manager, rotation |
| Containers | image verification, runtime controls |
| CI/CD | scanning, signed artifacts |
| Monitoring | logs, metrics, traces, SIEM |
| Incident Response | detection, containment, recovery |
| Backup | isolation, encryption, testing |
| Governance | policies, risk register, evidence |
| Third Parties | vendor assessment, monitoring, exit plans |
Before launching a serious AI platform, establish at minimum:
Secure authentication.
Strong authorization.
MFA for appropriate accounts.
Admin access protection.
Input validation.
Output validation.
Rate limiting.
Secure error handling.
AI provider controls.
Prompt-injection defenses.
Output validation.
Agent permission boundaries.
AI evaluation.
Encryption.
Tenant isolation.
Backup.
Retention policy.
Network segmentation.
Secure containers.
Secret management.
Dependency scanning.
Logging.
Monitoring.
Incident response.
Recovery procedures.
Risk ownership.
Security policies.
Vendor management.
Security review process.
authentication,
HTTPS,
basic authorization,
backups.
centralized secrets,
security testing,
monitoring,
access reviews.
Zero Trust,
AI security,
tenant isolation,
DevSecOps,
policy enforcement.
continuous validation,
automated detection,
AI red teaming,
progressive delivery,
advanced resilience.
Security becomes continuously measurable and automatically improved through:
telemetry,
risk analysis,
automated controls,
continuous testing,
incident learning,
architecture evolution.
For a beginner implementing this architecture, do not attempt to build everything simultaneously.
A practical sequence is:
Build:
Next.js application
Backend/API
Database
Authentication
Basic authorization
Add:
Object storage
File upload
Database models
Queue
Cache
Add:
AI provider abstraction
Model routing
Prompt handling
Output validation
AI safety controls
Add:
Document ingestion
Embeddings
Vector search
RAG
Memory
Add:
Agents
Tool calling
Tool authorization
Sandboxing
Human approval
Add:
Secrets management
encryption
network controls
tenant isolation
security logging
Add:
quarantine
malware scanning
sandboxed media processing
metadata controls
trusted output storage
Add:
Git workflow
dependency scanning
SAST
container scanning
CI/CD security
Add:
monitoring
SIEM/SOC integration
detection
incident response
backup/recovery
Add:
policies
risk register
vendor management
compliance evidence
continuous improvement.
The entire architecture can be summarized as:
IDENTITY
+
AUTHORIZATION
+
DATA PROTECTION
+
AI SAFETY
+
ISOLATION
+
VALIDATION
+
MONITORING
+
RECOVERY
+
GOVERNANCE
=
SECURE AI PLATFORM
No single control provides complete security.
Security emerges from the combination of multiple independent controls.
The complete platform can ultimately be represented as:
INTERNET
│
▼
┌─────────────────┐
│ CDN / WAF / DDoS│
└────────┬────────┘
│
▼
┌─────────────────┐
│ API GATEWAY │
└────────┬────────┘
│
┌─────────────┴─────────────┐
│ │
▼ ▼
AUTHENTICATION RATE LIMITING
│ │
└─────────────┬─────────────┘
▼
┌─────────────────────┐
│ APPLICATION SERVICES│
└──────────┬──────────┘
│
┌───────────────────────┼────────────────────────┐
│ │ │
▼ ▼ ▼
USER DATA AI SERVICES MEDIA
│ │ │
▼ ▼ ▼
PostgreSQL POLICY ENGINE QUEUE
│ │
▼ ▼
AI ROUTER WORKERS
│ │
┌────────────┼────────────┐ │
│ │ │ ▼
▼ ▼ ▼ OBJECT STORAGE
Provider A Provider B Local AI
│ │
└────────────┴────────────┘
│
▼
EXTERNAL SERVICES
┌───────────────────────────┐
│ SECURITY CONTROL PLANE │
│ │
│ Identity │
│ Authorization │
│ Secrets │
│ Encryption │
│ Policy │
│ Tenant Isolation │
│ AI Safety │
│ Supply Chain │
└────────────┬──────────────┘
│
▼
┌───────────────────────────┐
│ OBSERVABILITY │
│ │
│ Logs │
│ Metrics │
│ Traces │
│ Security Events │
└────────────┬──────────────┘
│
▼
┌───────────────┐
│ SIEM / SOC │
└───────┬───────┘
│
▼
DETECTION / RESPONSE / IR
│
▼
RECOVERY / IMPROVEMENT
│
└──────→ GOVERNANCE
The previous chapters described individual security domains.
This chapter connects them into one architecture.
A production-grade AI platform should therefore be designed as a collection of controlled trust boundaries rather than as a single application.
The most important architectural relationships are:
Identity → Authorization → Policy → Application
Application → AI Policy → Model → Validation
Application → Data Authorization → Database / Storage / RAG
Agent → Tool Authorization → Sandbox → Action
External Input → Validation → Quarantine → Processing → Trusted Output
Source → Build → Verification → Deployment → Monitoring
Telemetry → Detection → Incident Response → Recovery → Learning
Risk → Control → Evidence → Validation → Governance
The final objective is not to create a platform that can never fail.
That is unrealistic.
The objective is to build a platform where:
failures are constrained,
unauthorized actions are difficult,
sensitive data is protected,
suspicious behavior is detected,
incidents can be contained,
systems can recover,
and lessons continuously improve the architecture.
The complete security philosophy can therefore be summarized as:
Verify everything appropriate. Minimize privilege. Isolate failures. Protect data. Validate AI behavior. Monitor continuously. Recover safely. Improve continuously.
This reference architecture provides the foundation for turning the previous research chapters into an actual implementation plan.
End of Chapter 100
Comments
Post a Comment