# yaelitrovnik/storagegrid-usage-proxy architecture

> Architecture diagram of the GitHub repository yaelitrovnik/storagegrid-usage-proxy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yaelitrovnik/storagegrid-usage-proxy
- Repository: https://github.com/yaelitrovnik/storagegrid-usage-proxy

## Overview

#### Purpose and entry points

StorageGRID Usage Proxy is a long-running Python HTTP proxy for a closed-network Splunk/HTTP-SNIFFER gateway. It exposes a stable local usage endpoint while managing StorageGRID Tenant API bearer tokens only in process memory.

Primary application entry point: `storagegrid_usage_proxy.py`. Container/runtime entry points are defined by `Dockerfile`, `compose.yml`, and host lifecycle scripts such as `scripts/start.sh`.

#### Request-facing proxy boundary

The proxy serves:
- `GET /storagegrid/usage` for HTTP-SNIFFER, protected by `X-StorageGRID-Proxy-Key`
- `GET /healthz` for process liveness
- `GET /readyz` for token-backed operational readiness

The proxy is the boundary between a locally shared API key and upstream bearer authentication. Production listener exposure and security settings are supplied through `compose.yml` and `config/proxy.env`; certificates are mounted from `certs/`.

Relevant paths: `storagegrid_usage_proxy.py`, `compose.yml`, `config/proxy.env`.

#### StorageGRID authorization lifecycle

The application authenticates to the StorageGRID Tenant API via `POST /api/v4/authorize`, validates candidate tokens using `GET /api/v4/org/usage`, and activates only validated tokens. Tokens remain RAM-resident and are periodically refreshed.

On scheduled refresh failure, the previous working token remains active. If an upstream usage request returns HTTP 401, the proxy reauthorizes and retries once. This isolates HTTP-SNIFFER from token rotation and avoids changing its configuration or restarting it.

Relevant path: `storagegrid_usage_proxy.py`.

#### Usage retrieval flow

Control flow is:

HTTP-SNIFFER → authenticated local `/storagegrid/usage` → proxy token state → StorageGRID `/api/v4/org/usage` → returned usage JSON → HTTP-SNIFFER/Splunk.

The upstream TLS boundary is configured with `TLS_VERIFY` and an optional CA bundle. In production, Compose maps the host certificate directory read-only into the container at `/app/certs`.

Relevant paths: `storagegrid_usage_proxy.py`, `compose.yml`, `certs/.keep`.

#### Deployment and runtime model

Docker Compose is the recommended production runtime, intended for offline deployment: a versioned image TAR and SHA256 are transferred to the closed-network host, loaded locally, then started with Compose. The container uses restart policy rather than relying on Docker health status to restart an unhealthy-but-running process.

Development and direct-host operations are supported through setup, run, status, and autostart scripts.

Relevant paths: `Dockerfile`, `compose.yml`, `scripts/setup.sh`, `scripts/run.sh`, `scripts/install-autostart.sh`.

#### Release and supply-chain flow

`TAG` is the release-version source. CI builds versioned and `latest` images, exports an offline Docker archive, and produces a checksum for controlled transfer. Both GitHub Actions and GitLab CI paths exist, with image packaging scripts shared around the same offline distribution model.

Relevant paths: `TAG`, `.github/workflows/build-offline-image.yml`, `.github/scripts/export-offline-image.sh`, `.gitlab-ci.yml`, `.gitlab-ci-cd/package-docker-offline.sh`.

#### Operational boundaries

Persistent host-side state is intentionally limited to deployment configuration, trusted CA material, logs, and runtime artifacts; bearer tokens are excluded from files and environment mutation at runtime. Environment validation and upstream connectivity checks are explicit operational gates before service use.

Relevant paths: `config/proxy.env`, `scripts/check-config.sh`, `scripts/test-upstream.sh`, `logs/.keep`, `runtime/.keep`.

Main entry points: [`storagegrid_usage_proxy.py`](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py) (Usage Proxy), [`Dockerfile`](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/Dockerfile) (Offline container image), [`.github/scripts/export-offline-image.sh`](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/.github/scripts/export-offline-image.sh) (Image archive and checksum), [`scripts/check-config.sh`](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/scripts/check-config.sh) (Operational gates)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Proxy Runtime"]
  node_sniffer["HTTP-SNIFFER / Splunk<br/>consumer"]
  node_proxy["Usage Proxy<br/>Python service"]
  node_usage_endpoint["GET /storagegrid/usage<br/>protected endpoint"]
  node_health_endpoints["Health and readiness<br/>endpoints"]
  node_token_lifecycle["Token lifecycle<br/>in-memory state"]
  node_tenant_auth{{"Tenant authorize API<br/>upstream API"}}
  node_tenant_usage{{"Tenant usage API<br/>upstream API"}}
end

subgraph group_deployment["Deployment"]
  node_compose["Docker Compose<br/>runtime definition<br/>[compose.yml]"]
  node_proxy_env["Proxy environment<br/>deployment config<br/>[proxy.env]"]
  node_certs["Trusted certificates<br/>CA material<br/>[.keep]"]
  node_container_image["Offline container image<br/>Docker image TAR"]
  node_host_scripts["Host operations<br/>lifecycle scripts<br/>[setup.sh]"]
  node_operational_gates["Operational gates<br/>validation scripts<br/>[check-config.sh]"]
  node_host_state["Host runtime state<br/>persistent directories<br/>[.keep]"]
end

subgraph group_release["Release Pipeline"]
  node_release_tag["Release TAG<br/>version source"]
  node_github_build["GitHub offline build<br/>CI workflow"]
  node_gitlab_build["GitLab offline package<br/>CI pipeline<br/>[.gitlab-ci.yml]"]
  node_image_export["Image archive and checksum<br/>release artifact"]
end

node_sniffer -->|"GET with proxy key"| node_usage_endpoint
node_usage_endpoint -->|"handled by"| node_proxy
node_proxy -->|"serves"| node_health_endpoints
node_proxy -->|"uses"| node_token_lifecycle
node_token_lifecycle -->|"authorize / reauthorize"| node_tenant_auth
node_token_lifecycle -->|"validate candidate token"| node_tenant_usage
node_proxy -->|"fetch usage; retry once on 401"| node_tenant_usage
node_tenant_usage -->|"usage JSON via proxy"| node_sniffer
node_proxy_env -->|"listener and TLS settings"| node_proxy
node_certs -->|"read-only mount"| node_compose
node_compose -->|"runs"| node_container_image
node_container_image -->|"contains"| node_proxy
node_host_scripts -.->|"direct-host lifecycle"| node_proxy
node_operational_gates -->|"validate"| node_proxy_env
node_operational_gates -.->|"connectivity check"| node_tenant_usage
node_proxy -->|"writes logs/runtime artifacts"| node_host_state
node_release_tag -->|"versions"| node_github_build
node_release_tag -->|"versions"| node_gitlab_build
node_github_build -->|"produces"| node_image_export
node_gitlab_build -->|"packages"| node_image_export
node_image_export -->|"transferred and loaded offline"| node_container_image

click node_proxy "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py"
click node_usage_endpoint "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py"
click node_health_endpoints "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py"
click node_token_lifecycle "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py"
click node_tenant_auth "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py"
click node_tenant_usage "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py"
click node_compose "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/compose.yml"
click node_proxy_env "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/config/proxy.env"
click node_certs "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/certs/.keep"
click node_container_image "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/Dockerfile"
click node_host_scripts "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/scripts/setup.sh"
click node_operational_gates "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/scripts/check-config.sh"
click node_host_state "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/logs/.keep"
click node_release_tag "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/TAG"
click node_github_build "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/.github/workflows/build-offline-image.yml"
click node_gitlab_build "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/.gitlab-ci.yml"
click node_image_export "https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/.github/scripts/export-offline-image.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_sniffer,node_proxy,node_usage_endpoint,node_health_endpoints,node_token_lifecycle,node_tenant_auth,node_tenant_usage toneBlue
class node_compose,node_proxy_env,node_certs,node_container_image,node_host_scripts,node_operational_gates,node_host_state toneAmber
class node_release_tag,node_github_build,node_gitlab_build,node_image_export toneMint
```

## Components

### Proxy Runtime

Local authenticated usage boundary and token lifecycle.

- **HTTP-SNIFFER / Splunk**: consumer · Consumes the stable local usage endpoint.
- [Usage Proxy](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py): Python service · Long-running local proxy with RAM-only bearer token state. · `storagegrid_usage_proxy.py`
- [GET /storagegrid/usage](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py): protected endpoint · Requires X-StorageGRID-Proxy-Key. · `storagegrid_usage_proxy.py`
- [Health and readiness](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py): endpoints · Provides /healthz and token-backed /readyz. · `storagegrid_usage_proxy.py`
- [Token lifecycle](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py): in-memory state · Authorizes, validates, refreshes, and retains the last working token. · `storagegrid_usage_proxy.py`
- [Tenant authorize API](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py): upstream API · POST /api/v4/authorize issues bearer tokens. · `storagegrid_usage_proxy.py`
- [Tenant usage API](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/storagegrid_usage_proxy.py): upstream API · GET /api/v4/org/usage validates tokens and supplies usage JSON. · `storagegrid_usage_proxy.py`

### Deployment

Offline container and host operation model.

- [Docker Compose](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/compose.yml): runtime definition · Supplies listener exposure, security settings, restart policy, and certificate mount. · `compose.yml`
- [Proxy environment](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/config/proxy.env): deployment config · Provides production settings including TLS verification. · `config/proxy.env`
- [Trusted certificates](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/certs/.keep): CA material · Mounted read-only at /app/certs when needed. · `certs/.keep`
- [Offline container image](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/Dockerfile): Docker image TAR · Loaded on the closed-network host before Compose starts it. · `Dockerfile`
- [Host operations](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/scripts/setup.sh): lifecycle scripts · Supports setup, direct run, and autostart installation. · `scripts/setup.sh`
- [Operational gates](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/scripts/check-config.sh): validation scripts · Validates environment and upstream connectivity before use. · `scripts/check-config.sh`
- [Host runtime state](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/logs/.keep): persistent directories · Limited to logs and runtime artifacts; tokens are never persisted. · `logs/.keep`

### Release Pipeline

Versioned offline image production.

- [Release TAG](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/TAG): version source · Source version for release images. · `TAG`
- [GitHub offline build](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/.github/workflows/build-offline-image.yml): CI workflow · Builds images and exports the offline archive. · `.github/workflows/build-offline-image.yml`
- [GitLab offline package](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/.gitlab-ci.yml): CI pipeline · Alternative CI path for the same offline distribution model. · `.gitlab-ci.yml`
- [Image archive and checksum](https://github.com/yaelitrovnik/storagegrid-usage-proxy/blob/master/.github/scripts/export-offline-image.sh): release artifact · Controlled-transfer package for disconnected hosts. · `.github/scripts/export-offline-image.sh`

## Connections

- HTTP-SNIFFER / Splunk → GET /storagegrid/usage: GET with proxy key
- GET /storagegrid/usage → Usage Proxy: handled by
- Usage Proxy → Health and readiness: serves
- Usage Proxy → Token lifecycle: uses
- Token lifecycle → Tenant authorize API: authorize / reauthorize
- Token lifecycle → Tenant usage API: validate candidate token
- Usage Proxy → Tenant usage API: fetch usage; retry once on 401
- Tenant usage API → HTTP-SNIFFER / Splunk: usage JSON via proxy
- Proxy environment → Usage Proxy: listener and TLS settings
- Trusted certificates → Docker Compose: read-only mount
- Docker Compose → Offline container image: runs
- Offline container image → Usage Proxy: contains
- Host operations → Usage Proxy: direct-host lifecycle
- Operational gates → Proxy environment: validate
- Operational gates → Tenant usage API: connectivity check
- Usage Proxy → Host runtime state: writes logs/runtime artifacts
- Release TAG → GitHub offline build: versions
- Release TAG → GitLab offline package: versions
- GitHub offline build → Image archive and checksum: produces
- GitLab offline package → Image archive and checksum: packages
- Image archive and checksum → Offline container image: transferred and loaded offline
