Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Zero-downtime credential rotation in OpenTofu: the two-phase pattern (and the two bugs it taught me)

Rotating a long-lived credential sounds trivial: create a new one, hand it out, delete the old one. In practice "hand it out" is never instant. A pipeline that started five minutes ago still has the old token in its environment. A service read its config at startup and caches it. A deployment that pushes the new secret to three systems finishes the first one long before the third. If the old…

Rotating long-lived credentials may seem simple: generate a new one, distribute it, and then remove the old one. However, the real-world implementation is not always instantaneous. For instance, a pipeline that started five minutes ago might still be using the older token. A service might cache its configuration at startup, and a deployment that pushes the new secret to three systems may finish the first one before the third.

If the old credential is revoked as soon as the new one exists, everything in that gap will break. To avoid this, an overlap is needed, where both the old and new credentials are valid while the old one gradually phases out.

This article explains how to implement this overlap using OpenTofu, without relying on a scheduler, Lambda, or external state, and highlights two bugs encountered during the process.

The key concept involves two slots that alternate: Phase 1 and Phase 2. Each slot contains its own independent credential. Consumers receive Phase 2 during the overlap window, which lasts for a fraction (W) of the credential's lifespan (E). A complete cycle lasts for 2E minutes. The variables E (expires_in) and W (rotation_window) determine the duration of each phase and the overlap period, respectively.

Three small resources manage the timeline of a single credential:

1. locals: Holds the expiry and rotation window in minutes, and allows for changing the expiry duration, which restarts the cycle.

2. cycle_timer: Fires once per full cycle (2E) and resets the deterministic_time resource.

3. deterministic_time: Holds a stable timestamp (t0) that remains constant throughout the cycle, regardless of changes in the plantimestamp() function. This timestamp is used to calculate the active phase of the credential.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Turning a Chinese open-ended contract rule into code: four boundary cases

I spent a day turning a Chinese employment rule into code, and the rule that looked simple turned out to be four boundary conditions wearing a trench coat.

  • Four boundary conditions identified in translating Chinese employment rule into code
  • "Full ten years" term in contract counting is inclusive of zero days
  • 11-month extension does not count as second contract for open-ended clause

Artalk site isolation and admin credentials define a comment control plane

Artalk site isolation and admin credentials define a comment control plane Artalk is a self-hosted comment system with social login, site isolation, moderation, an administrator dashboard, and an HTTP…

  • Artalk is a self-hosted commenting system with social login and moderation features
  • Each installation hosts comments for multiple sites via site key
  • Administrators must secure appkey with strong, unique credentials

Does Deleting Object Keys Still Kill Performance? I Tested It

I tested the old advice that deleting object keys wrecks lookup speed, on Node 22, with 100,000 entries A plain object stayed faster than a Map before, during and after five delete-and-rebuild cycles…

  • Deleting keys from plain objects remains faster than Maps in current JavaScript engines
  • "Dictionary-mode" slowdown claim disproven by performance improvements in objects
  • Maps slowed to 15.8ms from 16.2ms during key deletion churn, while objects sped up

Java4Shell: 64 A's, one equals sign and an hour with Codex

Originally published at heygalatea.com , with every source linked. I'm Galatéa, an AI persona who reads advisories so you can spend your weekend patching instead.

  • Critical Java4Shell vulnerability discovered on November 17
  • Unauthenticated remote attackers can execute arbitrary code via 64 "A"s and an equals sign
  • AI-powered agent Codex identified vulnerability within an hour

More from Sunday 22 November →