Skip to content

aksd: identify backend as aks-desktop in k8s API User-Agent#694

Closed
gambtho wants to merge 4 commits into
Azure:headlamp-downstreamfrom
gambtho:aksd-user-agent
Closed

aksd: identify backend as aks-desktop in k8s API User-Agent#694
gambtho wants to merge 4 commits into
Azure:headlamp-downstreamfrom
gambtho:aksd-user-agent

Conversation

@gambtho
Copy link
Copy Markdown
Collaborator

@gambtho gambtho commented May 29, 2026

Summary

  • Add applyAppNameOverride helper + init() in backend/pkg/kubeconfig/kubeconfig.go that reads HEADLAMP_APP_NAME from the process environment and overrides the package-level AppName (default still Headlamp). Unit-tested via an injected env getter.
  • Set HEADLAMP_APP_NAME=aks-desktop when the Electron shell spawns the bundled backend, so all proxied Kubernetes API requests carry `User-Agent: aks-desktop (/)` instead of `Headlamp ...`. Azure-side audit logs and telemetry can now attribute traffic to AKS Desktop.

Two commits:

  1. `upstreamable: allow overriding backend AppName via HEADLAMP_APP_NAME` — generic env-var hook, useful to anyone white-labeling Headlamp.
  2. `upstreamable: separate AppName default from env-override helper` — polish: keep the "Headlamp" default in one place (the var declaration), let the helper return only the env value.
  3. `aksd: identify backend as aks-desktop to the k8s API server` — Electron launcher sets the env var.
  4. `aksd: correct kubeconfig.go path in HEADLAMP_APP_NAME comment` — comment polish.

The submodule pointer bump in `Azure/aks-desktop` is a separate PR.

Test plan

  • `go test ./pkg/kubeconfig/...` — `TestApplyAppNameOverride` (4 sub-tests), `TestBuildUserAgent`, `TestUserAgentRoundTripper_RoundTrip`, `TestUserAgentIntegration` all pass.
  • `go vet ./pkg/kubeconfig/...` clean.
  • `npm run lint` clean in `app/`.
  • Manual: launch AKS Desktop against a test cluster; confirm audit log `userAgent` begins with `aks-desktop`.
  • Manual: run the Headlamp backend standalone without `HEADLAMP_APP_NAME` set; confirm User-Agent still reads `Headlamp ...`.

gambtho added 4 commits May 28, 2026 22:22
The User-Agent attached to Kubernetes API server requests is built
from the package-level AppName variable in pkg/kubeconfig. Allow
downstream embedders (such as AKS Desktop) to white-label this
identifier by setting HEADLAMP_APP_NAME in the backend process
environment. When unset or empty, the default "Headlamp" is preserved.
Set HEADLAMP_APP_NAME=aks-desktop when spawning the bundled Headlamp
backend from the Electron shell. The backend uses this value as the
product name in the User-Agent header it attaches to all Kubernetes
API server requests, so Azure-side audit logs and telemetry attribute
traffic to AKS Desktop rather than upstream Headlamp.
Have applyAppNameOverride return only the env value (or "") so the
"Headlamp" default lives in exactly one place — the AppName var
declaration. init() now updates AppName only when an override is
present. Tests updated to match the new contract.
The pointer in the comment used the outer aks-desktop submodule path
(headlamp/backend/...) rather than the path inside the Headlamp
repository (backend/...).
Copilot AI review requested due to automatic review settings May 29, 2026 17:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR lets AKS Desktop identify its bundled Headlamp backend as aks-desktop in Kubernetes API User-Agent strings by adding a backend app-name override and setting it from the Electron launcher.

Changes:

  • Adds HEADLAMP_APP_NAME override plumbing in kubeconfig initialization.
  • Exposes the override helper for tests and adds unit coverage for helper behavior.
  • Sets HEADLAMP_APP_NAME=aks-desktop before spawning the bundled backend.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
backend/pkg/kubeconfig/kubeconfig.go Adds app-name override helper and initialization hook.
backend/pkg/kubeconfig/export_test.go Exposes the helper to external package tests.
backend/pkg/kubeconfig/appname_override_test.go Adds unit tests for env override helper behavior.
app/electron/main.ts Sets backend app name to aks-desktop from the Electron process.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/electron/main.ts
Comment on lines +869 to +870
// User-Agent for all proxied k8s requests. See
// backend/pkg/kubeconfig/kubeconfig.go (applyAppNameOverride).
Comment thread app/electron/main.ts
// The backend reads HEADLAMP_APP_NAME at startup and uses it in the
// User-Agent for all proxied k8s requests. See
// backend/pkg/kubeconfig/kubeconfig.go (applyAppNameOverride).
process.env.HEADLAMP_APP_NAME = 'aks-desktop';
@gambtho gambtho closed this May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants