Metadata-Version: 2.5
Name: glovebox-core
Version: 0.1.7
Summary: Glovebox's security decisions as pure functions: the host rules, the JSON reader, the egress verdict and the monitor's fail-closed rules
Project-URL: Homepage, https://github.com/AlexanderMattTurner/agent-glovebox
Project-URL: Source, https://github.com/AlexanderMattTurner/agent-glovebox
Author: AlexanderMattTurner
License-Expression: Apache-2.0
Keywords: egress,glovebox,hostname,policy,sandbox
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Security
Requires-Python: >=3.9
Requires-Dist: graphql-core==3.2.12
Description-Content-Type: text/markdown

# glovebox-core

Glovebox's security decisions as pure functions: the host rules, the JSON reader, the egress verdict and the monitor's fail-closed rules. No module here reads a file, a socket, a subprocess, the clock, a thread or the environment. An input that needs one arrives as an argument: a `Protocol` the caller implements, or a value the caller read. `tests/core/test_purity.py` refuses any other import.

## Host rules

`glovebox_core.host_rules` is the one answer to "which host is this" that every part of glovebox uses: the egress proxy's verdict service, the launcher, the session driver and the evals. A host is compared in one spelling: ASCII only, surrounding whitespace removed, lowercased, and an IP literal in its standard form. A name that is not ASCII, or that starts or ends with a dot, is refused rather than folded, so two readers can never disagree about it.

`pod_grants` is the one reader of a Kata pod's `glovebox.dev/egress-grants` annotation, and the node calls it. It returns the granted hosts at their tiers, the address grants and the port grants. It raises `GrantRefused` with the node's own message for the first entry the node refuses. How wide an address grant may be is each node's own setting, so it is not checked here.

A host with a port, such as `{"host": "git.example.com:22", "rw": true}`, is a port grant. The node relays a raw stream to that port on the name's public addresses, so it needs `"rw": true`. A host without a port keeps its plain host meaning.

A grant may not name a `*.` wildcard over a public suffix, or over a name with one below it. `pod_grants` takes the Public Suffix List as an argument: `glovebox_hosts.BUNDLED_SUFFIXES` is the list `tldextract` bundles. Where the list cannot be read, every name is refused.

```python
>>> from glovebox_core.host_rules import pod_grants
>>> from glovebox_hosts import BUNDLED_SUFFIXES
>>> granted = pod_grants('["httpbin.org", {"host": "git.example.com:22", "rw": true}]', BUNDLED_SUFFIXES)
>>> granted.hosts
{'httpbin.org': 'ro'}
>>> granted.ports
[PortGrant(host='git.example.com', port=22)]
>>> pod_grants('["*.amazonaws.com"]', BUNDLED_SUFFIXES)
Traceback (most recent call last):
...
glovebox_core.host_rules.GrantRefused: glovebox.dev/egress-grants: '*.amazonaws.com' is a wildcard over a name with the public suffix ...
```

`encode_pod_grants` is the writer for the same annotation. It writes each entry as a bare read-only string, sorted and once, and never adds `"rw"`. It raises `GrantRefused` for an address or `HOST:PORT`, which opens a raw tunnel that only a person grants, read-write, on the node. It reads its text back with `pod_grants`, so it also raises for any other entry the node would refuse.

A runner that writes the annotation checks each entry before it asks for a pod. `grant_host_refusal(host, suffixes)` gives the node's reason for refusing a host name, or None. `address_grant(entry)` reads an address entry as an `AddressGrant`, returns None for a host name, and raises `GrantRefused` for a malformed one.

The host rules and `glovebox_core.json_object` import only the standard library, so they run under Python 3.9. The egress modules need Python 3.11.

## Egress verdict

`glovebox_core.verdict.decide` rules where one request Envoy asks about may go. The caller passes what it read as `Facts`, such as the setup window, and every address screen as a `Screen`. The verdict resolves no name and writes no record.

## Monitor fail-closed rules

`glovebox_core.monitor` gives the answer for a tool call that no monitor model judged. An outage takes `outage_decision`: the configured fail mode, or ASK for a high-risk call. A reply with no readable verdict, an open circuit breaker and a missing API key each take their own `fixed_decision`. No fail-closed answer is ALLOW. The monitor package makes the model call and keeps the breaker and the records.
