Metadata-Version: 2.4
Name: keeper-manifest-drift-watch
Version: 1.0.0rc2
Summary: Drift-detection daemon for Keeper Manifest tenants - polls live state, opens GitHub PRs, posts to Slack/ServiceNow.
Project-URL: Documentation, https://docs.keeper.io/keeperpam/keeper-manifest/
Project-URL: Homepage, https://github.com/Keeper-Security/keeper-manifest
Project-URL: Repository, https://github.com/Keeper-Security/keeper-manifest
Project-URL: Issues, https://github.com/Keeper-Security/keeper-manifest/issues
Project-URL: Changelog, https://github.com/Keeper-Security/keeper-manifest/blob/main/CHANGELOG.md
Project-URL: Security, https://github.com/Keeper-Security/keeper-manifest/blob/main/SECURITY.md
Project-URL: License, https://github.com/Keeper-Security/keeper-manifest/blob/main/LICENSE
Author: Keeper Security Engineering
Maintainer: Martin Sawczyn, Jeremy London
License-Expression: MIT
License-File: LICENSE
Keywords: daemon,drift,gitops,keeper,manifest
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Security
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.11
Requires-Dist: keeper-manifest<1.1.0,>=1.0.0rc2
Provides-Extra: dev
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff==0.15.10; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == 'test'
Description-Content-Type: text/markdown

# keeper-manifest-drift-watch

Drift-detection daemon for [Keeper Manifest](https://github.com/Keeper-Security/keeper-manifest) tenants.

Polls the live tenant on a schedule, compares to git-tracked manifests, and either:

- Opens a GitHub Pull Request with a one-line fix proposal, **or**
- Posts a structured Slack message with the diff summary, **or**
- Files a ServiceNow ticket with the same payload.

The daemon never applies changes itself - it surfaces drift so a human
(or another approved automation) can decide.

Canonical documentation: [Drift Watch](https://docs.keeper.io/keeperpam/keeper-manifest/command-reference/drift-watch) and [Keeper Manifest Documentation](https://docs.keeper.io/keeperpam/keeper-manifest/overview).

## Install

```bash
pip install keeper-manifest-drift-watch
# Or install in an isolated environment:
uv tool install keeper-manifest-drift-watch
```

The `keeper-manifest` main distribution ships the `keeper-manifest drift-watch`
CLI verb, which auto-detects this package and dispatches to it.

## Preview gate

The CLI is gated behind `KEEPER_MANIFEST_PREVIEW=drift-watch` so that the
daemon's outbound side-effects (PRs, Slack posts, ServiceNow tickets)
require explicit operator opt-in. A bare `KEEPER_MANIFEST_PREVIEW=1` is
**not** sufficient - the substring `drift-watch` must be present.

## Programmatic use

```python
from keeper_manifest_drift_watch.drift_watch import WatchConfig, watch_loop

cfg = WatchConfig(
    manifest_paths=["manifests/prod-pam.yaml"],
    poll_interval_seconds=300,
    github_repo="Keeper-Security/our-tenant-manifests",
    github_token="ghp_...",
    pr_base_branch="main",
    dry_run=False,
    state_file=None,           # or explicit path / KEEPER_MANIFEST_DRIFT_WATCH_STATE_FILE
    dedup_ttl_seconds=86400,   # or KEEPER_MANIFEST_DRIFT_WATCH_DEDUP_TTL_SECONDS
)
watch_loop(cfg)
```

## Subprocess and state contract

`watch_loop` invokes `keeper-manifest plan --json` per manifest, validates `"schema": "keeper-plan-result.v1"` (plus the strict 5-key versionless legacy envelope), verifies integer summary/change-row/exit-code consistency before any side effects, and treats:

- exit `0` → verified clean poll; clears active drift for that manifest and allows adaptive `1.5x` clean backoff
- exit `2` → validated drift detected; dispatches unsuppressed per-destination alerts/PRs
- exit `4` / `5` / malformed JSON / inconsistent counts → unhealthy error; records `healthy: false` without backing off or erasing unresolved drift

Health and delivery fingerprints are persisted atomically (`0600`, `O_NOFOLLOW`, max `1 MiB`) as `"schema": "keeper-drift-watch-state.v1"` at `state_file` (or `--state-file` / `KEEPER_MANIFEST_DRIFT_WATCH_STATE_FILE`; default `$KEEPER_MANIFEST_DRIFT_WATCH_STATE_DIR` → `$XDG_STATE_HOME/keeper-manifest/drift-watch` → `~/.keeper/drift-watch/state-<sha256>.json`).

- **Per-destination deduplication and retry:** Each enabled channel (`slack`, `servicenow`, `github_pr`) is marked only after successful delivery and suppressed for identical SHA-256 plan-intent fingerprints within `dedup_ttl_seconds`; failed channels retry on the next poll.
- **Redacted-secret hashing limit:** Because `plan --json` redacts secret values (`***REDACTED***`), consumer-only hashing cannot distinguish two plans that differ exclusively inside redacted secret ciphertext when visible keys and metadata are identical.
- **Crash-duplicate bound:** If the daemon crashes after an external send succeeds and before the local atomic rename commits `keeper-drift-watch-state.v1`, that destination may receive a duplicate notification on restart. Persisted state never enables `auto_apply` or bypasses `--dry-run`, `--require-clean-git`, or CLI `FileLock` enforcement.

Timeouts (defaults - env-overridable):

| Operation | Default | Env override |
|---|---|---|
| `keeper-manifest plan` | 120 s | `KEEPER_MANIFEST_PLAN_TIMEOUT_SECONDS` |
| `git fetch` / `git push` | 60 s | (not env-overridable) |
| `gh pr create` | 60 s | (not env-overridable) |
| ServiceNow response read | 1 MiB | (not env-overridable) |

## License

MIT - see the parent repository.
