How engflow/auth works
Project Type and Purpose
• Type: A command‑line credential helper tool, written in Go, invoked by Bazel.
• Purpose: Automate “login/export/import/logout” of EngFlow auth tokens, storing them securely and supplying them to Bazel via the --credential_helper flag.
File Structure
• Top‑level build: Bazel (WORKSPACE, BUILD, .bazelrc, MODULE.bazel), Go modules (go.mod, go.sum).
• cmd/engflow_auth: Main entrypoint (main.go) and tokens.go define CLI commands: login, export, import, logout.
• internal/… packages implement core logic and abstractions:
– oauthdevice: implements OAuth2 device‑flow handshake.
– oauthtoken: defines token stores (keyring, file, debug, fake).
– browser: opens URLs in user’s default browser.
– autherr: centralized error types.
– buildstamp: embeds build metadata.
• infra/…: CI and release scripts, GitHub workflows, credential‑management helpers (login.sh, logout.sh).
• platform/…: cross‑compilation toolchain definitions for Linux/macOS/Windows.
Extract Architecture Insights from the README
• Auth flow:
– Interactive login: engflow_auth login [CLUSTER URL] → open browser → complete flow → token stored in system keyring.
– Non‑interactive (CI): export reads token, inject as secret, import writes token to file store, logout to clean up.
• Integration point: Bazel calls engflow_auth as credential helper to fetch tokens during remote operations.
• engflow_auth CLI binary
– OAuth device flow (oauthdevice)
– Token store abstraction (oauthtoken)
– Browser launcher (browser)
– Error handler (autherr)
• External Services:
– EngFlow Authentication Server (OAuth 2.0 endpoint)
– User’s Web Browser (for interactive flow)
• Local Persistence:
– System keyring (encrypted store)
– File store (plaintext, for CI)
• Bazel process (invoker of CLI)
• CI System (e.g., GitHub Actions)
• User / CI → engflow_auth (CLI invocation)
• engflow_auth → OAuth Server: device‑flow initiation & polling
• engflow_auth → Browser: open URL for user to authenticate
• OAuth Server → engflow_auth: token issuance
• engflow_auth → Token Store (keyring or file)
• Bazel → engflow_auth: fetch token at build time
• CI System → engflow_auth import/export/logout via scripts
c. Architectural Patterns & Principles:
• Modular separation: cmd/ vs internal/ packages.
• Abstraction of token storage (allows keyring or file).
• Single responsibility per internal package (device flow, storage, errors).
• Use of Bazel for reproducible builds and cross‑compilation.
d. Key Technologies / Frameworks:
• Go (language)
• Bazel (build & release artifacts)
• OAuth 2.0 device flow (authentication protocol)
• System keyring APIs (platform‐specific)
• GitHub Actions or other CI for non‑interactive use cases