Skip to content

[log] Add debug logging to GenerateRandomAPIKey in auth/apikey.go#4002

Merged
lpcox merged 2 commits intomainfrom
log/auth-apikey-debug-logging-ba1c747ffc8ff959
Apr 17, 2026
Merged

[log] Add debug logging to GenerateRandomAPIKey in auth/apikey.go#4002
lpcox merged 2 commits intomainfrom
log/auth-apikey-debug-logging-ba1c747ffc8ff959

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

Adds 3 debug logging calls to internal/auth/apikey.go using the existing package-level logger (log, declared in auth/header.go).

Changes

internal/auth/apikey.go — 3 new log.Print / log.Printf calls in GenerateRandomAPIKey:

Location Log message
Function entry "Generating random API key"
On error "Random API key generation failed: %v"
On success "Random API key generated successfully"

Why this file?

GenerateRandomAPIKey is called at gateway startup (spec §7.3) whenever no API key is configured. Logging this lifecycle event helps developers:

  • Confirm that key generation occurs when expected
  • Diagnose failures in strutil.RandomHex (e.g., entropy issues)
  • See the startup sequence in DEBUG=auth:* output

Design decisions

  • Reuses existing logger: var log = logger.New("auth:header") is already declared in the auth package. No new logger variable or import is needed in apikey.go.
  • No key exposure: The log messages confirm generation success/failure without logging the actual key value.
  • No side effects: All log arguments are already-evaluated variables.

Validation

  • go build ./...
  • go vet ./...
  • go test ./internal/auth/... ✅ (all tests pass)
  • go test ./... ✅ (all unit tests pass; pre-existing integration test failures unrelated to this change)

Enabling debug output

DEBUG=auth:* ./awmg --config config.toml

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • invalidhostthatdoesnotexist12345.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "invalidhostthatdoesnotexist12345.com"

See Network Configuration for more information.

Generated by Go Logger Enhancement · ● 4.3M ·

Log function entry, success, and failure for GenerateRandomAPIKey using
the existing package-level debug logger (declared in auth/header.go).
This provides visibility into API key generation at startup when
DEBUG=auth:* is enabled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot added automation enhancement New feature or request labels Apr 17, 2026
@lpcox lpcox marked this pull request as ready for review April 17, 2026 16:32
Copilot AI review requested due to automatic review settings April 17, 2026 16:32
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

Adds debug-level logging around random API key generation in the internal/auth package to improve startup diagnostics when no API key is configured.

Changes:

  • Log entry into GenerateRandomAPIKey
  • Log the underlying error when key generation fails
  • Log successful completion of key generation (without logging the key)
Show a summary per file
File Description
internal/auth/apikey.go Adds debug logs around random API key generation for easier startup troubleshooting.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread internal/auth/apikey.go Outdated
Comment on lines +13 to +16
log.Print("Generating random API key")
key, err := strutil.RandomHex(32)
if err != nil {
log.Printf("Random API key generation failed: %v", err)
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

These new debug logs are emitted via the package-level log declared in header.go with namespace auth:header, so API-key generation messages will be tagged as auth:header. This makes log filtering/searching misleading (e.g., you can’t enable just API-key logs) and doesn’t match the behavior being logged. Consider introducing a dedicated logger for this file (e.g., auth:apikey) or renaming the existing logger namespace to something broader and updating call sites accordingly.

See below for a potential fix:

	stdlog "log"
	"os"

	"github.com/github/gh-aw-mcpg/internal/strutil"
)

var apiKeyLog = stdlog.New(os.Stderr, "auth:apikey ", 0)

// GenerateRandomAPIKey generates a cryptographically random API key.
// Per spec §7.3, the gateway SHOULD generate a random API key on startup
// if none is provided. Returns a 32-byte hex-encoded string (64 chars).
func GenerateRandomAPIKey() (string, error) {
	apiKeyLog.Print("Generating random API key")
	key, err := strutil.RandomHex(32)
	if err != nil {
		apiKeyLog.Printf("Random API key generation failed: %v", err)
		return "", fmt.Errorf("failed to generate random API key: %w", err)
	}
	apiKeyLog.Print("Random API key generated successfully")

Copilot uses AI. Check for mistakes.
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented Apr 17, 2026

@copilot address the review feedback #4002 (review)

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 17, 2026

@copilot address the review feedback #4002 (review)

Implemented in ce2abc8: GenerateRandomAPIKey now uses a dedicated auth:apikey logger (logAPIKey) instead of the package-level auth:header logger, so API key generation logs are correctly namespaced and filterable.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build313786029/b510/launcher.test /tmp/go-build313786029/b510/launcher.test -test.testlogfile=/tmp/go-build313786029/b510/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true _.a 523579/b299/ x_amd64/vet --gdwarf-5 --64 (dns block)
    • Triggering command: /tmp/go-build1818934385/b514/launcher.test /tmp/go-build1818934385/b514/launcher.test -test.testlogfile=/tmp/go-build1818934385/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s 5235�� /tmp/go-build402523579/b013/vet.cfg cfg 64/pkg/tool/linux_amd64/vet -D GOAMD64_v1 -o 64/pkg/tool/linux_amd64/vet 5235�� /tmp/go-build402523579/b134/vet.cfg 64/pkg/tool/linu-dynimport 64/pkg/tool/linux_amd64/vet go jlzPEUyAk p/bin/bash 64/pkg/tool/linux_amd64/vet (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build313786029/b492/config.test /tmp/go-build313786029/b492/config.test -test.testlogfile=/tmp/go-build313786029/b492/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 1.80.0/internal/resolver/passthrough/passthrough.go 523579/b164/ x_amd64/vet ctor (dns block)
    • Triggering command: /tmp/go-build1818934385/b496/config.test /tmp/go-build1818934385/b496/config.test -test.testlogfile=/tmp/go-build1818934385/b496/testlog.txt -test.paniconexit0 -test.timeout=10m0s 5235�� _.a -trimpath 64/pkg/tool/linux_amd64/vet -p github.com/tetradocker-cli-plugin-metadata -lang=go1.24 64/pkg/tool/linux_amd64/vet (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build313786029/b510/launcher.test /tmp/go-build313786029/b510/launcher.test -test.testlogfile=/tmp/go-build313786029/b510/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true _.a 523579/b299/ x_amd64/vet --gdwarf-5 --64 (dns block)
    • Triggering command: /tmp/go-build1818934385/b514/launcher.test /tmp/go-build1818934385/b514/launcher.test -test.testlogfile=/tmp/go-build1818934385/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s 5235�� /tmp/go-build402523579/b013/vet.cfg cfg 64/pkg/tool/linux_amd64/vet -D GOAMD64_v1 -o 64/pkg/tool/linux_amd64/vet 5235�� /tmp/go-build402523579/b134/vet.cfg 64/pkg/tool/linu-dynimport 64/pkg/tool/linux_amd64/vet go jlzPEUyAk p/bin/bash 64/pkg/tool/linux_amd64/vet (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build313786029/b510/launcher.test /tmp/go-build313786029/b510/launcher.test -test.testlogfile=/tmp/go-build313786029/b510/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true _.a 523579/b299/ x_amd64/vet --gdwarf-5 --64 (dns block)
    • Triggering command: /tmp/go-build1818934385/b514/launcher.test /tmp/go-build1818934385/b514/launcher.test -test.testlogfile=/tmp/go-build1818934385/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s 5235�� /tmp/go-build402523579/b013/vet.cfg cfg 64/pkg/tool/linux_amd64/vet -D GOAMD64_v1 -o 64/pkg/tool/linux_amd64/vet 5235�� /tmp/go-build402523579/b134/vet.cfg 64/pkg/tool/linu-dynimport 64/pkg/tool/linux_amd64/vet go jlzPEUyAk p/bin/bash 64/pkg/tool/linux_amd64/vet (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build313786029/b519/mcp.test /tmp/go-build313786029/b519/mcp.test -test.testlogfile=/tmp/go-build313786029/b519/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true cfg olang.org/protob-ifaceassert x_amd64/vet --gdwarf-5 --64 -o x_amd64/vet om/t�� cfg /tmp/go-build402-ifaceassert x_amd64/vet . 523579/b299/_cgo/usr/bin/runc --64 x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build1818934385/b523/mcp.test /tmp/go-build1818934385/b523/mcp.test -test.testlogfile=/tmp/go-build1818934385/b523/testlog.txt -test.paniconexit0 -test.timeout=10m0s (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from lpcox April 17, 2026 16:46
@lpcox lpcox merged commit b9c4059 into main Apr 17, 2026
7 checks passed
@lpcox lpcox deleted the log/auth-apikey-debug-logging-ba1c747ffc8ff959 branch April 17, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants