Skip to content

feat: add insecure provider option - #50

Open
rcmorano wants to merge 5 commits into
dzhng:mainfrom
rcmorano:feat/add-insecure-provider-option
Open

rcmorano wants to merge 5 commits into
dzhng:mainfrom
rcmorano:feat/add-insecure-provider-option

Conversation

@rcmorano

@rcmorano rcmorano commented Oct 4, 2026

Copy link
Copy Markdown

Summary

First contribution here — happy to adjust to whatever conventions the project
prefers, and thanks in advance for the review.

This adds an explicit --insecure opt-in so jg auth can save a custom
Jev-compatible endpoint that speaks plain http:// on a non-loopback host and
requires no API key (e.g. a self-hosted gateway on a private network). I ran into
this need when pointing jg at a local LAN endpoint; the strict default is the
right call for a tool that ships source content to a provider, so I kept this as
a deliberate, saved-record-only opt-in rather than any environment override.

Control flow of the new path:

jg auth --provider custom --base-url http://192.168.0.135:8080/v1 --model jev --insecure --stdin
  parseCommand (apps/cli/src/args.ts)
    --insecure accepted only with --provider custom (preset provider → exit 1)
  authenticate (apps/cli/src/auth.ts)
    validateBaseURL(baseURL, { insecure })   # http allowed only when opted in
    readKey                                  # empty stdin accepted when insecure
    save credentials.json                    # { ..., apiKey: "", insecure: true }, 0600/0700
    stdout: "Custom endpoint (host, insecure) key saved."
    stdout: one-line warning naming the host (traffic unencrypted, unauthenticated)

jg doctor / jg "question" .
  loadCredentials
    empty apiKey accepted only when provider=custom && insecure=true
    http without the flag → "Base URL must use https:// … re-run jg auth with
      --insecure …" instead of the generic error (key never leaked)
  createEvaluator (packages/core/src/evaluator.ts)
    SDK gets a harmless placeholder key (it requires non-empty)
    fetch wrapper strips the Authorization header when the saved key is empty

Interactive auth accepts jg auth --insecure as a preselect, or asks for
confirmation when a plain-http URL is entered. Records without "insecure": true
validate and behave exactly as before.

I tried to follow the existing contracts (stdout-only output, no key echoing,
strict defaults, no env overrides) — please correct me if I missed a convention.

Evidence

  • Before: auth --provider custom --base-url http://192.168.0.135:8080/v1 --insecure --stdin
    exited 1 ("Base URL must use https:// …"); empty key stdin exited 1.
    After: saves {provider:"custom", baseURL, model, apiKey:"", insecure:true}
    with 0600/0700 modes, prints the warning, stderr empty, key never echoed;
    doctor and search succeed against a fixture server with no Authorization
    header sent.
  • bun test apps/cli/test packages/core/test test/evaluator.test.ts (docker-gated
    suites run against the built dist): 97 pass, 0 fail — includes a new pty test
    for the interactive confirmation flow.
  • Installed-package journey against the npm-packed artifact:
    "installed insecure custom endpoint saves an empty key and searches without an
    auth header" passes; existing preset journeys still pass.
  • check-types, lint, format:check clean; parser suite 39/39.
  • Not run: the full container suites (bun run verify) — my environment lacked
    buildx initially; CI should be the authority here, and I'm glad to chase
    anything it flags.

Merge Danger

Door: two-way. Reverting restores strict validation; already-saved insecure
records simply fail to load again with the generic credentials error. The
insecure field is additive and ignored by old binaries, so nothing needs
migration in either direction.

Blast Radius: custom-endpoint auth and provider request headers. Preset
providers, cache identity, and search output are untouched; the header strip
only triggers when the saved key is "", which only an insecure custom record
can hold.

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.

1 participant