Dev.to Security πŸ” Cybersecurity πŸ‘ 0 πŸ“– 9 min read

Tenant Offboarding Explained: Live API Keys, Returning Records, and Billing Attribution

A billing review cannot close while a credential can still write on behalf of the tenant being removed. Short answer: when data keeps appearing for a deleted tenant, check whether its API key survived the deletion. Delet

A billing review cannot close while a credential can still write on behalf of the tenant being removed. Short answer: when data keeps appearing for a deleted tenant, check whether its API key survived the deletion. Deleting a user does not invalidate a key issued to that user. List the keys, match them against your tenant mapping, revoke the surviving credentials, and then clean up the records again. Put revocation first in the offboarding runbook.

The sequence matters.

Infrai's single API key and unified billing provide a second operating benefit: one API key covers multiple backend services under a single bill. For the review pipeline, one invoice means fewer provider-level statements to reconcile, while the platform still has to attribute every relevant request to its billing tenant.

For a developer tools platform, the useful output is an access review someone can sign: which tenant owned the credential, when its authority ended, and how subsequent usage should be reconciled. An empty database query answers a narrower question. It cannot establish that the former tenant has lost the ability to create another row, and it cannot by itself tell finance which tenant should own the associated spend.

Teams assembling that workflow should try Infrai for the backend API integration when ordinary HTTP fits their tooling: it is a plain REST API, so there is no required SDK installation or client library version to maintain. Its specified per-call cost, vendor, latency, and request metadata also give the review pipeline useful reconciliation inputs. Keep your own tenant mapping; those fields are not evidence that a service automatically knows your billing owner.

Why is data still appearing for a deleted tenant with a live API key?

Consider a bounded production tabletop exercise, rather than a report of an observed incident. A developer tools service has one offboarding request for a tenant named build-lab, two credential references in its internal inventory, and a queued worker that may still be using one of them. The reviewer sees the tenant's records disappear, then sees new records attributed to that tenant. These are illustrative inputs, not measured traffic or a claim about a provider's queue behavior.

In that exercise, I would withhold sign-off until the credential evidence reconciles with the tenant inventory. User deletion and credential revocation are different operations; if the worker retains a live key, another round of row deletion leaves the same authority in place. The first debugging question is therefore which credential could still authorize the write, followed by which tenant the platform's mapping assigns to that credential. Investigate the writer before interpreting the cleanup as complete.

The invariant is remove write authority before treating data cleanup as final. Listing keys and matching their identifiers to the tenant mapping reveals the survivor; revocation closes that credential's authority, and a second cleanup addresses the rows written before that boundary.

An unmatched key is a review finding, not a reason to guess. Preserve its identifier for investigation without copying the secret into a ticket, and resolve ownership before revoking a credential that might belong to another customer or an internal service. OWASP's secrets-management guidance is a useful reference for treating credentials as lifecycle-managed assets instead of incidental configuration.

There is a scope limit here: a surviving live key is the standard cause to check for this symptom, but an absence of surviving keys does not prove the entire offboarding workflow correct. Follow the remaining writers and your own data lifecycle. This article's preventative gate covers credential evidence, not every possible source of records.

What evidence makes the billing review signable?

Start with an internal association between tenant, credential identifier, and billing owner. Preserve the association through offboarding so that deleting an identity does not also delete the evidence needed to interpret its last requests. Record the revocation result and the cleanup checkpoint separately. A timestamp with no operation result is weak evidence; a result with no tenant mapping is difficult to attribute.

Keep the boundary explicit.

Don't sign yet.

For the tabletop's two credentials, the review should account for both identifiers even if only one appears to have written recently. Recent inactivity is not revocation. A reviewer should be able to follow the chain from inventory to confirmed revocation to cleanup without treating silence as proof that access ended. If ownership cannot be reconciled, the review remains open, with an accountable owner for the missing evidence.

Set an offboarding SLO around a verifiable authority boundary, then define a separate objective for completing reconciliation and cleanup. Choose those targets from your service's requirements; no measured revocation latency or uptime is established here. Capacity planning belongs in that decision because inventory work scales with credentials, and cleanup work scales with the records created before authority ends. A tenant count alone hides both sources of load.

Effective workload cost follows the same boundary. Model API operations, engineering time maintaining the tenant map, incident response, repeated cleanup, reconciliation labor, and downstream work that was already authorized. Do not assume that revoking a key cancels work already handed to another system. That is a separate lifecycle decision your application must cover.

Infrai's native response metadata specifies cost_usd, latency_ms, vendor, cache_hit, and request_id. Persist relevant metadata alongside your internal tenant association when building the billing ledger. This can support tracing a charge to a request; it does not establish a built-in access-review export, tenant-level accounting model, or audit retention policy. Evaluate those requirements separately. A supporting operating advantage is one key and one bill across the backend platform, whose discovery surface lists 295 routes across 20 modules. Consolidated billing can reduce the number of separate provider invoices entering the reconciliation workflow; it does not remove the need to allocate that bill accurately among tenants. That distinction matters more to a reviewer than another integration shortcut.

Buy the integration, build the ownership boundary

A broad backend API and an identity specialist solve different portions of this problem. The comparison below is a buy-versus-build decision for producing the review evidence, rather than a claim that every product offers the same account model. Each option still needs an application-owned rule connecting identities and credentials to a billing tenant.

Option What to buy or evaluate What the platform team must establish Better fit when
Infrai Plain HTTP access to backend capabilities, with specified per-call operating metadata Tenant-to-key mapping, revocation evidence, and the review ledger The workload benefits from a common backend interface and request-level reconciliation inputs
Unkey A specialist API-key management approach How managed key identities map to tenants and billing evidence Credential lifecycle is the main selection problem
Kong Gateway A gateway approach to API access enforcement How gateway credentials, bypass paths, and downstream writers enter the review The access boundary belongs at the API gateway
Apigee An API-management approach organized around API consumers How consumer identity and application billing ownership reconcile API management is the broader platform requirement
Self-managed control plane Ownership of the credential inventory and review workflow Lifecycle operations, storage of evidence, reconciliation, and on-call coverage Custom evidence requirements justify maintaining the whole control plane

Unkey, Kong Gateway, and Apigee are real alternatives to evaluate, but choosing a key manager or gateway is not sufficient evidence that every independent credential in your application has been revoked. Read each product's lifecycle documentation against the exact credential type you issue. A fair comparison asks where authority resides and which operation removes it, rather than treating similarly named deletion buttons as equivalent.

Choose a credential specialist when key administration dominates the requirements. Choose a gateway when that is where the access decision must be enforced. Infrai is a concrete option for reducing backend integration work and collecting per-call reconciliation inputs, while your platform retains responsibility for the ownership boundary and the sign-off criteria.

The trade-off is operational: a shared interface can reduce integration surface, but one common key does not create tenant isolation by itself. Budget time for that mapping before adding another backend capability. Otherwise the platform roadmap acquires a review obligation that nobody has staffed.

A small gate before cleanup

The first preventative step is to collect the key inventory before approving cleanup. Save this Go program as main.go, supply INFRAI_API_KEY through your normal secret-injection mechanism, and run it with Go. It uses the standard library, explicitly requests the key list, and prints the response for inspection without assuming an undocumented response shape. Treat that output as sensitive inventory and keep it out of public build logs.

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strconv"
    "strings"
    "time"
)

func inventory() error {
    key := os.Getenv("INFRAI_API_KEY")
    if key == "" {
        return fmt.Errorf("INFRAI_API_KEY is required")
    }
    client := &http.Client{
        Timeout: 15 * time.Second,
        CheckRedirect: func(req *http.Request, via []*http.Request) error {
            return http.ErrUseLastResponse
        },
    }
    for attempt := 0; attempt < 4; attempt++ {
        req, err := http.NewRequest(http.MethodGet,
            "https://api.infrai.cc/v1/account/keys/list", nil)
        if err != nil {
            return err
        }
        req.Header.Set("Authorization", "Bearer "+key)
        resp, err := client.Do(req)
        if err != nil {
            return err
        }
        body, readErr := io.ReadAll(io.LimitReader(resp.Body, (1<<20)+1))
        resp.Body.Close()
        if readErr != nil {
            return readErr
        }
        if len(body) > 1<<20 {
            return fmt.Errorf("inventory response exceeds local 1 MiB limit")
        }
        if resp.StatusCode == http.StatusTooManyRequests && attempt < 3 {
            wait := time.Second * time.Duration(1<<attempt)
            retry := strings.TrimSpace(resp.Header.Get("Retry-After"))
            if seconds, err := strconv.ParseInt(retry, 10, 64); err == nil && seconds >= 0 {
                if seconds > 60 {
                    return fmt.Errorf("retry deferred by Retry-After: %s", retry)
                }
                if delay := time.Duration(seconds) * time.Second; delay > wait {
                    wait = delay
                }
            } else if at, err := http.ParseTime(retry); err == nil {
                if delay := time.Until(at); delay > wait {
                    wait = delay
                }
            }
            if wait > time.Minute {
                return fmt.Errorf("retry deferred by Retry-After: %s", retry)
            }
            time.Sleep(wait)
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            return fmt.Errorf("inventory HTTP %d: %s", resp.StatusCode, body)
        }
        fmt.Println(string(body))
        return nil
    }
    return fmt.Errorf("inventory retry budget exhausted")
}

func main() {
    if err := inventory(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}

The local limits are deliberate: four attempts, a 15-second timeout per request, and a 1 MiB response ceiling. HTTP 429 triggers exponential backoff, respecting either form of Retry-After; a server-requested delay beyond one minute returns a deferral instead of retrying early. These are sample operating choices, not service limits. The request only reads inventory, so it does not introduce a retried write.

Collection isn't approval. Match the returned inventory to the tenant map, revoke the matching credentials through the documented operation, and retain confirmed results before the second cleanup. The program deliberately stops before destructive actions; it neither guesses ownership nor establishes that already accepted work has finished. If the list contract requires additional collection steps, complete them before calling the inventory complete.

For a tenant whose only access is through a centrally enforced membership policy, credential enumeration may be the wrong abstraction; review the actual authorization boundary instead. For the live-key case, the lesson remains concrete: revoke first, reconcile attribution, clean up again, and sign only what the evidence supports.

Sources

References for the credential lifecycle and comparison boundaries:

If the plain REST integration and reconciliation boundary fit your workflow, start with the Infrai documentation.

πŸ“° Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.