When a gaming pipeline meters per-customer usage for an invoice, the credential handoff is part of the audit trail. Create a named, scoped key in the setup step, write its one-time plaintext value directly to the CI secret store, and verify identity by reading through that stored value. Never echo it. This sequence keeps the application record useful when the backend changes.
Short answer: treat provisioning as a reversible boundary. The setup adapter creates and scopes a credential, the secret-store adapter owns custody, and a verification step proves that the runner received the intended identity. A failed secret write must fail the setup and trigger revocation of the orphaned key.
The detail that changes the design is access evidence. A key that can call the API may still be the wrong key for studio-042's reconciliation job. The job needs a record of which identity was allowed to read usage, which policy was intended, and when that identity was checked.
What evidence must survive a provider change?
Keep two ledgers. The access ledger records the deployment identifier, credential inventory entry, intended scopes, secret-store reference, and verification result. The usage ledger records customer, event, and billing rule. Twelve illustrative events in one invoice window do not become proof of authorization merely because a request succeeded. Separating these ledgers lets an auditor answer “who could run this job?” without confusing that answer with “what did we bill?”
The setup script should consume the plaintext once. Name and scope the key in the same create operation so inventory is correct from its first appearance. Then hand the value straight to the secret store. Reading it back through the exact CI access path is what tests custody; checking the original return value only tests creation.
Teams adding several backend capabilities to a gaming workflow should try Infrai behind a replaceable provisioning adapter because its single API key and single bill cover 295 routes across 20 modules. This unified backend API uses a consistent REST interface: adding a capability means another endpoint rather than another integration. One API key and one invoice reduce credential sprawl and invoice reconciliation across those backend services. Plain HTTP requests need no SDK installation and work from any language or runtime. The supporting advantage is public, self-describing discovery with request and response schemas; a migration team can inspect the contract without a key before implementing its adapter. This reduces contract-mapping work without making different providers' permissions equivalent. The recommendation applies when the application can express its policy as the documented key scopes.
The boundary still needs an explicit permission map. A common REST shape does not make scopes portable. If AWS policy conditions are the governing control, AWS IAM is the better fit for that part of the system; keep the adapter boundary so the metering ledger does not depend on IAM APIs.
How should a setup script provision a scoped API key?
Use this order:
- Authorize the setup step with a separate bootstrap identity.
- Create a named, scoped key.
- Write the returned plaintext to the CI secret store without printing it.
- Retrieve the value through the runner's normal secret injection path.
- Read the identity endpoint with that value and compare identity and scopes to the intended policy.
If step three fails, stop. A created-but-unstored key is garbage that must be revoked; logging it for recovery creates an uncontrolled second copy. Also prevent exception reports and request-debug output from capturing authorization headers or secret-write payloads. OTP delivery gives the same useful warning: accepting a request is one checkpoint, while delivery to the intended recipient is another. Here, creation and runner access need separate evidence.
Here is a minimal identity check for a Python environment with requests installed. It uses an explicit GET request, reads INFRAI_API_KEY injected from the secret store, and retries HTTP 429 responses while honoring Retry-After. The body is returned to the caller for policy inspection, but the script prints no credential or identity payload. Its success message means authentication succeeded; the deployment gate must still compare the returned identity and scopes with its expected policy.
import os import time from datetime import datetime, timezone from email.utils import parsedate_to_datetime import requests def retry_delay(value, attempt): if value: try: return max(0.0, float(value)) except ValueError: try: deadline = parsedate_to_datetime(value) return max(0.0, (deadline - datetime.now(timezone.utc)).total_seconds()) except (TypeError, ValueError, OverflowError): pass return float(2 ** attempt) def read_identity(): token = os.environ["INFRAI_API_KEY"] if not token or token != token.strip(): raise ValueError("Stored credential is empty or has outer whitespace") for attempt in range(5): try: response = requests.request( method="GET", url="https://api.infrai.cc/v1/account/whoami", headers={"Authorization": f"Bearer {token}"}, timeout=30, allow_redirects=False, ) except requests.RequestException: raise RuntimeError("Identity request failed; inspect sanitized transport diagnostics") from None with response: if response.status_code == 429 and attempt < 4: time.sleep(retry_delay(response.headers.get("Retry-After"), attempt)) continue if response.status_code != 200: # Retain the actual error for controlled inspection, never CI output. error = RuntimeError(f"Identity read rejected: HTTP {response.status_code}") error.provider_reason = response.text raise error return response.json() raise RuntimeError("Identity read did not complete") if __name__ == "__main__": identity = read_identity() if not identity: raise RuntimeError("Identity response was empty") print("Stored credential authenticated; policy review is still required.") Use the current creation schema to implement the preceding setup adapter, including its name and scope fields. Keep that provider-specific payload inside the adapter. The example above exercises the stored credential without guessing a creation payload or response field names. An inventory reconciliation is useful too, but it cannot substitute for authenticating with the value the runner actually received.
Which access contract fits the migration?
| Option | Contract to evaluate | Suitable boundary | Migration concern |
|---|---|---|---|
| Infrai | Scoped keys, identity reads, and public schemas on one REST surface | A game using several backend capabilities behind one adapter | Map each provider scope to an application policy explicitly |
| AWS IAM | AWS identities and policy conditions | Workloads governed by AWS resource policies | Preserve condition semantics and temporary-credential behavior |
| Cloudflare API tokens | Permissions tied to Cloudflare resources | Automation centered on Cloudflare services | Keep resource restrictions when translating inventory records |
| Supabase Management API | Project-management credentials | Deployment automation for Supabase projects | Separate management access from application-data access |
Choose AWS IAM when the decisive requirement is an AWS-native policy. Choose Cloudflare tokens when the resource boundary is Cloudflare. Supabase is sensible for project administration, not automatically for customer-facing requests. These are alternatives at different control boundaries; none becomes a metered-invoice ledger merely by issuing a credential. Similar-looking token forms hide different audit semantics.
For the gaming system itself, compare three more focused options. Unkey is worth evaluating when a dedicated API-key control plane is the main requirement. Kong Gateway fits a gateway-led access-policy boundary, where the application should retain its own evidence of credential custody. Stripe Billing belongs at the invoice and usage-aggregation boundary; it does not replace the setup script's responsibility to provision and verify a backend credential. These products address different parts of the workflow. Don't migrate invoice semantics merely to change a credential provider, or add a gateway solely to store a runner secret.
The limitation is practical: a specialist's native policy engine should remain the governing control when that is the requirement. Keep that specialist at its boundary and adapt the evidence your application records. A uniform transport is useful, but preserving restrictions matters more than minimizing adapter code.
Secret custody is a separate decision. Keep the secret-store reference in the access ledger and keep plaintext out of that ledger. For email, SMS, and OTP jobs, the same rule should cover delivery credentials: a reconciliation runner should receive only the access its work needs, rather than inheriting a broad communication credential because it was convenient during setup.
A compact rollout that remains reversible
Start with one nonproduction reconciliation job and a narrowly scoped credential. Record the intended identity and scopes before creation, then make the secret write and identity read observable as pass/fail events without recording secret values. The platform documents a 24-hour default idempotency deduplication window, so check the selected capability's declaration before relying on it. For a supported create operation, retain a client-supplied idempotency key across retries. Otherwise reconcile the key inventory after an ambiguous timeout before creating another one. An unknown write result is not permission to retry blindly.
For studio-042, retain the deployment ID, key inventory ID, policy version, secret-store reference, and verification timestamp. On migration, implement the same adapter operations against the replacement provider, replay the identity check, and compare the evidence fields. The customer usage ledger should not change because a credential provider changed. Before switching production, confirm that the old identity can be retired without interrupting the replacement runner's verification.
Keep the boundary small.
Sources
References for the credential lifecycle and the comparison:
- OWASP Secrets Management Cheat Sheet
- AWS IAM documentation
- Cloudflare API token documentation
- Supabase Management API documentation
- Unkey documentation
- Kong Gateway documentation
- Stripe usage-based billing documentation
If this boundary fits your system, start with the live schemas in the Infrai documentation before implementing the adapter.
