# spiffe/spire-identity-exchange architecture

> Architecture diagram of the GitHub repository spiffe/spire-identity-exchange, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/spiffe/spire-identity-exchange
- Repository: https://github.com/spiffe/spire-identity-exchange

## Overview

spire-identity-exchange exchanges platform-native workload tokens for SPIRE-issued SVIDs: a workload submits a token, the service validates it and derives selectors, then the SPIRE Agent’s Delegated Identity API matches those selectors to registration entries and returns an SVID. The graph preserves the documented GitHub, GitLab, Kubernetes, and SPIFFE validators, plus stack composition and the legacy template-based path. Edges reflect README statements and source-index references or shown calls; several internal dispatch details are unsampled, so they are not expanded into speculative links.

Main entry points: [`internal/service/runner.go`](https://github.com/spiffe/spire-identity-exchange/blob/main/internal/service/runner.go) (Service runner), [`pkg/validator/registry/registry.go`](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/registry/registry.go) (Plugin registry), [`pkg/validator/stack/validator.go`](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/stack/validator.go) (Stack validator), [`pkg/validator/jwt/validator.go`](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/jwt/validator.go) (JWT validation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_service["Exchange service"]
  node_api["Exchange API"]
  node_runner["Service runner<br/>[runner.go]"]
  node_mint["SVID minting<br/>[mintcertificate.go]"]
  node_legacy_mint["Legacy minting"]
  node_agent["SPIRE Agent"]
  node_template["SPIFFE templates<br/>[template.go]"]
end

subgraph group_plugins["Identity validators"]
  node_github["GitHub OIDC<br/>[validator.go]"]
  node_gitlab["GitLab OIDC<br/>[validator.go]"]
  node_k8s["Kubernetes PSAT<br/>[validator.go]"]
  node_token_review["K8s TokenReview<br/>[tokenreview.go]"]
  node_spiffe["SPIFFE SVID<br/>[validator.go]"]
  node_github_legacy["Legacy GitHub<br/>[validator.go]"]
  node_k8s_legacy["Legacy K8s<br/>[validator.go]"]
end

subgraph group_validation["Validation framework"]
  node_registry["Plugin registry<br/>[registry.go]"]
  node_stack["Stack validator<br/>[validator.go]"]
  node_jwt["JWT validation<br/>[validator.go]"]
  node_keyprovider["JWT key providers<br/>[keyprovider.go]"]
  node_replay["Replay checking<br/>[validator.go]"]
end

subgraph group_operations["Operations"]
  node_config["Configuration<br/>[config.go]"]
  node_metrics["Prometheus metrics<br/>[server.go]"]
end

node_workload(("Workload"))
node_svid["Issued SVID"]

node_workload -->|"submits token"| node_api
node_api -.->|"routes requests"| node_runner
node_runner -->|"loads settings"| node_config
node_runner -->|"serves mint requests"| node_mint
node_mint -->|"requests SVID"| node_agent
node_agent -->|"issues SVID"| node_svid
node_svid -->|"returns SVID"| node_workload
node_runner -->|"loads plugins"| node_registry
node_registry -->|"registers"| node_github
node_registry -->|"registers"| node_gitlab
node_registry -->|"registers"| node_k8s
node_registry -->|"registers"| node_spiffe
node_runner -->|"configures stacks"| node_stack
node_stack -.->|"validates member tokens"| node_github
node_stack -.->|"validates member tokens"| node_gitlab
node_stack -.->|"validates member tokens"| node_k8s
node_github -->|"validates JWTs"| node_jwt
node_gitlab -->|"validates JWTs"| node_jwt
node_spiffe -->|"validates JWTs"| node_jwt
node_jwt -->|"gets verification keys"| node_keyprovider
node_k8s -->|"authenticates tokens"| node_token_review
node_runner -->|"initializes legacy auth"| node_github_legacy
node_runner -->|"initializes legacy auth"| node_k8s_legacy
node_github_legacy -->|"wraps validator"| node_replay
node_legacy_mint -->|"derives identity"| node_template
node_runner -->|"starts metrics"| node_metrics

click node_api "https://github.com/spiffe/spire-identity-exchange/blob/main/api/SpireIdentityExchangeApi.proto"
click node_runner "https://github.com/spiffe/spire-identity-exchange/blob/main/internal/service/runner.go"
click node_mint "https://github.com/spiffe/spire-identity-exchange/blob/main/internal/service/mintcertificate.go"
click node_legacy_mint "https://github.com/spiffe/spire-identity-exchange/blob/main/internal/service/mintcertificate_legacy.go"
click node_github "https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/github/validator.go"
click node_gitlab "https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/gitlab/validator.go"
click node_k8s "https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/k8s/validator.go"
click node_token_review "https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/k8s/tokenreview.go"
click node_spiffe "https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/spiffe/validator.go"
click node_github_legacy "https://github.com/spiffe/spire-identity-exchange/blob/main/internal/github-oidc/validator.go"
click node_k8s_legacy "https://github.com/spiffe/spire-identity-exchange/blob/main/internal/k8s-sa-token/validator.go"
click node_registry "https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/registry/registry.go"
click node_stack "https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/stack/validator.go"
click node_jwt "https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/jwt/validator.go"
click node_keyprovider "https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/jwt/keyprovider.go"
click node_replay "https://github.com/spiffe/spire-identity-exchange/blob/main/internal/cache/validator.go"
click node_config "https://github.com/spiffe/spire-identity-exchange/blob/main/internal/config/config.go"
click node_metrics "https://github.com/spiffe/spire-identity-exchange/blob/main/internal/metrics/prometheus/server.go"
click node_template "https://github.com/spiffe/spire-identity-exchange/blob/main/internal/utils/template.go"

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_api,node_runner,node_mint,node_legacy_mint,node_agent,node_template toneBlue
class node_github,node_gitlab,node_k8s,node_token_review,node_spiffe,node_github_legacy,node_k8s_legacy toneAmber
class node_registry,node_stack,node_jwt,node_keyprovider,node_replay toneMint
class node_config,node_metrics toneRose
class node_workload,node_svid toneIndigo
```

## Components

### Exchange service

- [Exchange API](https://github.com/spiffe/spire-identity-exchange/blob/main/api/SpireIdentityExchangeApi.proto): `api/SpireIdentityExchangeApi.proto`
- [Service runner](https://github.com/spiffe/spire-identity-exchange/blob/main/internal/service/runner.go): `internal/service/runner.go`
- [SVID minting](https://github.com/spiffe/spire-identity-exchange/blob/main/internal/service/mintcertificate.go): `internal/service/mintcertificate.go`
- [Legacy minting](https://github.com/spiffe/spire-identity-exchange/blob/main/internal/service/mintcertificate_legacy.go): `internal/service/mintcertificate_legacy.go`
- **SPIRE Agent**
- [SPIFFE templates](https://github.com/spiffe/spire-identity-exchange/blob/main/internal/utils/template.go): `internal/utils/template.go`

### Identity validators

- [GitHub OIDC](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/github/validator.go): `pkg/validator/github/validator.go`
- [GitLab OIDC](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/gitlab/validator.go): `pkg/validator/gitlab/validator.go`
- [Kubernetes PSAT](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/k8s/validator.go): `pkg/validator/k8s/validator.go`
- [K8s TokenReview](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/k8s/tokenreview.go): `pkg/validator/k8s/tokenreview.go`
- [SPIFFE SVID](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/spiffe/validator.go): `pkg/validator/spiffe/validator.go`
- [Legacy GitHub](https://github.com/spiffe/spire-identity-exchange/blob/main/internal/github-oidc/validator.go): `internal/github-oidc/validator.go`
- [Legacy K8s](https://github.com/spiffe/spire-identity-exchange/blob/main/internal/k8s-sa-token/validator.go): `internal/k8s-sa-token/validator.go`

### Validation framework

- [Plugin registry](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/registry/registry.go): `pkg/validator/registry/registry.go`
- [Stack validator](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/stack/validator.go): `pkg/validator/stack/validator.go`
- [JWT validation](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/jwt/validator.go): `pkg/validator/jwt/validator.go`
- [JWT key providers](https://github.com/spiffe/spire-identity-exchange/blob/main/pkg/validator/jwt/keyprovider.go): `pkg/validator/jwt/keyprovider.go`
- [Replay checking](https://github.com/spiffe/spire-identity-exchange/blob/main/internal/cache/validator.go): `internal/cache/validator.go`

### Operations

- [Configuration](https://github.com/spiffe/spire-identity-exchange/blob/main/internal/config/config.go): `internal/config/config.go`
- [Prometheus metrics](https://github.com/spiffe/spire-identity-exchange/blob/main/internal/metrics/prometheus/server.go): `internal/metrics/prometheus/server.go`

### Other components

- **Workload**
- **Issued SVID**

## Connections

- Workload → Exchange API: submits token (evidence: `README.md`)
- Exchange API → Service runner: routes requests
- Service runner → Configuration: loads settings
- Service runner → SVID minting: serves mint requests (evidence: `internal/service/runner.go`)
- SVID minting → SPIRE Agent: requests SVID (evidence: `README.md`)
- SPIRE Agent → Issued SVID: issues SVID (evidence: `README.md`)
- Issued SVID → Workload: returns SVID (evidence: `README.md`)
- Service runner → Plugin registry: loads plugins
- Plugin registry → GitHub OIDC: registers (evidence: `pkg/validator/registry/registry.go`)
- Plugin registry → GitLab OIDC: registers (evidence: `pkg/validator/registry/registry.go`)
- Plugin registry → Kubernetes PSAT: registers (evidence: `pkg/validator/registry/registry.go`)
- Plugin registry → SPIFFE SVID: registers (evidence: `pkg/validator/registry/registry.go`)
- Service runner → Stack validator: configures stacks
- Stack validator → GitHub OIDC: validates member tokens
- Stack validator → GitLab OIDC: validates member tokens
- Stack validator → Kubernetes PSAT: validates member tokens
- GitHub OIDC → JWT validation: validates JWTs (evidence: `pkg/validator/github/validator.go`)
- GitLab OIDC → JWT validation: validates JWTs (evidence: `pkg/validator/gitlab/validator.go`)
- SPIFFE SVID → JWT validation: validates JWTs (evidence: `pkg/validator/spiffe/validator.go`)
- JWT validation → JWT key providers: gets verification keys (evidence: `pkg/validator/jwt/validator.go`)
- Kubernetes PSAT → K8s TokenReview: authenticates tokens (evidence: `pkg/validator/k8s/validator.go`)
- Service runner → Legacy GitHub: initializes legacy auth
- Service runner → Legacy K8s: initializes legacy auth
- Legacy GitHub → Replay checking: wraps validator
- Legacy minting → SPIFFE templates: derives identity (evidence: `internal/service/mintcertificate_legacy.go`)
- Service runner → Prometheus metrics: starts metrics
