Skip to content

fix: switch REST client auth to x-api-key header - #78

Closed
jscaltreto wants to merge 3 commits into
circlefin:mainfrom
jscaltreto:fix/use-x-api-key-header
Closed

fix: switch REST client auth to x-api-key header#78
jscaltreto wants to merge 3 commits into
circlefin:mainfrom
jscaltreto:fix/use-x-api-key-header

Conversation

@jscaltreto

@jscaltreto jscaltreto commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

QuickNode's REST API no longer accepts Authorization: Bearer tokens — it now requires the API key via the x-api-key header. This caused terraform plan to fail with a 401 Unauthorized during provider configuration even when supplying a valid API key. This PR aligns the main REST client with the streams client, which was already using x-api-key correctly.

Also bumps several dependencies to address CVEs surfaced by the Trivy scan, and updates the generated API clients to match.

Detail

Auth fix:

  • internal/provider/provider.go: Replaced securityprovider.NewSecurityProviderBearerToken with an inline RequestEditorFn that sets x-api-key: <apiKey> on each request, matching the pattern already used for the streams client. Removed the now-unused securityprovider import.
  • internal/utils/error.go: Changed ErrorResponse.Error from *string to json.RawMessage. QuickNode returns error as a JSON object (not a string) in non-200 responses, causing a silent unmarshal failure that swallowed the real API error message and replaced it with a misleading internal warning.

Dependency upgrades:

  • golang.org/x/net v0.55.0 → v0.56.0 (CVE-2026-46600)
  • golang.org/x/text v0.37.0 → v0.40.0 (CVE-2026-56852)
  • golang.org/x/crypto v0.52.0 → v0.54.0 (latest)
  • google.golang.org/grpc v1.79.3 → v1.82.1 (GHSA-hrxh-6v49-42gf)
  • github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 → v2.7.1 (GHSA-rjwr-m7qx-3fjr)
  • github.com/oapi-codegen/runtime v1.1.1 → v1.6.0 (required by regenerated code from v2.7.1 codegen)
  • Added .trivyignore for GO-2026-5932 (golang.org/x/crypto/openpgp is unmaintained by design, has no fixed version, and is not imported by any package in our dependency tree — Trivy flags it at the module level).
  • Added .licenseignore entry for go.yaml.in/yaml/v3 (Apache-2.0 AND MIT dual-license; both are acceptable).

Regenerated API clients (api/quicknode/quicknode.gen.go, api/streams/streams.gen.go): changes are additive only — typed context keys for auth scopes and Valid() methods on all enum types.

Testing

Verified locally using dev_overrides with a valid QuickNode API key. Prior to this change, terraform plan failed with 401 Unauthorized and a JSON unmarshal warning. After this change, the provider configures successfully and plans complete.

Trivy scan passes locally with 0 findings after the dependency upgrades. All unit tests pass.

Documentation

No documentation changes required.

QuickNode's API no longer accepts Authorization: Bearer tokens; it now
requires the API key via the x-api-key header. The streams client already
used this header correctly; align the main REST client to match.

Also update ErrorResponse.Error from *string to json.RawMessage so
non-200 error bodies (where "error" is an object, not a string) unmarshal
cleanly and surface the real API message in diagnostics.
Upgrade dependencies to address CVEs surfaced by Trivy:
- golang.org/x/net v0.55.0 → v0.56.0 (CVE-2026-46600)
- golang.org/x/text v0.37.0 → v0.40.0 (CVE-2026-56852)
- golang.org/x/crypto v0.52.0 → v0.54.0 (latest)
- google.golang.org/grpc v1.79.3 → v1.82.1 (GHSA-hrxh-6v49-42gf)
- github.com/oapi-codegen/oapi-codegen/v2 v2.4.1 → v2.7.1 (GHSA-rjwr-m7qx-3fjr)

Add .trivyignore for GO-2026-5932 (golang.org/x/crypto/openpgp is
unmaintained by design, no fixed version exists, and no package in
our dependency tree imports it — it is flagged at the module level).
oapi-codegen/runtime v1.1.1 is missing StyleParamWithOptions and
StyleParamOptions introduced in newer codegen output. Bump to v1.6.0
to match the v2.7.1 codegen upgrade.

Regenerated api/quicknode/quicknode.gen.go and api/streams/streams.gen.go
via make generate. Changes are additive: typed context keys for auth
scopes and Valid() methods on all enum types.
@jscaltreto

Copy link
Copy Markdown
Contributor Author

Closing in favor of #79

@jscaltreto jscaltreto closed this Jul 22, 2026
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