Skip to content

fix: make authentication remediation safe for headless use - #103

Merged
francoischalifour merged 3 commits into
mainfrom
fc/agent-safe-auth-remediation
Sep 4, 2026
Merged

fix: make authentication remediation safe for headless use#103
francoischalifour merged 3 commits into
mainfrom
fc/agent-safe-auth-remediation

Conversation

@francoischalifour

Copy link
Copy Markdown
Member

Why

The CLI’s first-run authentication guidance was optimized for an interactive human terminal, but it was also emitted to agents, JSON consumers, and non-TTY environments.

That created several rough edges:

  • doctor led headless callers toward browser login or interactive --scope configuration, neither of which can complete safely in automation.
  • Some remediation examples placed secrets directly in command arguments.
  • A failed lakehouse query said only “No credentials,” making the affected authentication plane unclear.
  • Login and configure errors include multiple lines of guidance, but the human error renderer sanitized their newline characters into literal \x0a.
  • Configuration failures also appended a command EXAMPLES section, which is useful for parser/usage errors but noisy and misleading when configuration is the actual problem.
  • Documentation promises a [ERROR] prefix, while the CLI rendered ERROR.

This PR keeps the existing interactive path for humans while making failure guidance safe and actionable for programmatic callers.

What changed

Context-aware doctor remediation

doctor now carries an explicit interactive property in its check context. It is true only for a human terminal with TTY stdin and without --json or --agent.

For an interactive human terminal, doctor preserves the existing login-first guidance:

Run: altertable login
Or run: altertable profile configure --scope <plane>

For --agent, --json, or non-TTY stdin, doctor instead provides plane-specific, non-interactive remediation.

Management authentication:

Run: printf '%s' "$KEY" | altertable profile configure --api-key-stdin --env <name>
Or set: ALTERTABLE_API_KEY and ALTERTABLE_ENV

Lakehouse authentication:

Run: printf '%s' "$PASSWORD" | altertable profile configure --user <username> --password-stdin
Or set: ALTERTABLE_BASIC_AUTH_TOKEN or ALTERTABLE_LAKEHOUSE_USERNAME and ALTERTABLE_LAKEHOUSE_PASSWORD

The same mode-aware recommendations are used for failed management and lakehouse API checks, not only missing credentials. This avoids directing agents toward a browser or interactive wizard after a probe failure.

Safe non-interactive login and configure guidance

When login is invoked without an interactive terminal, its error now recommends piping an API key through --api-key-stdin or using management environment variables.

The non-TTY profile configure error similarly replaces the API-key-on-argv example with --api-key-stdin. This avoids suggesting that secrets be exposed in process listings.

Clearer lakehouse query failures

The missing credential error raised by the lakehouse query path now says “No lakehouse credentials,” making it clear that the data-plane authentication is missing rather than management authentication.

Human error presentation

Human-readable errors now:

  • Use the documented [ERROR] prefix.
  • Preserve trusted multiline messages as actual terminal lines.
  • Continue sanitizing terminal control characters on each rendered line.
  • Suppress command examples for configuration errors; examples remain available for usage and parser errors.

JSON error envelopes are unchanged.

Tests

Added or updated coverage for:

  • JSON doctor remediation for both authentication planes.
  • Non-TTY human doctor remediation.
  • Interactive human doctor remediation retaining login-first behavior.
  • Agent-mode doctor remediation even when stdin is a TTY.
  • API-probe remediation in non-interactive mode.
  • Missing query credentials identifying the lakehouse plane.
  • Multiline login and profile configure errors.
  • [ERROR] rendering and multiline sanitization.
  • Suppression of command EXAMPLES for configuration failures.

Tailor doctor guidance to interactive versus agent, JSON, and non-TTY callers, with stdin-safe commands and environment-variable alternatives for each authentication plane.

Render human errors with the documented [ERROR] marker, preserve multiline guidance, and keep configuration failures from appending command examples. Name lakehouse credentials explicitly when queries lack authentication.
Pass DoctorCheckContext directly to skip, run, and remediation callbacks. Remove the unused failure wrapper and error parameter so the lifecycle contract follows the existing command callback convention.

@albert20260301 albert20260301 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Required before merge: rename this PR with a Conventional Commit prefix (for example, fix(cli): make authentication remediation safe for headless use). The semantic-title check is currently the only failing check; the rest of the CI matrix is green.

@francoischalifour francoischalifour changed the title Make authentication remediation safe for headless use fix: make authentication remediation safe for headless use Sep 3, 2026

@albert20260301 albert20260301 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Title corrected and required checks are now green; approving.

@francoischalifour
francoischalifour enabled auto-merge (squash) September 4, 2026 08:57
@francoischalifour
francoischalifour merged commit f3336a0 into main Sep 4, 2026
12 checks passed
@francoischalifour
francoischalifour deleted the fc/agent-safe-auth-remediation branch September 4, 2026 09:00
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.

3 participants