Skip to content

🎯 Fix vault login -method=oidc -format=json returning exit code 0 on callback timeout/failure #2

Description

@kyresehk190

📝 Description

When executing vault login -method=oidc -format=json, an authentication failure caused by an expired or timed-out OIDC callback returns a JSON object describing the error, but the Vault CLI exits with status code 0 instead of a non-zero exit code.

This behavior breaks automation and CI/CD pipelines, which rely on exit codes to determine the success or failure of the login step. Because the CLI exits with 0, downstream steps attempt to use an invalid or non-existent token, leading to cascading failures that are harder to debug.

This issue is specific to the OIDC login flow when structured JSON output is requested. The standard human-readable output correctly returns a non-zero exit status upon authentication failure.

🎯 Acceptance Criteria

  • When vault login -method=oidc -format=json fails due to a callback timeout, expiration, or any other authentication error, the CLI must exit with a non-zero status code (e.g., 1).
  • The JSON error payload describing the failure must still be printed to the appropriate stream (stderr or stdout depending on Vault's CLI output standards).
  • Successful OIDC logins using -format=json must continue to exit with status code 0.
  • OIDC logins using the default human-readable format must continue to exit with a non-zero status code on failure (no regressions).

🛠️ Technical Specifications & Context

This repository is a Go-based codebase representing HashiCorp Vault. The CLI command handling logic is primarily located under the command/ directory.

Key Areas to Investigate:

  1. command/login.go: This file handles the vault login command execution. Look at how the command handler processes the OIDC method and how it handles errors returned from the authentication flow.
  2. Output Formatting Logic: The bug likely resides where the CLI formats the output. When -format=json is specified, the CLI formatter might be intercepting the error to print it as a JSON object, but failing to propagate the error back to the command runner, causing the runner to assume the execution completed successfully (returning 0).
  3. OIDC Credential Handler: Check how the OIDC callback timeout error is propagated. If the callback times out, the handler should return a concrete error that the CLI command runner recognizes and handles.

Specifically, look for where Format or code is evaluated inside the command runner:

// Example pattern to look for in command execution:
if err != nil {
    if format == "json" {
        // If the code prints the JSON error here but returns nil or exits 0, this needs to be fixed.
    }
}

🧪 Verification & Testing

Manual Verification

  1. Start a local Vault dev server.
  2. Configure the OIDC auth method with a very short authorization code flow timeout or manually trigger a timeout by not completing the browser login flow.
  3. Run the login command:
    vault login -method=oidc -format=json
  4. Allow the callback to time out.
  5. Verify the exit code of the command:
    echo $?
    Expected behavior: The exit code is non-zero (e.g., 1).
    Current buggy behavior: The exit code is 0.

Automated Tests

  • Add or update a test case in command/login_test.go (or the relevant CLI test file) that mocks an OIDC login failure with the -format=json flag.
  • Assert that the returned error is not nil and that the command execution helper returns a non-zero exit code.

Opire Bounty


This repo is using Opire - what does it mean? 👇
💵 Everyone can add rewards for this issue commenting /reward 100 (replace 100 with the amount).
🕵️‍♂️ If someone starts working on this issue to earn the rewards, they can comment /try to let everyone know!
🙌 And when they open the PR, they can comment /claim #2 either in the PR description or in a PR's comment.

🪙 Also, everyone can tip any user commenting /tip 20 @kyresehk190 (replace 20 with the amount, and @kyresehk190 with the user to tip).

📖 If you want to learn more, check out our documentation.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions