Skip to content

Define API key Terraform state design - #84

Open
IlyaasK wants to merge 1 commit into
hypeship/app-data-sourcefrom
hypeship/api-key-state-design
Open

Define API key Terraform state design#84
IlyaasK wants to merge 1 commit into
hypeship/app-data-sourcefrom
hypeship/api-key-state-design

Conversation

@IlyaasK

@IlyaasK IlyaasK commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

Defines the Terraform state and lifecycle boundary for future Kernel API-key support.

  • Documents plaintext-once, masked-read, sensitive-state, rotation, deletion, project-scope, and metadata-only import semantics.
  • Defines deterministic null, empty, lifetime, name-normalization, exact-lookup, and retained-rotation-history behavior.
  • Links the accepted state design from the v1 architecture.
  • Separates the safe masked kernel_api_key data source from the blocked kernel_api_key resource.

Why this is v1 work

API keys are durable configuration, but their one-time plaintext and ability to authenticate the provider make them higher risk than ordinary metadata resources. v1 requires an accepted state and recovery model before lifecycle code is added.

Resource and data-source scope

This PR is documentation only. It does not register a resource or data source and makes no API, SDK, provider, or state changes.

The masked metadata data source may proceed after a tagged SDK exposes the API's exact-name list filter. The resource remains deferred.

API contract

The latest tagged Go SDK, v0.76.0, exposes API-key Create, Get, Update, List, Delete, and Rotate. Reads are masked; Create and Rotate return plaintext once. Rotate creates a new canonical ID, clamps old-key grace to its existing expiration, and retains the expired old row as non-deleted history. Names are non-unique, and the API's exact filter uses case- and accent-insensitive database collation.

The pending v0.77.0 SDK release generates the exact-name list field. This provider will continue to use the SDK only.

Terraform state semantics

The future resource model distinguishes readable durable metadata from provider-preserved intent:

  • key is sensitive computed plaintext preserved after Create or Rotate and null after import.
  • masked_key, creator, project metadata, and timestamps come from durable reads.
  • rotation_keeper is the only rotation trigger.
  • rename occurs before rotation so the new key copies the desired name.
  • project scope resolves through resource override, provider default, authenticated-key binding, then organization-wide scope.
  • exact-name data-source lookup post-filters byte-for-byte and diagnoses ambiguity.

Sensitive field handling

Terraform sensitivity controls display, not backend encryption. The design requires an encrypted, access-controlled state backend because plaintext remains in state history. Masked reads never replace plaintext state, and import never claims to recover plaintext.

Import behavior

Future resource import accepts the canonical API-key ID and reads masked metadata only. Plaintext, the original relative lifetime, and prior rotation keeper remain unset. A keeper configured after import is an explicit first rotation.

Verification

Passed locally:

  • gofmt -l cmd internal
  • go test -short -timeout=2m ./...
  • go vet ./...
  • go mod verify
  • go mod tidy -diff
  • terraform fmt -check -recursive examples
  • bash scripts/check-docs.sh
  • bash scripts/check-markdown-links.sh
  • git diff --check

Acceptance status

No acceptance test applies to this documentation-only PR. The design records the required future matrix for Create, Read, rename, rotation, import, scope, historical rows, lifetime edges, deletion, and self-use safety.

Deferred concerns

The resource must not ship until all three gates are met:

  • replayable Create and Rotate idempotency, including plaintext response replay and a token that survives failed applies;
  • a stable current-key self-rotation guard;
  • authoritative effective project-scope metadata for the authenticating key.

The masked data source waits only for the tagged exact-name SDK surface.

GitHub issues

This PR does not resolve an existing GitHub issue.


Note

Low Risk
Documentation-only changes with no runtime, state, or authentication behavior.

Overview
This PR is documentation only—no provider, SDK, or API code.

It adds docs/api-key-state.md, which accepts the future kernel_api_key Terraform state model (sensitive plaintext preservation, rotation_keeper-driven rotation, project-scope resolution, metadata-only import) and spells out lifecycle, validation, and safety rules aligned with the current Kernel API/SDK (v0.76.0, pending v0.77.0 exact-name list).

It defers the resource until replayable Create/Rotate idempotency and a current-key self-rotation guard with effective project-scope metadata exist, while allowing the masked kernel_api_key data source after a tagged SDK exposes the exact-name filter.

docs/architecture.md now points v1 readers at that design doc and restates the same unblock vs. proceed split for API-key work.

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

@IlyaasK
IlyaasK requested review from Sayan- and tnsardesai July 11, 2026 15:56
@IlyaasK
IlyaasK marked this pull request as ready for review July 11, 2026 15:59
@IlyaasK
IlyaasK removed request for Sayan- and tnsardesai July 13, 2026 13:25
@IlyaasK
IlyaasK force-pushed the hypeship/app-data-source branch from e741e1a to ae07bda Compare July 13, 2026 13:35
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-state-design branch 3 times, most recently from d2751dc to 6bf88e0 Compare July 13, 2026 15:39
@IlyaasK
IlyaasK force-pushed the hypeship/app-data-source branch from aae651a to 3a87f31 Compare July 13, 2026 15:39
@IlyaasK
IlyaasK force-pushed the hypeship/app-data-source branch from 3a87f31 to 2fdba56 Compare July 20, 2026 19:38
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-state-design branch from 6bf88e0 to 12ca1a6 Compare July 20, 2026 19:38

@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.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 12ca1a6. Configure here.

Comment thread docs/api-key-state.md
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-state-design branch from 12ca1a6 to f7b91b9 Compare July 21, 2026 14:46
@IlyaasK
IlyaasK force-pushed the hypeship/app-data-source branch from 2a84554 to eac44ec Compare July 21, 2026 18:10
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-state-design branch from f7b91b9 to 91aa9cf Compare July 21, 2026 18:10
@IlyaasK
IlyaasK force-pushed the hypeship/app-data-source branch from eac44ec to eab41e8 Compare July 21, 2026 19:51
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-state-design branch from 91aa9cf to cc2e49b Compare July 21, 2026 19:51
@IlyaasK
IlyaasK force-pushed the hypeship/api-key-state-design branch from cc2e49b to 7c330ea 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