# paloaltonetworks/a3s architecture

> Architecture diagram of the GitHub repository paloaltonetworks/a3s, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/paloaltonetworks/a3s
- Repository: https://github.com/paloaltonetworks/a3s

## Overview

##### Project type and purpose
- A3S (“Auth As A Service”) is a backend‐focused full-stack authentication and ABAC authorization server written in Go.
- It provides:
- A RESTful HTTP API (cmd/a3s)
- A CLI client “a3sctl” (cmd/a3sctl)
- A small web-based login UI (internal/ui/js/login)
- Support for multiple external authentication sources (MTLS, LDAP, HTTP, OIDC, AWS, GCP, Azure, remote A3S)
- Policy and namespace management, backed by MongoDB and a NATS push channel

##### High-level components
- Client tier
- a3sctl CLI (Go binary)
- Web UI (static JS/TS served by the server)
- Example apps (Python “testapp”, “httpsource”, “claimmod”)
- API server (cmd/a3s)
- HTTP(S) API endpoints
- Bootstrap & runtime initialization (pkgs/bootstrap)
- Request routing and handlers (pkgs/api)
- Core processors (internal/processors) implementing authentication, authorization, import, etc.
- Issuer implementations (internal/issuer/*) for each source type
- Identity modifiers (internal/identitymodifier)
- JWT/token management (pkgs/token)
- Persistence via MongoDB (pkgs/crud, pkgs/indexes)
- Pub/Sub via NATS for cache invalidation and push notifications (pkgs/notification, pkgs/push)
- Data stores
- MongoDB for all metadata (namespaces, sources, authorizations, import labels)
- In-memory or file-based caches for OIDC state (internal/oidcceremony) and namespace trees (pkgs/nscache)
- External services
- LDAP servers
- OIDC providers
- Your own HTTP authentication endpoint
- Remote A3S instances
- Cloud metadata services (AWS, GCP, Azure)

##### Relationships and data flows
- Authentication flow
1. Client (a3sctl / UI) calls “/auth/{source}” on A3S over HTTPS
2. API handler dispatches to the appropriate issuer in internal/issuer
3. If configured, calls identity modifier (HTTP callback)
4. Assembles claims and signs a JWT (pkgs/token)
5. Returns identity token to client
- Authorization check
1. Client presents JWT to A3S “/authz” endpoint or validates locally
2. Server retrieves policies (internal/processors/authorizations.go) and computes effective permissions using authorizer (pkgs/authorizer)
3. Optionally pushes cache invalidation messages to NATS for connected apps
- Management API and CLI
- a3sctl uses the same REST API to create namespaces, sources, authorizations and perform imports
- Pub/Sub and caching
- Server publishes change events (pkgs/push) on NATS so that clients or dashboards can invalidate or update permission caches

##### Architectural patterns and principles
- Layered architecture: bootstrap → API routing → processors → business-logic packages → datastore
- Plugin-style issuers: each auth source is a separate module implementing a common interface (internal/issuer)
- Declarative import & reconciliation (pkgs/api/import.go)

##### Final checklist
- Clear separation of client, server core, storage, external systems
- Groupings or containers to convey modular layering
- Notes on key design patterns: plugin issuers, layered processing, declarative import

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients
    subgraph "Clients"
        CLI["CLI Client (a3sctl)"]:::client
        WebUI["Web Login UI"]:::client
        TestApp["Example Apps"]:::client
    end

    %% Server Core
    subgraph "A3S Server"
        subgraph "Bootstrap & HTTP Server"
            Bootstrap["Bootstrap & Runtime Init"]:::server
        end
        subgraph "API Layer"
            API["Routing & Handlers"]:::server
        end
        subgraph "Processors"
            Processors["Core Processors"]:::server
        end
        Token["Token Manager"]:::server
    end

    %% Internal Packages
    subgraph "Internal Packages"
        Issuers["Auth Sources (Issuers)"]:::external
        IdentityMod["Identity Modifiers"]:::server
        Authorizer["Policy Authorizer"]:::server
        CRUD["CRUD & Indexes"]:::server
        CacheNS["Namespace Cache"]:::server
        PubSub["NATS Pub/Sub"]:::server
        OIDCCeremony["OIDC State Ceremony"]:::server
    end

    %% Data Stores
    subgraph "Data Stores"
        Mongo["MongoDB"]:::db
        NATS["NATS"]:::db
    end

    %% External Auth Systems
    subgraph "External Auth Systems"
        LDAP["LDAP"]:::external
        OIDC["OIDC"]:::external
        HTTPAuth["HTTP Auth"]:::external
        RemoteA3S["Remote A3S"]:::external
        Cloud["Cloud Metadata"]:::external
    end

    %% Relationships
    CLI -->|HTTPS REST| API
    WebUI -->|HTTPS REST| API
    TestApp -->|HTTPS REST| API
    API -->|"initialize"| Bootstrap
    Bootstrap --> API
    API -->|"dispatch"| Processors
    Processors -->|"use issuers"| Issuers
    Issuers -->|TLS/LDAP/HTTP/OIDC| LDAP
    Issuers -->|OIDC| OIDC
    Issuers -->|HTTP| HTTPAuth
    Issuers -->|A3S| RemoteA3S
    Issuers -->|Cloud STS| Cloud
    Processors -->|"modify identity"| IdentityMod
    Processors -->|"authorize"| Authorizer
    Processors -->|"persist"| CRUD
    CRUD -->|read/write| Mongo
    API -->|"sign tokens"| Token
    API -->|"publish events"| PubSub
    PubSub -->|pub/sub| NATS
    NATS -->|push invalidation| CLI
    NATS -->|push invalidation| WebUI
    NATS -->|push invalidation| TestApp
    Processors -->|"OIDC state"| OIDCCeremony
    Processors -->|"namespace cache"| CacheNS
    CacheNS -->|in-memory| API

    %% Click Events
    click API "https://github.com/paloaltonetworks/a3s/blob/master/cmd/a3s/main.go"
    click API "https://github.com/paloaltonetworks/a3s/blob/master/cmd/a3s/conf.go"
    click API "https://github.com/paloaltonetworks/a3s/blob/master/cmd/a3s/fips.go"
    click CLI "https://github.com/paloaltonetworks/a3s/blob/master/cmd/a3sctl/main.go"
    click CLI "https://github.com/paloaltonetworks/a3s/tree/master/cmd/a3sctl/internal"
    click WebUI "https://github.com/paloaltonetworks/a3s/tree/master/internal/ui/js/login"
    click Bootstrap "https://github.com/paloaltonetworks/a3s/tree/master/pkgs/bootstrap"
    click API "https://github.com/paloaltonetworks/a3s/tree/master/pkgs/api"
    click Processors "https://github.com/paloaltonetworks/a3s/tree/master/internal/processors"
    click Issuers "https://github.com/paloaltonetworks/a3s/tree/master/internal/issuer"
    click IdentityMod "https://github.com/paloaltonetworks/a3s/tree/master/internal/identitymodifier"
    click OIDCCeremony "https://github.com/paloaltonetworks/a3s/tree/master/internal/oidcceremony"
    click Token "https://github.com/paloaltonetworks/a3s/tree/master/pkgs/token"
    click CRUD "https://github.com/paloaltonetworks/a3s/tree/master/pkgs/crud"
    click CRUD "https://github.com/paloaltonetworks/a3s/tree/master/pkgs/indexes"
    click PubSub "https://github.com/paloaltonetworks/a3s/tree/master/pkgs/push"
    click PubSub "https://github.com/paloaltonetworks/a3s/tree/master/pkgs/notification"
    click CacheNS "https://github.com/paloaltonetworks/a3s/tree/master/pkgs/nscache"
    click Authorizer "https://github.com/paloaltonetworks/a3s/tree/master/pkgs/authorizer"
    click TestApp "https://github.com/paloaltonetworks/a3s/tree/master/examples/python"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:1px,shape:parallelogram
    classDef server fill:#bbf,stroke:#333,stroke-width:1px
    classDef db fill:#bfb,stroke:#333,stroke-width:1px,shape:cylinder
    classDef external fill:#f96,stroke:#333,stroke-width:1px
```
