# How we monitor for compliance drift

A daily sweep checks resources against policy for public buckets, untagged resources, and over-broad roles, files findings, and proposes remediation as a reviewed change rather than applying it.

Canonical page: https://openchatly.com/use-cases/compliance-monitoring

Infrastructure drifts out of compliance quietly. A bucket gets made public for a
one-off, a resource ships without its tags, a role picks up a permission it no
longer needs. Each change is small and reasonable in the moment, but they
accumulate, and nobody notices until an audit or an incident surfaces them all at
once. By then reconstructing when each drift happened is hard.

We handle this by checking the infrastructure against policy every day, so drift
surfaces the day it appears. This writes up how we run that on Kortix — the
connections, the steps, and the guardrails — so you can set up the same sweep.

- **Team:** Kortix
- **Trigger:** A daily scheduled sweep
- **Connected systems:** AWS · Audit logs · Slack
- **Mode:** Cron-driven · Review-gated

## The problem

The common approaches each have limits. A quarterly manual audit finds drift late
and in bulk, when the context is hardest to recover. A fixed rules engine catches
the checks it was configured for and nothing beyond them. And auto-remediation
that fixes drift on its own can break a service that depended on the very
configuration it "corrected."

We wanted the infrastructure checked against policy daily, with findings filed
where the team already works and fixes proposed as reviewed changes rather than
applied silently.

## What we built

On Kortix, a daily schedule triggers an agent. Each sweep runs in its own
isolated session — a cloud sandbox — with scoped, read access to AWS and the
audit logs. The agent checks resources against policy — public buckets, untagged
resources, over-broad roles — and files what it finds to Slack. Remediation is
proposed as a reviewed change, never applied automatically.

## How it works

### Copy the setup prompt into a new session

Open your Kortix workspace, start a new session, paste this prompt and send it.
The agent writes the agent file, the compliance-sweep skill and the daily
trigger, and opens a change request for you to review. Prefer clicks? Choose
**Use this template** instead.

**Setup prompt**

```
Set up a daily compliance monitoring agent in this workspace.

1. Create the agent agents/compliance-monitoring.md. Its job is to check AWS against our compliance policy and propose fixes as change requests. It may use the AWS and Slack connectors. It only reads AWS.

2. Create the skill skills/compliance-sweep/SKILL.md with these rules:
   - Read the policy from memory/compliance-policy.md on every run. If the file does not exist, start from the rules below and propose it.
   - No S3 bucket is public unless the policy allow-lists it by name.
   - Every resource carries the owner and environment tags.
   - No IAM role holds a full wildcard grant or an unscoped iam:PassRole.
   - For each finding, look up in CloudTrail when it changed and who changed it, then open a change request with the fix. Never apply a fix in AWS.

3. Add a cron trigger daily-compliance-sweep to kortix.yaml. It runs the compliance-monitoring agent every day at 06:00 UTC with the prompt "Load the compliance-sweep skill, run one complete sweep, and post the findings to #security."

4. Tell me which of these connectors are not connected yet.

5. Open a change request with all of it. Do not merge it.
```

### Connect your tools

Open **Connectors** in your workspace and connect AWS with read-only access and
Slack. Credentials are brokered server-side and never enter the
agent's machine.

- **AWS** (Required):
Checks buckets, tags and IAM roles, and reads audit logs.
- **Slack** (Required):
Posts findings with their audit trail and proposed fixes.
- **Jira** (Optional):
Tracks each finding as a ticket for its owner.

### Run it once with this prompt

Merge the change request, then start a session with the
**compliance-monitoring** agent and send this prompt. Review the change
requests it opens before you let the schedule take over.

**Prompt**

```
Run one compliance sweep on AWS. Read only.

1. Load the policy from memory/compliance-policy.md.
2. List every S3 bucket and IAM role once, and check each against the policy: public buckets, missing required tags and over-broad roles.
3. For each finding, look up in CloudTrail when it changed and who changed it.
4. Open one change request per finding with the proposed fix. Do not apply any fix.
5. Post each finding with its audit trail and change request link to #security, or one line if nothing drifted.
```

### Let the daily schedule take over

The change request added this trigger to `kortix.yaml`. From now on the agent
runs every day at 06:00 UTC, each run in a new session on its own cloud computer. To change the time, edit the cron line, or open
**Triggers** in the workspace.

**kortix.yaml**

```yaml
triggers:
  - slug: daily-compliance-sweep
    name: Daily compliance sweep
    on:
      cron: "0 0 6 * * *"
    run:
      agent: compliance-monitoring
      prompt: Load the compliance-sweep skill, run one complete sweep, and post the findings to #security.
```

### Propose every fix as a change request

The agent only reads AWS. Each fix arrives as a change request with the
diagnosis and the proposed change. A person reviews it, merges it and applies
it. Nothing changes in AWS without that review.

### Read the findings

Each run ends with one message in the channel. This is what a run looks like
in the session:

> **Daily compliance sweep · 06:00**
>
> Prompt: Load the compliance-sweep skill, run one complete sweep, and post the findings to #security.
>
> Found **3** findings: **1** newly public bucket, **1** resource without the
> **owner** tag, and **1** role with a wildcard grant. CloudTrail shows when each
> one changed and who changed it. **3** change requests with the proposed fixes
> wait for review.

> **The pattern**
> Run the sweep on a **cron** trigger, give the agent scoped read **connectors**
> into AWS and the audit logs, encode the compliance policy as **skills** and
> **memory**, and propose every fix as a reviewed **change request** rather than
> applying it.

## Make it do more

Once it works, paste any of these into the same session.

**Check security groups**

```
Extend the policy to flag security groups that allow 0.0.0.0/0 on any port other than 443, in every region I list.
```

**Weekly posture report**

```
Every Monday, post the count of open findings by type to #security, and list the change requests that still wait for review.
```

**Keep audit evidence**

```
Each month, write a dated summary of every finding and its fix to memory/compliance-evidence.md for audit review.
```

## Guardrails

Giving an agent a standing view of the infrastructure is a trust question. The
relevant controls on Kortix:

- **Isolation.** Every sweep runs in its own isolated sandbox on its own branch.
  The session is granted access only to what it's scoped to read, and only the findings it
  files are written back out.
- **Scoped secrets.** Each credential is encrypted in the secrets manager,
  injected into the sandbox at runtime, and scoped to the agents you grant them to or the
  logs.
- **Human approval gate.** Remediation is proposed, never auto-applied; a person
  reviews and applies each change.
- **Everything is code.** The agent's persona, skills, and permissions are files
  in the repo — versioned and changed through a reviewed **change request**, not
  a dashboard setting.

## The outcome

- **Daily:** Infrastructure re-checked against policy every day
- **Same-day:** Drift caught before it accumulates for an audit
- **Review-gated:** Every fix proposed as a change, never auto-applied

The drift that used to surface in bulk at audit time now arrives as small daily
findings in Slack, each with a proposed fix a person reviews before it's applied.
The team reviews a change instead of reconstructing months of drift, and the
infrastructure stays close to policy.
