Runtime Application Protection

Production-grade guide to runtime application protection covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.

Runtime Application Protection (RAP) secures applications while they are running, detecting and responding to threats in real time—protecting against exploits, data leaks, and configuration drifts that static analysis and pre-deployment scanning miss. It matters most during active service: when an application is live under user load, receiving requests, processing data, and interacting with external systems.

Detecting Runtime Threats

Applications in production face threats that are invisible during development and testing: dynamic attack surfaces, unanticipated input, and evolving infrastructure. RAP continuously monitors running processes to detect anomalies such as unexpected system calls, abnormal memory usage, suspicious network traffic, and unauthorized file access.

A typical RAP system ingests logs, traces, and metrics from the application and its host, correlates events across services, and applies detection rules to identify anomalies. The core mechanism is a lightweight agent deployed alongside the application, which collects telemetry and sends it to a central analysis engine.

The agent runs in the same process as the application or as a sidecar container. It captures:

Each event is timestamped and associated with a unique request or transaction ID. The agent emits structured JSON logs to a local file or directly to a collector.

{
  "timestamp": "2024-07-15T12:34:56.789Z",
  "event": "syscall",
  "pid": 4213,
  "tid": 4213,
  "syscall": "openat",
  "args": {
    "dfd": 23,
    "pathname": "/etc/secret.conf",
    "flags": 0,
    "mode": 0
  },
  "return": 31,
  "duration_ns": 21043
}

The collector aggregates events and applies detection logic. Rules may be written in a simple declarative language or in SQL-like expressions.

SELECT
  application,
  service,
  COUNT(*) AS event_count,
  AVG(duration_ns) AS avg_duration
FROM events
WHERE event = 'syscall'
  AND syscall = 'read'
  AND duration_ns > 50000
GROUP BY application, service
HAVING COUNT(*) > 10
ORDER BY avg_duration DESC
LIMIT 5;

When a rule triggers, it generates an alert. The system may automatically respond—logging, sending to a dashboard, or initiating a remediation action.

Responding to Detected Threats

Once a threat is detected, RAP systems respond through a combination of alerting, logging, and automated actions. Response is not just notification; it includes immediate mitigation.

A common response is to generate a security incident with context. The incident includes:

The system may also execute a mitigation action. For example, if a suspicious execve call is detected on a web service:

{
  "event": "syscall",
  "syscall": "execve",
  "args": {
    "filename": "/usr/local/bin/php",
    "argv": ["/usr/local/bin/php", "/app/web/index.php", "--debug"],
    "envp": [ "PATH=/usr/local/bin:/usr/bin:/bin", "DB_HOST=prod-db" ]
  }
}

This pattern suggests a PHP script is being executed with unexpected arguments—possibly an attacker uploading a malicious script.

The RAP engine may respond by:

  1. Blocking the process: using kill -SIGTERM or systemctl stop to halt the service
  2. Isolating the container: applying docker network disconnect, iptables rules, or cgroup limits
  3. Enforcing a policy: writing a new security.json file to the container’s filesystem
  4. Sending a signal: writing a message to a queue or sending an HTTP POST to an orchestration service

The agent may also trigger a contextual response, such as:


$ /opt/rap/execute.sh --action=block --target=web-service --reason="Suspicious execve: php index.php --debug"

The response script may:

curl -X POST https://slack.com/api/chat.postMessage \
  -H "Authorization: Bearer xoxb-1234567890-..." \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "#security-alerts",
    "text": "🚨 RAP Alert: Suspicious execve detected on web-service",
    "attachments": [
      {
        "title": "Process Context",
        "fields": [
          { "title": "PID", "value": "4213", "short": true },
          { "title": "Command", "value": "/usr/local/bin/php index.php --debug", "short": true },
          { "title": "Environment", "value": "DB_HOST=prod-db, PATH=...", "short": false }
        ],
        "color": "#ff0000"
      }
    ]
  }'

Enforcing Security Policies

RAP enforces security policies at runtime. These policies define what is allowed and what constitutes a violation.

A policy is a set of rules that govern application behavior. Rules may be based on:

Policies are defined in JSON or YAML and loaded at startup.

# /etc/rap/policy.yml
name: "Production Web Service"
description: "Enforces secure behavior for production web service"
rules:
  - name: "Allow only known file paths"
    type: "file-access"
    expected:
      - "/etc/app.conf"
      - "/app/static/"
      - "/var/log/app.log"
    allow_new: true
    severity: "high"
    actions:
      - "log"
      - "alert"
      - "block"

  - name: "Require specific network endpoints"
    type: "network"
    outbound:
      - "https://api.payment.com"
      - "tcp://redis:6379"
    allow_any: false
    severity: "critical"
    actions:
      - "alert"
      - "execute"
      - "send-webhook"

The agent reads the policy and validates every runtime event against it. On a violation, it executes the defined actions.

For example, if the agent sees a connect call to smtp://mail.example.com:587, but the policy only allows api.payment.com and redis:6379, the event triggers a critical alert.

The agent may also dynamically update the policy. If a new rule is added via a REST API, the agent polls a /policy endpoint every 30 seconds.

GET /policy?version=20240715-1234 HTTP/1.1
Host: rap-collector.example.com
Authorization: Bearer secret-abc123
{
  "version": "20240715-1234",
  "rules": [
    {
      "name": "Allow dynamic config updates",
      "type": "file-access",
      "expected": [ "/app/config/*.json" ],
      "allow_new": true,
      "severity": "medium",
      "actions": [ "log", "alert" ]
    }
  ]
}

The agent updates its policy and applies it immediately—no restart required.

Handling Failure Modes

RAP systems silently fail in subtle ways. These are the sharp edges that surface only under production load.

One common failure is event loss: when the agent cannot write to the collector due to network issues. The agent buffers events in a local queue, typically in a circular buffer or a simple file.

If the buffer fills, the agent drops the oldest events and logs a warning:

[WARN] 2024-07-15T12:35:12.345Z: Event buffer full; dropping oldest events

The collector must handle duplicate events. When a network outage causes the same event to be sent multiple times, the system must deduplicate.

A common deduplication strategy is to use a unique identifier (UUID) per event. The collector maintains a set of seen IDs and drops duplicates.

{
  "event_id": "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8",
  "timestamp": "2024-07-15T12:34:56.789Z",
  "event": "syscall",
  "syscall": "openat",
  "args": { "dfd": 23, "pathname": "/etc/secret.conf" }
}

The agent may also fail to load the policy. If the policy file is malformed, the agent logs:

[ERROR] 2024-07-15T12:34:50.123Z: Failed to parse policy: /etc/rap/policy.yml
Expected key 'rules' at line 5, column 3

The system continues with a default policy, but alerts the operator.

Another failure is policy drift: the runtime configuration diverges from the expected policy, but the system does not detect it until the next event.

For example, the agent expects APP_ENV=production, but the process is started with APP_ENV=staging. The event execve contains the wrong environment, but the rule only triggers when the environment is set at startup.

To catch this, the agent may periodically validate configuration:

$ /opt/rap/validate-config.sh

The script reads the current environment and compares it to the expected values in the policy. If a mismatch is found, it logs:

[WARNING] 2024-07-15T12:35:00.000Z: Configuration drift detected: APP_ENV=staging, expected=production

The system may then trigger a reconciliation action, such as:

# Update environment file
$ cat > /etc/app.env << EOF
APP_ENV=production
LOG_LEVEL=info
DATABASE_URL=postgresql://prod-db:5432/app
EOF

The agent may also generate baseline profiles to detect anomalies. The profile captures a normal behavior over time—e.g., typical system call sequences during a request.

The system uses a sliding window of events to build a model of normal behavior. On a deviation, it emits an alert.

For example, a typical request to a user profile endpoint might include:

If the agent sees connect to smtp:25 instead, it logs:

[ANOMALY] 2024-07-15T12:34:58.123Z: Unexpected network call: smtp:25

The profile may be updated automatically. The system collects events for 24 hours, then recomputes the baseline.

Integrating with DevSecOps Workflows

RAP integrates with existing DevSecOps practices. It is not a standalone tool but a component in a continuous security pipeline.

When a new build is deployed, the RAP agent starts automatically. It reads configuration from the container image, environment variables, and a shared /etc/rap directory.

The agent may be managed via systemctl:

$ systemctl enable rap-agent
$ systemctl start rap-agent
$ systemctl status rap-agent

Logs are collected via journalctl:

$ journalctl -u rap-agent -f -o cat

The agent may also expose a health check endpoint:

GET /health HTTP/1.1
Host: localhost:8080
{
  "status": "healthy",
  "uptime_seconds": 3456,
  "events_processed": 123456,
  "last_policy_update": "2024-07-15T12:34:50.000Z"
}

The agent may also expose metrics via Prometheus:

# HELP rap_events_processed Total number of events processed
# TYPE rap_events_processed counter
rap_events_processed{service="web"} 123456
rap_events_processed{service="api"} 98765

These metrics feed into monitoring dashboards (Grafana, Prometheus, Datadog) and trigger alerts.

When an alert is generated, the system may automatically create an incident in a ticketing system.

POST /api/incidents HTTP/1.1
Host: jira.example.com
Authorization: Bearer jira-token-12345
Content-Type: application/json

{
  "title": "RAP Alert: Suspicious execve on web-service",
  "description": "A PHP script was executed with --debug flag.",
  "priority": "high",
  "assignee": "security-team",
  "tags": [ "runtime", "execution", "anomaly" ]
}

The integration is not limited to alerts. RAP may also provide security feedback to the CI/CD pipeline.

When a deployment fails due to a runtime violation, the system may update a security-report.json file in the repository:

{
  "deployment_id": 123,
  "status": "failed",
  "violations": [
    {
      "rule": "Allow only known file paths",
      "event": "openat",
      "file": "/etc/backup.conf",
      "expected": [ "/etc/app.conf", "/app/static/", "/var/log/app.log" ],
      "action": "block"
    }
  ],
  "summary": {
    "total_violations": 3,
    "critical": 1,
    "high": 2,
    "timestamp": "2024-07-15T12:34:56.789Z"
  }
}

The CI/CD system can then fail the build, notify the team, and link to the full RAP report.

Summary

Runtime Application Protection is not a product but a pattern: continuous monitoring, policy enforcement, and automated response, all centered on the running application. It detects threats invisible to static analysis and responds with precision and immediacy. It succeeds when the system runs autonomously—when the agent runs, the policy is applied, and the response is executed without human intervention. Its value lies in the details: the JSON logs, the event rules, the configuration drift, the policy updates, and the seamless integration with existing tools. It is the bridge between pre-deployment security and the live, evolving application.

This page was rewritten on 12 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.