Metadata-Version: 2.4
Name: aegvanta-scopeguard
Version: 0.2.0
Summary: Offline deny-by-default IP scope policy helper
License-Expression: MIT
Project-URL: Repository, https://github.com/emrecoskunz/aegvanta-scopeguard
Project-URL: Issues, https://github.com/emrecoskunz/aegvanta-scopeguard/issues
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Aegvanta ScopeGuard

A small, dependency-free Python library and CLI for evaluating literal IP addresses against an explicit assessment scope. Intended for authorized defensive security tooling and offline policy checks. Deny rules take precedence; missing allow rules deny access. No network connections, DNS queries, scanning, or third-party runtime dependencies.

## Installation

Requires Python 3.10+. The package is available on [PyPI](https://pypi.org/project/aegvanta-scopeguard/).

```sh
python -m pip install aegvanta-scopeguard
```

For development, clone this repository and install from the repository root:

```sh
python -m pip install .
```

Download versioned distributions and SHA-256 checksums from [GitHub releases](https://github.com/emrecoskunz/aegvanta-scopeguard/releases).

## Library example

```python
from scopeguard import ScopePolicy
policy = ScopePolicy(allow=['192.0.2.0/24'], deny=['192.0.2.10/32'])
assert policy.permits('192.0.2.1')
assert not policy.permits('192.0.2.10')
assert policy.evaluate('192.0.2.10').reason == 'explicit_deny'
```

## Reuse a JSON policy in Python

Version 0.2.0 adds `ScopePolicy.from_json` and the `scopeguard` command. Both use the same parser. Check your installed version with `python -m pip show aegvanta-scopeguard`. To evaluate a policy from your application:

```python
from scopeguard import ScopePolicy

# ValueError or an I/O error must abort the operation, not allow the target.
policy = ScopePolicy.from_json('{"allow":["192.0.2.0/24"],"deny":["192.0.2.10/32"]}')
decision = policy.evaluate("192.0.2.1")
```

The [JSON Schema](examples/policy.schema.json) describes the file structure for editor validation. The library is authoritative for CIDR validity, duplicate keys, and address handling. A positive decision is a scope match only; it does not authorize a network connection.

## CLI example

Save this JSON as `policy.json` in your working directory:

```json
{"allow":["192.0.2.0/24"],"deny":["192.0.2.10/32"]}
```

Run the module with any supported version. Version 0.2.0 also provides the equivalent `scopeguard --policy policy.json 192.0.2.1` command.

```sh
python -m scopeguard --policy policy.json 192.0.2.1
```

The CLI prints a JSON decision and exits with code 0 (allowed), 1 (denied or invalid target), or 2 (invalid/missing policy or invalid CLI usage). Example addresses are reserved for documentation. Policies accept only allow and deny arrays of explicit CIDR strings; duplicate keys, invalid CIDRs and unsupported target forms are rejected.

## Limits

This is a standalone prototype and policy helper, **not** an authorization system or a network enforcement boundary. Callers must verify written authorization, independently enforce egress controls, and validate the actual destination at connection time. Hostnames, IPv4-mapped IPv6 targets and scoped IPv6 addresses are rejected. Invalid policy CIDRs raise an error; do not catch configuration errors and fall back to permissive behavior. It does not resolve hostnames, authorize redirects, or establish that a target is safe.

## Development

```sh
python -m unittest discover -s tests -v
```

See [project background](docs/AEGVANTA.md), [contribution guide](CONTRIBUTING.md), [security policy](SECURITY.md), and [MIT license](LICENSE). Reproducible bug reports, genuine use cases and focused patches are welcome. Use synthetic data; never include credentials, customer logs or private infrastructure information.
