Skip to content

Add masked API key data source - #100

Open
IlyaasK wants to merge 1 commit into
hypeship/deployment-data-sourcefrom
hypeship/api-key-data-source
Open

Add masked API key data source#100
IlyaasK wants to merge 1 commit into
hypeship/deployment-data-sourcefrom
hypeship/api-key-data-source

Conversation

@IlyaasK

@IlyaasK IlyaasK commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add the read-only kernel_api_key data source for masked API-key metadata by canonical ID or byte-exact name. Register it with the provider, document it, add a lookup example, and include focused unit and opt-in acceptance coverage.

Scope

This PR adds one data source only. It does not add an API-key resource, create/rotate actions, runtime operations, or direct HTTP fallback code.

API contract

The tagged Kernel Go SDK v0.76.0 exposes organization-scoped masked Get and paginated List methods. List query is substring matching, so the provider scans every non-deleted result page, deduplicates canonical IDs, applies byte-exact name equality, and reports zero or multiple matches instead of selecting by list order. Provider project_id is deliberately not sent to these organization endpoints.

Terraform state semantics

The data source accepts exactly one of id or name. State contains canonical identity, masked key metadata, optional project metadata, timestamps, and creator metadata. Deleted keys and malformed API responses are rejected. Expired but non-deleted keys remain readable according to the API status contract. Data sources do not support import.

Sensitive data

masked_key is marked sensitive. Plaintext values returned by fixture creation are never used, logged, placed in Terraform configuration, or stored in state. No rotate method is exposed by the provider wrapper.

Verification

  • gofmt -l cmd internal
  • go test -short -count=1 -timeout=2m ./...
  • go vet ./...
  • terraform fmt -check -recursive examples
  • bash scripts/check-docs.sh
  • bash scripts/check-examples.sh
  • bash scripts/check-markdown-links.sh

The opt-in acceptance test creates a uniquely named project-scoped key with an organization-wide administrative credential, reads it by ID and exact name, verifies masked/no-drift state, deletes it, and verifies coded absence. It was not run locally because live credentials are unavailable; it remains a manual release gate.

Deferred concerns

The kernel_api_key resource remains blocked on replayable Create/Rotate idempotency and a reliable way to prevent managing or deleting the key currently authenticating Terraform. Those blockers remain documented in docs/api-key-state.md.

This PR does not resolve a GitHub issue.


Note

Medium Risk
Introduces organization-scoped credential metadata reads and sensitive masked state, but read-only with no plaintext or rotation; main risk is lookup/pagination correctness and ambiguous name handling after rotation.

Overview
Adds the read-only kernel_api_key data source so Terraform can resolve masked API-key metadata by canonical id or byte-exact name (exactly one selector). State exposes identity, project metadata, timestamps, creator fields, and sensitive masked_key only—no plaintext key or rotation/resource fields.

Name lookup uses the SDK’s substring list query with active status, walks all pages, deduplicates by ID, applies byte-exact name equality (workaround until an exact-name list filter ships), and errors on zero or ambiguous matches. internal/kernelclient adds org-scoped Get/List (no provider project_id header on these endpoints) plus Create/Delete for acceptance fixtures; Rotate stays unexposed.

The provider registers the data source; docs, changelog, migration notes, examples/lookups, generated schema docs, and the manual acceptance workflow matrix are updated accordingly. Unit and opt-in acceptance tests cover pagination, ambiguity, malformed responses, and live ID/name reads with cleanup.

Reviewed by Cursor Bugbot for commit f3c4de0. Bugbot is set up for automated code reviews on this repo. Configure here.

@IlyaasK
IlyaasK marked this pull request as ready for review July 11, 2026 22:58
@IlyaasK
IlyaasK requested review from Sayan- and tnsardesai July 11, 2026 22:58
Comment thread internal/datasources/apikey/datasource.go
@IlyaasK
IlyaasK removed request for Sayan- and tnsardesai July 13, 2026 13:25
@IlyaasK
IlyaasK force-pushed the hypeship/deployment-data-source branch from 8a725e7 to 1b58199 Compare July 13, 2026 13:36
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-data-source branch from 2c0f72f to 8aee855 Compare July 13, 2026 13:36
@IlyaasK
IlyaasK force-pushed the hypeship/deployment-data-source branch from 1b58199 to ee22563 Compare July 13, 2026 14:32
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-data-source branch from 8aee855 to 5b55393 Compare July 13, 2026 14:32

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5b55393. Configure here.

Comment thread internal/datasources/apikey/datasource.go
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-data-source branch from 5b55393 to 3f5505e Compare July 13, 2026 15:39
@IlyaasK
IlyaasK force-pushed the hypeship/deployment-data-source branch from ee22563 to 2061aa5 Compare July 13, 2026 15:39
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-data-source branch from 3f5505e to d88ea70 Compare July 20, 2026 19:38
@IlyaasK
IlyaasK force-pushed the hypeship/deployment-data-source branch from 2061aa5 to 932e241 Compare July 20, 2026 19:38
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-data-source branch from d88ea70 to f5cd0ba Compare July 21, 2026 14:46
@IlyaasK
IlyaasK force-pushed the hypeship/deployment-data-source branch from 932e241 to e4e3439 Compare July 21, 2026 14:46
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-data-source branch from f5cd0ba to bdfc3de Compare July 21, 2026 18:10
@IlyaasK
IlyaasK force-pushed the hypeship/deployment-data-source branch from 18bf76f to e5257d1 Compare July 21, 2026 19:51
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-data-source branch from bdfc3de to 099bdff Compare July 21, 2026 19:51
Expose organization-scoped API key metadata without admitting plaintext or API key lifecycle into Terraform. Use the tagged SDK's paginated search and enforce exact-name identity in the provider, with focused unit and opt-in acceptance coverage.
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-data-source branch from 099bdff to f3c4de0 Compare July 21, 2026 20:15
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