Skip to content

Expose Debug API through the CLI - #7133

Merged
sorindumitru merged 5 commits into
spiffe:mainfrom
sorindumitru:debug-api
Aug 8, 2026
Merged

sorindumitru merged 5 commits into
spiffe:mainfrom
sorindumitru:debug-api

Conversation

@sorindumitru

@sorindumitru sorindumitru commented Jul 9, 2026 •

Copy link
Copy Markdown
Member

Pull Request check list

  • Commit conforms to CONTRIBUTING.md?
  • Proper tests/regressions included?
  • Documentation updated?

Affected functionality
Agent and server CLIs

Description of change
The debug API is now exposed through the CLI, making it easier to use.

Signed-off-by: Sorin Dumitru <[email protected]>
Signed-off-by: Sorin Dumitru <[email protected]>
Copilot AI review requested due to automatic review settings July 9, 2026 09:25
@sorindumitru sorindumitru changed the title Debug api Expose Debug API through the CLI Jul 9, 2026

Copilot AI 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.

Pull request overview

This PR exposes the existing Agent and Server Debug APIs via new CLI subcommands (debug getinfo), making it easier for operators to retrieve runtime debug information (uptime, counts, and SVID chain) without writing custom clients.

Changes:

  • Add spire-server debug getinfo backed by the server Debug gRPC API, including CLI wiring and tests.
  • Add spire-agent debug getinfo backed by the agent Debug gRPC API, including OS-specific socket/named-pipe handling and tests.
  • Update CLI documentation and the agent sample config to surface the new debug functionality.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
doc/spire_server.md Documents new spire-server debug getinfo command and flags
doc/spire_agent.md Documents new spire-agent debug getinfo command and flags
conf/agent/agent.conf Updates sample agent config to include an Admin API socket path
cmd/spire-server/util/util.go Adds NewDebugClient() to the server CLI client interface
cmd/spire-server/cli/debug/debug.go Implements spire-server debug getinfo command and pretty output
cmd/spire-server/cli/debug/debug_posix_test.go POSIX usage string expectations for server debug command
cmd/spire-server/cli/debug/debug_windows_test.go Windows usage string expectations for server debug command
cmd/spire-server/cli/debug/debug_test.go Unit tests for server debug command behavior/output
cmd/spire-server/cli/cli.go Registers debug getinfo in the server CLI command map
cmd/spire-agent/cli/debug/debug.go Implements spire-agent debug getinfo command and pretty output
cmd/spire-agent/cli/debug/debug_posix.go POSIX socket flag/address handling for agent debug command
cmd/spire-agent/cli/debug/debug_windows.go Windows named-pipe flag/address handling for agent debug command
cmd/spire-agent/cli/debug/debug_posix_test.go POSIX usage + helper setup for agent debug tests
cmd/spire-agent/cli/debug/debug_windows_test.go Windows usage + helper setup for agent debug tests
cmd/spire-agent/cli/debug/debug_test.go Unit tests for agent debug command behavior/output
cmd/spire-agent/cli/cli.go Registers debug getinfo in the agent CLI command map

Comment thread conf/agent/agent.conf Outdated
server_address = "127.0.0.1"
server_port = "8081"
socket_path ="/tmp/spire-agent/public/api.sock"
admin_socket_path ="/tmp/spire-agent/private/admin.sock"

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.

makes sense to me, or do you plan to make it enabled as default?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, that's probably best

Comment thread doc/spire_agent.md
Comment on lines +390 to +392
Prints debug information about the agent, including uptime, last successful
sync time, cached SVID counts, and the agent's own SVID chain.

Comment on lines +93 to +96
env.Printf("Agent Debug Info:\n")
env.Printf(" Uptime: %s\n", (time.Duration(resp.Uptime) * time.Second).String())
env.Printf(" Last Sync Success: %s\n", time.Unix(resp.LastSyncSuccess, 0).UTC().Format(time.RFC3339))
env.Printf(" Cached X.509 SVIDs: %d\n", resp.CachedX509SvidsCount)
Comment thread conf/agent/agent.conf Outdated
server_address = "127.0.0.1"
server_port = "8081"
socket_path ="/tmp/spire-agent/public/api.sock"
admin_socket_path ="/tmp/spire-agent/private/admin.sock"

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.

makes sense to me, or do you plan to make it enabled as default?

Comment thread cmd/spire-agent/cli/debug/debug.go Outdated
return newGetInfoCommand(commoncli.DefaultEnv)
}

func newGetInfoCommand(env *commoncli.Env) *getInfoCommand {

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.

can you reuse https://github.com/spiffe/spire/blob/main/cmd/spire-agent/util/util.go#L66? I think this is going to reduce this code a lot and add windows/linux support for free

Comment thread doc/spire_agent.md
|---------------|------------------------------------|----------------------------------|
| `-socketPath` | Path to the SPIRE Agent API socket | /tmp/spire-agent/public/api.sock |

### `spire-agent debug getinfo`

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.

for both can you mention than the debugAPI must be enabled to use this?

Comment thread cmd/spire-agent/cli/debug/debug.go Outdated

env.Printf("Agent Debug Info:\n")
env.Printf(" Uptime: %s\n", (time.Duration(resp.Uptime) * time.Second).String())
env.Printf(" Last Sync Success: %s\n", time.Unix(resp.LastSyncSuccess, 0).UTC().Format(time.RFC3339))

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.

if it never sync it is ngoing to be 0 that is translated to 1970-01-01 right? can you verify no empty before printing this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I made it print (never) here.

Comment thread cmd/spire-agent/cli/debug/debug.go Outdated
func prettyPrintGetInfo(env *commoncli.Env, results ...any) error {
resp, ok := results[0].(*debugv1.GetInfoResponse)
if !ok {
return errors.New("internal error: cli printer; please report this bug")

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.

can you reuse ErrInternalCustomPrettyFunc as all another cmds? (same for all places like this)

Signed-off-by: Sorin Dumitru <[email protected]>
Signed-off-by: Sorin Dumitru <[email protected]>
@sorindumitru sorindumitru added this to the 1.15.3 milestone Aug 8, 2026
@sorindumitru
sorindumitru added this pull request to the merge queue Aug 8, 2026
Merged via the queue into spiffe:main with commit 7e41779 Aug 8, 2026
53 checks passed
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