Metadata-Version: 2.5
Name: openhound-postprocess
Version: 0.3.0
Summary: OpenHound collector for derived relationships from BloodHound graph data
Author-email: Jim Sykora <jsykora@specterops.io>
Requires-Python: <=3.14,>=3.13
Requires-Dist: openhound==0.4.1
Description-Content-Type: text/markdown

# OpenHound Postprocess

OpenHound Postprocess derives relationships from data already in BloodHound.
It queries the graph through the BloodHound API, builds lookup tables, and emits
OpenGraph edges between existing nodes.

## Generated edges

The tables show the direction of each emitted edge and the graph evidence used
to create it. A two-way arrow means the collector emits one edge in each
direction.

### GitHub Actions workload identity

| Platforms | Edge and direction | How the edge is derived |
| --- | --- | --- |
| GitHub Actions → Azure | `GH_CanAssumeIdentity` from a GitHub scope to an `AZFederatedIdentityCredential` | Use the credential's `subject` when its issuer is GitHub Actions. Resolve the subject to the corresponding GitHub repository, branch, environment, or organization role. |
| GitHub Actions → AWS | `GH_CanAssumeIdentity` from a GitHub scope to an `AWS_Role` | Extract the GitHub OIDC `sub` condition from an IAM trust policy's `Allow` statement for the GitHub OIDC provider. The collector supports `StringEquals` and `StringLike` subject conditions and resolves them to GitHub scopes. |

See [OIDC correlation](#oidc-correlation) for how exact and wildcard subjects
resolve to GitHub scopes.

### GitHub user and group identity

| Platforms | Edge and direction | How the edge is derived |
| --- | --- | --- |
| GitHub SAML with Entra ID, Okta, or PingOne | `GH_MapsToUser` from `GH_ExternalIdentity` to the identity provider's user. `GH_SyncedTo` from that user to `GH_User`. | Use the GitHub SAML provider to scope the lookup to its identity provider and environment. Match the external identity's SAML NameID to `AZUser.userprincipalname`, `Okta_User.username`, or `PingOne_User.email`. The sync edge also requires a resolved GitHub user. |
| Entra ID, Okta, or PingOne → GitHub via SCIM | `SCIM_Provisioned` from the identity provider's user to `SCIM_User`. `GH_SyncedTo` from that user to `GH_User`. | Start with an enabled SCIM user linked through a GitHub external identity to a GitHub user. Match `SCIM_User.external_id` to a unique `AZUser`, `Okta_User`, or `PingOne_User` by `objectid`. |
| Entra ID → SCIM group | `SCIM_Provisioned` from `AZGroup` to `SCIM_Group`. | Match `SCIM_Group.external_id` to a unique `AZGroup.objectid`. |

`GH_MapsToUser` is a non-traversable evidence edge. `GH_SyncedTo` is a
traversable, composed edge back to the GitHub user. See
[Identity correlation](#identity-correlation) for the SCIM path and current
group support.

### Hosts and devices

Each match emits traversable `Host_SameHostAs` edges between representations
of the same compute instance.

| Platforms | Edge direction | How the edge is derived |
| --- | --- | --- |
| Entra ID and Azure | `AZDevice` ↔ `AZVM` | Strip the exact `[AzureResourceId]:` prefix from matching entries in `AZDevice.physical_ids` and match the full resource ID to `AZVM.objectid`. |
| Entra ID and Active Directory | `AZDevice` ↔ `Computer` | Match `AZDevice.onpremid` to `Computer.objectid`. |
| Azure and Active Directory | `AZVM` ↔ `Computer` | Match `AZVM.vm_id` to `Computer.azvmid`. |
| Active Directory and Okta | `Computer` → `Okta_Device` | For Okta devices with `platform = 'WINDOWS'`, match `Okta_Device.object_sid` to `Computer.objectid`. |
| Jamf and Okta | `jamf_Computer` → `Okta_Device` | For Okta devices with `platform = 'MACOS'`, match `Okta_Device.udid` to `jamf_Computer.udid`. |

Host identity comparisons ignore case and surrounding whitespace and require
nonempty keys. The collector deduplicates directed edges and uses the stored
BloodHound object IDs as endpoints. See the
[Host_SameHostAs edge reference](docs/host-same-host-as.md) for details.

## Capabilities

Before collecting capability-specific resources, the extension probes for the
minimum graph signal needed to make that work useful:

- OIDC: a GitHub Actions Azure FIC or an AWS role that trusts
  `token.actions.githubusercontent.com`
- SAML: a `GH_SamlIdentityProvider` with a `GH_HasExternalIdentity` edge
- SCIM users: an active
  `(:SCIM_User)-[:SCIM_Provisioned]->(:GH_ExternalIdentity)-[:GH_MapsToUser]->(:GH_User)`
  path
- SCIM groups: a `SCIM_Group` with a non-null `external_id`
- Host correlation: an `AZDevice` with a `physical_ids` entry starting with
  `[AzureResourceId]:`, a device with a nonempty `onpremid`, or a Computer with
  a nonempty `azvmid`; Windows `Okta_Device` nodes also enable Computer collection; macOS Okta devices
  enable Jamf Computer collection

The generic node collection defaults to:

- `AZFederatedIdentityCredential`
- `AWS_Role`
- `GH_Organization`
- `GH_Repository`
- `GH_Branch`
- `GH_Environment`
- `GH_ExternalIdentity`
- `GH_SamlIdentityProvider`

FIC collection is scoped to GitHub Actions issuers using:

```cypher
MATCH (fic:AZFederatedIdentityCredential)
WHERE fic.issuer = 'https://token.actions.githubusercontent.com'
RETURN fic
```

## Configuration

```toml
[sources.source.postprocess]
bloodhound_url = "https://example.bloodhoundenterprise.io"
bloodhound_token_id = "..."
bloodhound_token_key = "..."

# Optional
node_kinds_json = "[\"AZFederatedIdentityCredential\",\"AWS_Role\",\"GH_Organization\",\"GH_Repository\",\"GH_Branch\",\"GH_Environment\",\"GH_ExternalIdentity\",\"GH_SamlIdentityProvider\"]"
node_filters_json = "{\"AZFederatedIdentityCredential\":\"{alias}.issuer = 'https://token.actions.githubusercontent.com'\",\"AWS_Role\":\"({alias})-[:AWS_TrustsOIDCProvider]->(:AWS_OIDCProvider {url:'token.actions.githubusercontent.com'})\"}"
edge_kinds_json = "[]"
prior_derived_edge_kinds_json = "[\"OIDC_RelatedTo\"]"
kind_prefix = "OIDC_"
chunk_size = 5000
```

## OIDC Correlation

For OIDC, `convert` emits `GH_CanAssumeIdentity` edges from GitHub scope nodes
to Azure FICs or AWS roles. It does not create new nodes.

Each AZ FIC subject is parsed and then correlated against GitHub lookup tables
in DuckDB:

- exact repository subjects emit from `GH_Repository`
- exact branch subjects emit from `GH_Branch` when present
- exact environment subjects emit from `GH_Environment` when present
- wildcard branch and wildcard environment subjects fall back to
  `GH_Repository`
- wildcard repo subjects fall back to the org `owners` role, plus `members`
  when `members_can_create_repositories = true`

OIDC correlation matches GitHub resource names without regard to case:

- organization login: case-insensitive
- repository full name: case-insensitive
- environment name: case-insensitive
- branch name: case-insensitive, preferring an exact-case match when present

Immutable GitHub OIDC subjects append numeric owner and repository database IDs
to the `repo` segment (for example, `repo:org@123/app@456`). The input
`GH_Organization.database_id`, `GH_Repository.database_id`, and
`GH_Repository.owner_database_id` properties are used to validate these IDs.
Opaque `node_id`, `objectid`, and `owner_id` values remain graph identifiers and
are never decoded to derive numeric database IDs.

Repository, branch, and environment OIDC edge endpoints use the stored
BloodHound `objectid`. GitHub `node_id` values are retained as aliases for
resolving repository-owner and branch/environment-repository references.
These references are compared without regard to case, including when converting
previously collected snapshots.

For branch fallback, the repo's `default_branch` is used as a coverage signal.
If the target branch is missing and the repo does not even have its default
branch collected, the branch inventory is treated as untrustworthy and no edge
is emitted.

Unsupported AZ FIC subjects are also retained during preprocess in
`postprocess.unsupported_az_federated_identity_subjects` so you can track
coverage gaps like tags, `job_workflow_ref`, malformed subjects, and other
not-yet-modeled subject forms.

Parsed AZ FIC subjects that are intentionally suppressed because the backing
GitHub data is not trustworthy enough to emit an edge are retained in
`postprocess.suppressed_az_federated_identity_subjects`.

Common suppression reasons include:

- organization is missing or not collected
- organization wildcard is too broad to correlate safely
- branch inventory is not trustworthy for repository fallback

## Identity Correlation

For SAML, the extension uses the GitHub SAML identity provider to determine the
foreign identity provider and environment, then matches the external identity's
SAML name ID to the provider-specific user identity property. A successful
match emits a non-traversable `GH_MapsToUser` evidence edge and a composed,
traversable `GH_SyncedTo` edge from the foreign user to the GitHub user.

For SCIM users, the extension only collects active provisioning paths:

```cypher
MATCH p=(:SCIM_User {enabled:true})-[:SCIM_Provisioned]->(:GH_ExternalIdentity)-[:GH_MapsToUser]->(:GH_User)
RETURN p
```

It then matches `SCIM_User.external_id` to foreign user `objectid` values and
emits a direct `SCIM_Provisioned` edge from the foreign user to the SCIM user.
Once that direct edge exists, it also emits a composed `GH_SyncedTo` edge whose
composition query shows the full foreign user -> SCIM user -> GitHub external
identity -> GitHub user path.

For SCIM groups, the extension currently matches `SCIM_Group.external_id` only
against `AZGroup.objectid` and emits `SCIM_Provisioned` from the Azure group to
the SCIM group. It does not yet emit a GitHub team edge because the
corresponding `GH_EnterpriseTeam` relationship has not been established.

## Host Correlation

See the [Host_SameHostAs edge reference](docs/host-same-host-as.md) for matching
rules, edge directions, collection behavior, and troubleshooting.

Each rule adds one capability probe. `az_devices` collects the union of device
candidates in one paginated pass. `az_vms` collects the VM inventory when either the device resource-ID probe or
the Computer `azvmid` probe finds candidates. `computers` collects the AD computer
inventory when the device on-premises ID probe, Computer `azvmid` probe, or
Windows Okta device probe finds candidates. `okta_devices` collects the union
of enabled Windows and macOS candidates in one pass, retaining Windows devices
with a nonempty `object_sid` and macOS devices with a nonempty `udid`.
`jamf_computers` collects the Jamf inventory only when macOS Okta candidates exist. Each inventory is collected once even when multiple
rules need it. VM-to-computer correlation also works without any AZDevice nodes.

Each inventory uses pages of `chunk_size` nodes (default 5,000). An exact
multiple of the page size requires a final empty page request. Collection
retains device object IDs, extracted resource IDs, and `onpremid`; VM object IDs
and `vm_id`; computer object IDs and `azvmid`; and Okta device object IDs,
`object_sid`, `udid`, and `platform`; plus Jamf computer object IDs and `udid`. Configured node filters and the fallback collection filter
apply.

DuckDB joins each pair of inventories once during conversion and caches the
matches; there are no per-node API calls. Older snapshots without a rule's
matching properties or inventory still convert, but require a fresh collection
to produce edges for that rule.

## Pipeline

The examples below use `uv run` so the commands execute inside this project's
managed Python environment with the local extension code installed. If you are
already running inside an environment where `openhound` and this package are
installed, you can drop the `uv run` prefix.

```bash
mkdir -p ./output
uv run python -m openhound collect postprocess ./output/collected
uv run python -m openhound preprocess postprocess ./output/collected/postprocess ./output/lookup.duckdb
uv run python -m openhound convert postprocess ./output/collected/postprocess ./output/opengraph --lookup-file ./output/lookup.duckdb
```

When upgrading an existing installation, move the source settings to
`[sources.source.postprocess]` and run the pipeline with a fresh collection
and lookup database. For scheduler deployments, follow the
[Compose upgrade instructions](docker-compose/README.md).

## Containers

Production images support Linux AMD64 and ARM64:

- Scheduler: `ghcr.io/specterops/openhound-postprocess:<version>` or `:latest`
- OpenHound CLI: `ghcr.io/specterops/openhound-postprocess:<version>-cli` or `:latest-cli`

See [Docker Compose deployment](docker-compose/README.md) for configuration,
offline preflight, persistent storage, startup, and updates. Publishing a
tagged GitHub release runs tests, uploads the Python distribution to PyPI,
publishes both GHCR images, and attaches the Compose bundle.
See [Releasing](docs/releasing.md) for publisher setup and tag formats.

## Additional Documentation

- [Host_SameHostAs Edge Reference](docs/host-same-host-as.md)
- [GitHub OIDC Federation Capability Guide](docs/github-oidc-federation-capability.md)
- [GitHub SCIM Provisioning Capability Guide](docs/github-scim-provisioning-capability.md)
