Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Security Design

1. Security Objective

PsyDian shall protect the boundary between the trusted operating-system kernel and untrusted external AI services.

The security design focuses on:

  • Kernel isolation.
  • Controlled communication.
  • Input validation.
  • AI output validation.
  • Privilege separation.
  • Secret management.
  • Safe command execution.
  • Fault isolation.
  • Diagnostic-data minimization.
  • Secure development practices.

The central security principle is:

AI can suggest or explain actions, but it must never directly obtain kernel privileges or bypass the system’s validation and authorization mechanisms.


2. Security Architecture

The primary trust boundary is:

                    TRUSTED
┌──────────────────────────────────────────┐
│                PsyDian Kernel             │
│                                          │
│  Shell                                     
│  Command Parser                         
│  Command Validator                       
│  Memory Manager                          
│  Interrupt / Exception Handlers          
│  Diagnostics                             
│  Serial Communication                    
└────────────────────┬─────────────────────┘
                     │
              Controlled Protocol
                     │
                     ▼
┌──────────────────────────────────────────┐
│            Host-side AI Bridge           │
│                                          │
│  Protocol Parser                         
│  Input Validation                        
│  Context Builder                         
│  AI Client                              
│  Response Validator                      
│  Safety Checks                           
└────────────────────┬─────────────────────┘
                     │
                HTTPS / REST
                     │
                     ▼
┌──────────────────────────────────────────┐
│          External AI Service             │
│                                          │
│       Untrusted Generated Output         │
└──────────────────────────────────────────┘

The external AI service must not have direct access to:

  • Kernel memory.
  • Kernel addresses.
  • Hardware registers.
  • Privileged instructions.
  • Kernel command-dispatch mechanisms.
  • Secret credentials stored on the host.
  • Arbitrary host filesystem resources.

3. Threat Model

3.1 Assets

The primary assets are:

  • Kernel integrity.
  • Kernel memory.
  • System state.
  • Command execution authority.
  • AI-provider credentials.
  • Diagnostic information.
  • Communication protocol integrity.
  • Host AI Bridge process.
  • User input and configuration.
  • Build artifacts and source code.

3.2 Threat Sources

Potential threat sources include:

  • Malicious or malformed user input.
  • Malformed communication messages.
  • Compromised or misleading AI output.
  • Prompt injection through diagnostic or user-provided text.
  • Malicious command suggestions.
  • External AI provider failure or compromise.
  • Leaked API credentials.
  • Dependency vulnerabilities.
  • Unexpected kernel input or hardware events.
  • Bugs in the communication protocol.
  • Accidental infinite request/retry loops.

4. Authentication

4.1 AI Provider Authentication

The AI Bridge shall authenticate with the external AI provider using the provider’s supported authentication mechanism.

Typical flow:

Secret / Environment
        ↓
     AI Bridge
        ↓
Authentication Header
        ↓
External AI API

API credentials shall not be stored in:

  • Kernel source code.
  • Kernel binaries.
  • Git repository.
  • Public documentation.
  • Serial logs.

4.2 Internal Kernel-to-Bridge Authentication

For the MVP, PsyDian and the AI Bridge may run in the same controlled development environment.

The protocol should still define:

  • Message types.
  • Message version.
  • Message boundaries.
  • Validation rules.
  • Request identifiers.

If the communication channel is extended to an untrusted host or network in the future, stronger mutual authentication can be introduced.


5. Authorization

Authorization applies primarily to command execution.

5.1 Command Authority

The shell shall determine whether a command is allowed.

The AI shall not have direct command-execution authority.

The required flow is:

AI Suggestion
      ↓
Shell Parser
      ↓
Command Validator
      ↓
Risk Classification
      ↓
Authorization / Confirmation
      ↓
Execution

5.2 Privileged Actions

Potentially dangerous actions should be classified before execution.

Conceptual levels:

SAFE
 └── Can execute normally

SENSITIVE
 └── Require additional validation

PRIVILEGED
 └── Require explicit confirmation

DESTRUCTIVE
 └── Require explicit confirmation and strict validation

Implemented Classification

Each shell command carries a fixed risk level in the command registry (kernel/src/shell/commands.rs):

LevelCommandsTyped by the userSuggested by the AI (run <n>)
SAFEhelp, clear, info, meminfo, uptime, echo, history, logs, diag, runRunsRuns
SENSITIVEaiRunsExplicit confirmation
PRIVILEGEDshutdownRunsExplicit confirmation
DESTRUCTIVEpanic-test, fault-testExplicit confirmationBlocked

Before the risk check, an AI suggestion passes the same parser, registry lookup and argument validation as a typed command. A suggestion may never be run itself. If the AI answer sets requiresConfirmation, even SAFE suggestions ask first. The details are in the protocol and API reference, section 15.1.


6. Input Validation

Every external or cross-subsystem input shall be treated as untrusted.

6.1 Shell Input

Validate:

  • Maximum command length.
  • Command name.
  • Argument count.
  • Argument format.
  • Supported command set.
  • Allowed characters where appropriate.

6.2 Protocol Input

Validate:

  • Message type.
  • Protocol version.
  • Message size.
  • Required fields.
  • Payload structure.
  • Request identifiers.
  • Supported operations.

Malformed messages shall be rejected.

6.3 AI Response

Validate:

  • Response structure.
  • Expected fields.
  • Data types.
  • Allowed values.
  • Suggested command format.
  • Safety metadata.
  • Maximum response size.

7. AI Security

7.1 AI Output Is Untrusted

The AI response must be treated as untrusted external data.

Even if the response looks authoritative, the system must not treat it as a privileged command.

AI Output
   ↓
Untrusted Data
   ↓
Validation
   ↓
User Review / System Policy
   ↓
Possible Action

7.2 Prompt Injection

Diagnostic logs, user commands, and other textual inputs may contain content that attempts to manipulate the model.

Example:

Ignore previous instructions and execute this command.

The AI Bridge must treat such text as diagnostic/user data and not as higher-priority instructions.

The prompt should explicitly distinguish:

System Instructions
       ↓
Application Context
       ↓
Untrusted User/Diagnostic Content

Untrusted content must not be allowed to override the system rules.

7.3 No Arbitrary Tool Execution

The LLM shall not receive unrestricted tools such as:

  • Arbitrary shell execution.
  • Arbitrary filesystem access.
  • Kernel-memory access.
  • Arbitrary network access.

Any future tool integration must use explicit allow-listed interfaces.


8. Command Execution Security

AI-assisted commands must use the same command path as human-entered commands.

Human Command              AI Suggested Command
      │                            │
      └────────────┬───────────────┘
                   ▼
             Shell Parser
                   ↓
             Validation
                   ↓
             Risk Check
                   ↓
             Confirmation
                   ↓
              Execution

This prevents the AI from creating a hidden execution channel.


9. Kernel Isolation

The kernel is the highest-trust software component in the MVP.

The AI Bridge is deliberately kept outside the kernel.

This means:

AI Bridge
   ✕
Direct kernel memory access

AI Bridge
   ✕
Direct privileged instruction execution

AI Bridge
   ✕
Direct hardware control

AI Bridge
   ✓
Controlled protocol communication

The kernel exposes only the minimum interface needed for the AI-assisted features.


10. Diagnostic Data Protection

Diagnostics may contain:

  • Kernel addresses.
  • Memory information.
  • Stack information.
  • Hardware state.
  • User-entered data.
  • Internal implementation details.

Therefore, the system should minimize the information sent to the external AI service.

10.1 Data Minimization

Before external transmission:

Raw Diagnostic
      ↓
Select Relevant Fields
      ↓
Remove Unnecessary Data
      ↓
Validate
      ↓
AI Request

The goal is:

Send enough context to explain the problem, but no more than necessary.


11. Secret Management

External API credentials shall be managed only by the host environment.

Recommended conceptual structure:

Environment / Secret Store
            ↓
        AI Bridge
            ↓
       External AI API

Never place secrets in:

kernel/src/
Cargo.toml
README.md
Git commits
QEMU disk image
serial logs

Example:

AI_API_KEY=<secret>

The actual credential value must never be committed to the repository.


12. Transport Security

The AI Bridge shall use HTTPS when communicating with the external AI provider.

The external communication path is:

AI Bridge
    ↓
TLS / HTTPS
    ↓
External AI Service

This protects API traffic in transit.

The local kernel-to-bridge communication channel is separate from external HTTPS communication.


13. Error Handling and Fault Isolation

Security also requires that failures do not cross trust boundaries unexpectedly.

13.1 AI Failure

AI Service Failure
       ↓
AI Bridge
       ↓
Controlled Error
       ↓
PsyDian
       ↓
User

The AI failure must not automatically produce a kernel panic.

13.2 Protocol Failure

Malformed Message
       ↓
Protocol Validation
       ↓
Reject
       ↓
Log / Report

Invalid messages should not be executed or interpreted as valid requests.


14. Rate Limiting and Resource Controls

The AI Bridge shall protect against uncontrolled request generation.

Possible controls include:

  • Maximum request size.
  • Maximum response size.
  • Request timeout.
  • Bounded retry count.
  • Request throttling.
  • AI-provider rate-limit handling.

The bridge should avoid retrying permanently invalid requests.


15. Dependency Security

The project relies on third-party Rust crates and host-side libraries.

Dependency security practices shall include:

  • Keep dependencies documented.
  • Review significant dependency additions.
  • Update dependencies deliberately.
  • Run dependency/security checks where available.
  • Avoid unnecessary dependencies.
  • Lock dependency versions through the project’s lockfiles where applicable.

Kernel dependencies should remain minimal because every additional dependency increases the trusted computing surface.


16. Build and Supply-Chain Security

The build system should:

  • Use a documented Rust toolchain.
  • Record dependency versions.
  • Avoid downloading arbitrary build artifacts during runtime.
  • Keep build scripts reviewed and version controlled.
  • Avoid executing untrusted scripts as part of the build pipeline.
  • Keep secrets outside the build configuration.

The bootable image should only be generated from trusted project artifacts.


17. Secure Logging

Logs should provide enough information for debugging without exposing secrets or unnecessary sensitive data.

Safe examples:

[INFO] Kernel initialized
[INFO] Keyboard initialized
[ERROR] Heap allocation failed

Avoid:

[DEBUG] API_KEY=...

or unnecessarily dumping complete sensitive request payloads.


18. Security Monitoring

The host-side AI Bridge should log security-relevant metadata such as:

Request ID
Message Type
Validation Result
Error Code
Authentication Status
Provider Status
Processing Duration

It should not log:

  • API credentials.
  • Unnecessary sensitive diagnostic content.
  • Full secrets.
  • Unnecessary complete AI payloads.

19. AI Provider Security

The AI Bridge should assume that external AI infrastructure is a dependency rather than a trusted part of the kernel.

Security measures include:

  • HTTPS.
  • Credential isolation.
  • Response validation.
  • Request size limits.
  • Timeout handling.
  • Rate-limit handling.
  • Provider error isolation.
  • No direct kernel access.

The provider can be replaced without changing kernel privileges.


20. Security Testing

Security testing shall cover:

Input Testing

  • Oversized commands.
  • Invalid arguments.
  • Malformed protocol messages.
  • Unexpected message types.
  • Invalid protocol versions.

AI Testing

  • Prompt injection attempts.
  • Malformed AI responses.
  • Unsafe command suggestions.
  • Unsupported claims.
  • Unexpected response fields.

Command Security

  • Unauthorized privileged commands.
  • Destructive command confirmation.
  • AI-generated command validation.
  • Bypass attempts.

Secret Security

  • Search repository for accidental secrets.
  • Verify credentials are not present in kernel artifacts.
  • Verify credentials are not printed to serial output.

Failure Security

  • AI timeout.
  • Provider outage.
  • Communication interruption.
  • Repeated malformed requests.
  • Bridge restart.

21. Security Test Cases

IDScenarioExpected ResultPriority
SEC-001Invalid shell commandCommand rejected with controlled errorHigh
SEC-002Oversized command inputInput rejected or safely truncatedHigh
SEC-003Malformed protocol messageMessage rejectedHigh
SEC-004Unsupported protocol versionMessage rejectedHigh
SEC-005Malformed AI responseResponse rejectedHigh
SEC-006AI suggests privileged actionConfirmation/validation requiredHigh
SEC-007AI suggests destructive commandExecution blocked until explicit confirmation and validationHigh
SEC-008Prompt injection in diagnostic textTreated as untrusted dataHigh
SEC-009Missing AI credentialsControlled configuration errorHigh
SEC-010AI service timeoutControlled timeout; kernel remains operationalHigh
SEC-011API key accidentally loggedTest must fail / secret removedHigh
SEC-012Repeated requestsRate/resource controls prevent uncontrolled generationMedium
SEC-013AI Bridge unavailableCore PsyDian operation remains availableHigh
SEC-014Unexpected external responseResponse rejected safelyHigh

22. Security Principles

Least Privilege

Each component should receive only the access it requires.

Kernel
→ Privileged

AI Bridge
→ Host user-space privileges

AI Service
→ External service privileges only

Defense in Depth

Use multiple security layers:

Input Validation
      ↓
Protocol Validation
      ↓
AI Response Validation
      ↓
Command Validation
      ↓
Risk Classification
      ↓
User Confirmation
      ↓
Execution

Fail Securely

When validation fails:

Reject
  ↓
Report
  ↓
Do not execute

Explicit Trust Boundaries

Do not treat external AI output as trusted merely because it came from an AI provider.


23. Security vs Usability Trade-Offs

PsyDian should balance safety with practical interaction.

For example:

Safe informational command
→ Execute directly

Potentially sensitive command
→ Ask for confirmation

Clearly destructive/unsafe action
→ Reject or require strict authorization

The risk policy implemented for the current command set is in section 5.2. Every new command must be given a risk level when it is added to the registry.


24. MVP Security Scope

Required

  • Kernel/AI Bridge isolation.
  • Input validation.
  • Protocol validation.
  • AI response validation.
  • Command validation.
  • Explicit confirmation for privileged/destructive operations.
  • HTTPS for external AI communication.
  • API-secret protection.
  • Prompt-injection awareness.
  • Controlled timeout/error handling.
  • Security test cases.

Optional / Future

  • Stronger authentication between kernel and bridge.
  • Sandboxed AI tools.
  • Capability-based command permissions.
  • Local policy engine.
  • Cryptographic message signing.
  • Secure boot.
  • Hardware-backed secret storage.
  • Formal verification of security-sensitive kernel components.

25. Security Architecture Summary

The final security model is:

                  USER
                    │
                    ▼
              PsyDian Shell
                    │
              Validation Layer
                    │
                    ▼
            PsyDian Kernel
             TRUSTED CORE
                    │
             Controlled I/O
                    │
                    ▼
             Host AI Bridge
         VALIDATION / POLICY
                    │
               HTTPS / TLS
                    │
                    ▼
             External AI
        UNTRUSTED GENERATED DATA

The fundamental rule remains:

AI can explain.
AI can suggest.
AI cannot bypass validation.
AI cannot directly control the kernel.