# azure/kubelogin architecture

> Architecture diagram of the GitHub repository azure/kubelogin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azure/kubelogin
- Repository: https://github.com/azure/kubelogin

## Overview

kubelogin is a Kubernetes client-go exec credential plugin for Azure authentication. Its principal workflow is invoked by kubectl, runs the plugin command to obtain credentials, and returns an exec-plugin credential result; it also converts existing kubeconfigs and exposes token-provider and Proof-of-Possession (PoP) library functionality. The tree documents multiple Azure login modes, while sampled source confirms conversion, options, token-provider, and PoP/cache components. Links to unsampled credential implementations are omitted where call ownership is not shown.

Main entry points: [`pkg/internal/token/options.go`](https://github.com/azure/kubelogin/blob/main/pkg/internal/token/options.go) (Authentication options), [`pkg/internal/token`](https://github.com/azure/kubelogin/tree/main/pkg/internal/token) (Credential providers), [`pkg/cmd`](https://github.com/azure/kubelogin/tree/main/pkg/cmd) (CLI commands), [`pkg/internal/pop/poptoken.go`](https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/poptoken.go) (PoP token acquisition)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Command interface"]
  node_main["CLI entry point<br/>[main.go]"]
  node_commands["CLI commands"]
  node_gettoken["Get-token command<br/>[token.go]"]
  node_remove_cache["Cache removal<br/>[removecachedir.go]"]
end

subgraph group_auth["Azure authentication"]
  node_options["Authentication options<br/>[options.go]"]
  node_env["Environment settings<br/>[variables.go]"]
  node_credentials["Credential providers"]
  node_exec_plugin["Exec credential output"]
end

subgraph group_conversion["Kubeconfig conversion"]
  node_converter_cmd["Convert command<br/>[convert.go]"]
  node_converter["Kubeconfig conversion<br/>[convert.go]"]
end

subgraph group_pop["PoP and cache"]
  node_pop_tokens["PoP token acquisition<br/>[poptoken.go]"]
  node_pop_cache["PoP cache<br/>[cache.go]"]
  node_linux_cache["Linux cache storage<br/>[linux.go]"]
  node_jwe["JWE encryption<br/>[jwe.go]"]
  node_aescbc["AES-CBC encryption<br/>[aescbc.go]"]
end

subgraph group_library["Public libraries"]
  node_token_provider["Public token provider<br/>[provider.go]"]
  node_public_options["Public token options<br/>[options_ctor.go]"]
  node_pop_api["Public PoP API<br/>[poptoken.go]"]
end

node_kubectl(("kubectl client"))
node_azure(("Azure identity service"))

node_kubectl -->|"invokes plugin"| node_main
node_main -->|"executes root command"| node_commands
node_commands -.->|"dispatches command"| node_gettoken
node_commands -.->|"dispatches command"| node_converter_cmd
node_converter_cmd -->|"calls conversion"| node_converter
node_converter -->|"uses token options"| node_options
node_gettoken -->|"uses token package"| node_credentials
node_credentials -.->|"produces exec credentials"| node_exec_plugin
node_options -->|"reads settings"| node_env
node_options -->|"configures PoP cache"| node_pop_cache
node_options -->|"uses PoP support"| node_pop_tokens
node_credentials -.->|"requests Azure tokens"| node_azure
node_public_options -->|"converts options"| node_options
node_token_provider -->|"creates credential"| node_credentials
node_pop_api -->|"delegates acquisition"| node_pop_tokens
node_pop_tokens -->|"uses cache"| node_pop_cache
node_linux_cache -->|"encrypts cache data"| node_jwe
node_jwe -->|"uses encryption"| node_aescbc

click node_main "https://github.com/azure/kubelogin/blob/main/main.go"
click node_commands "https://github.com/azure/kubelogin/tree/main/pkg/cmd"
click node_gettoken "https://github.com/azure/kubelogin/blob/main/pkg/cmd/token.go"
click node_remove_cache "https://github.com/azure/kubelogin/blob/main/pkg/cmd/removecachedir.go"
click node_converter_cmd "https://github.com/azure/kubelogin/blob/main/pkg/cmd/convert.go"
click node_converter "https://github.com/azure/kubelogin/blob/main/pkg/internal/converter/convert.go"
click node_options "https://github.com/azure/kubelogin/blob/main/pkg/internal/token/options.go"
click node_env "https://github.com/azure/kubelogin/blob/main/pkg/internal/env/variables.go"
click node_credentials "https://github.com/azure/kubelogin/tree/main/pkg/internal/token"
click node_exec_plugin "https://github.com/azure/kubelogin/blob/main/pkg/internal/token/execCredentialPlugin.go"
click node_token_provider "https://github.com/azure/kubelogin/blob/main/pkg/token/provider.go"
click node_public_options "https://github.com/azure/kubelogin/blob/main/pkg/token/options_ctor.go"
click node_pop_api "https://github.com/azure/kubelogin/blob/main/pkg/pop/poptoken.go"
click node_pop_tokens "https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/poptoken.go"
click node_pop_cache "https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/cache/cache.go"
click node_linux_cache "https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/cache/linux.go"
click node_jwe "https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/cache/internal/jwe/jwe.go"
click node_aescbc "https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/cache/internal/aescbc/aescbc.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_main,node_commands,node_gettoken,node_remove_cache,node_kubectl toneBlue
class node_options,node_env,node_credentials,node_exec_plugin toneAmber
class node_converter_cmd,node_converter toneMint
class node_pop_tokens,node_pop_cache,node_linux_cache,node_jwe,node_aescbc toneRose
class node_token_provider,node_public_options,node_pop_api,node_azure toneIndigo
```

## Components

### Command interface

- [CLI entry point](https://github.com/azure/kubelogin/blob/main/main.go): `main.go`
- [CLI commands](https://github.com/azure/kubelogin/tree/main/pkg/cmd): `pkg/cmd`
- [Get-token command](https://github.com/azure/kubelogin/blob/main/pkg/cmd/token.go): `pkg/cmd/token.go`
- [Cache removal](https://github.com/azure/kubelogin/blob/main/pkg/cmd/removecachedir.go): `pkg/cmd/removecachedir.go`

### Azure authentication

- [Authentication options](https://github.com/azure/kubelogin/blob/main/pkg/internal/token/options.go): `pkg/internal/token/options.go`
- [Environment settings](https://github.com/azure/kubelogin/blob/main/pkg/internal/env/variables.go): `pkg/internal/env/variables.go`
- [Credential providers](https://github.com/azure/kubelogin/tree/main/pkg/internal/token): `pkg/internal/token`
- [Exec credential output](https://github.com/azure/kubelogin/blob/main/pkg/internal/token/execCredentialPlugin.go): `pkg/internal/token/execCredentialPlugin.go`

### Kubeconfig conversion

- [Convert command](https://github.com/azure/kubelogin/blob/main/pkg/cmd/convert.go): `pkg/cmd/convert.go`
- [Kubeconfig conversion](https://github.com/azure/kubelogin/blob/main/pkg/internal/converter/convert.go): `pkg/internal/converter/convert.go`

### PoP and cache

- [PoP token acquisition](https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/poptoken.go): `pkg/internal/pop/poptoken.go`
- [PoP cache](https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/cache/cache.go): `pkg/internal/pop/cache/cache.go`
- [Linux cache storage](https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/cache/linux.go): `pkg/internal/pop/cache/linux.go`
- [JWE encryption](https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/cache/internal/jwe/jwe.go): `pkg/internal/pop/cache/internal/jwe/jwe.go`
- [AES-CBC encryption](https://github.com/azure/kubelogin/blob/main/pkg/internal/pop/cache/internal/aescbc/aescbc.go): `pkg/internal/pop/cache/internal/aescbc/aescbc.go`

### Public libraries

- [Public token provider](https://github.com/azure/kubelogin/blob/main/pkg/token/provider.go): `pkg/token/provider.go`
- [Public token options](https://github.com/azure/kubelogin/blob/main/pkg/token/options_ctor.go): `pkg/token/options_ctor.go`
- [Public PoP API](https://github.com/azure/kubelogin/blob/main/pkg/pop/poptoken.go): `pkg/pop/poptoken.go`

### Other components

- **kubectl client**
- **Azure identity service**

## Connections

- kubectl client → CLI entry point: invokes plugin (evidence: `README.md`)
- CLI entry point → CLI commands: executes root command (evidence: `main.go`)
- CLI commands → Get-token command: dispatches command
- CLI commands → Convert command: dispatches command
- Convert command → Kubeconfig conversion: calls conversion (evidence: `pkg/cmd/convert.go`)
- Kubeconfig conversion → Authentication options: uses token options (evidence: `pkg/internal/converter/convert.go`)
- Get-token command → Credential providers: uses token package (evidence: `pkg/cmd/token.go`)
- Credential providers → Exec credential output: produces exec credentials
- Authentication options → Environment settings: reads settings (evidence: `pkg/internal/token/options.go`)
- Authentication options → PoP cache: configures PoP cache (evidence: `pkg/internal/token/options.go`)
- Authentication options → PoP token acquisition: uses PoP support (evidence: `pkg/internal/token/options.go`)
- Credential providers → Azure identity service: requests Azure tokens
- Public token options → Authentication options: converts options (evidence: `pkg/token/options_ctor.go`)
- Public token provider → Credential providers: creates credential (evidence: `pkg/token/provider.go`)
- Public PoP API → PoP token acquisition: delegates acquisition (evidence: `pkg/pop/poptoken.go`)
- PoP token acquisition → PoP cache: uses cache (evidence: `pkg/internal/pop/poptoken.go`)
- Linux cache storage → JWE encryption: encrypts cache data (evidence: `pkg/internal/pop/cache/linux.go`)
- JWE encryption → AES-CBC encryption: uses encryption (evidence: `pkg/internal/pop/cache/internal/jwe/jwe.go`)
