Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

refactor(credentials-service): send the staged value as incoming on the wire (#116063)

Tom Owers1bae8174f9fb
diff --git a/posthog/credentials_service/client.py b/posthog/credentials_service/client.py
index c8a6405a05ea..de9f82b809a8 100644
--- a/posthog/credentials_service/client.py
+++ b/posthog/credentials_service/client.py
@@ -294,10 +294,7 @@ class CredentialsServiceClient:
resolved[key] = SecretValue(
state=payload.get("state", "steady"),
value=payload.get("value"),
- # `previous` is the wire name for the staged value. It is wrong, and renaming a
- # field both sides read needs a release where each accepts either — so the
- # correction stops at this boundary rather than propagating the wrong idea.
- incoming=payload.get("previous"),
+ incoming=payload.get("incoming"),
)
CREDENTIALS_SERVICE_FETCH_COUNTER.labels(outcome="ok").inc()
diff --git a/posthog/credentials_service/test/test_client.py b/posthog/credentials_service/test/test_client.py
index d55949cd1636..f30d2b597cd0 100644
--- a/posthog/credentials_service/test/test_client.py
+++ b/posthog/credentials_service/test/test_client.py
@@ -106,10 +106,10 @@ class TestCredentialsServiceClient(SimpleTestCase):
self.secrets.get(KEY, CALLER)
def test_get_with_incoming_exposes_the_staged_value_during_a_rotation(self) -> None:
- # The wire still calls it `previous`; it carries the value a rotation has STAGED, which the
- # service accepts but has not made live. A caller retries with it when the provider has
- # already been rotated — not to reach an older value, which is not served at all.
- rotating = {"state": "rotating", "value": "live", "previous": "staged", "version_id": "v1", "fetched_at": "now"}
+ # The staged value is the one a rotation has accepted but not made live. A caller retries
+ # with it when the provider has already been rotated, not to reach an older value, which
+ # is not served at all.
+ rotating = {"state": "rotating", "value": "live", "incoming": "staged", "version_id": "v1", "fetched_at": "now"}
with patch(POST, return_value=FakeResponse(body({KEY: rotating}))):
secret = self.secrets.get_with_incoming(KEY, CALLER)
assert secret.current == "live"
@@ -394,7 +394,7 @@ class TestResolveLogging(SimpleTestCase):
rotating = {
"state": "rotating",
"value": "live",
- "previous": "staged",
+ "incoming": "staged",
"version_id": "v9",
"fetched_at": "now",
}
@@ -446,7 +446,7 @@ class TestResolveLogging(SimpleTestCase):
rotating = {
"state": "rotating",
"value": secret_value,
- "previous": "staged-do-not-log-me",
+ "incoming": "staged-do-not-log-me",
"version_id": "v1",
"fetched_at": "now",
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/common/tests/test_credentials_service.py b/products/warehouse_sources/backend/temporal/data_imports/sources/common/tests/test_credentials_service.py
index 1335d5394e94..30b400927ffd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/common/tests/test_credentials_service.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/common/tests/test_credentials_service.py
@@ -126,7 +126,7 @@ class TestHelper(SimpleTestCase):
KEY: {
"state": "rotating",
"value": "live",
- "previous": "staged",
+ "incoming": "staged",
"version_id": "v2",
"fetched_at": "now",
}
diff --git a/services/credentials-service/README.md b/services/credentials-service/README.md
index fd6258a8dc2a..3e115aa277d3 100644
--- a/services/credentials-service/README.md
+++ b/services/credentials-service/README.md
@@ -56,7 +56,7 @@ one call needed:
"GOOGLE_ADS_APP_CLIENT_SECRET": {
"state": "rotating",
"value": "…",
- "previous": "…",
+ "incoming": "…",
"version_id": "…",
"fetched_at": "…",
},
@@ -169,7 +169,7 @@ pick it up before completing.
| State | Condition | Response |
| ---------- | ------------------------------------------------ | ------------------------------------- |
| `steady` | no `_FALLBACKS` sibling, or it repeats the value | `value` only |
-| `rotating` | the sibling holds a different, staged value | `value` + `previous` (the staged one) |
+| `rotating` | the sibling holds a different, staged value | `value` + `incoming` (the staged one) |
| `recovery` | field named in `CREDENTIALS_RECOVERY_KEYS` | no value; caller raises a typed error |
`recovery` covers a credential that is known-burned with no valid replacement yet. These
diff --git a/services/credentials-service/src/resolve.ts b/services/credentials-service/src/resolve.ts
index 5040e6e95e3b..011a9b6abef3 100644
--- a/services/credentials-service/src/resolve.ts
+++ b/services/credentials-service/src/resolve.ts
@@ -18,13 +18,8 @@ const UNKNOWN_KEY = 'unknown'
export interface WireSecret {
state: string
value?: string
- /**
- * The staged value, still named `previous` on the wire. The name is wrong — it is the
- * incoming value, not the outgoing one — but renaming a field both sides read needs a
- * release where each accepts either, so the internal model is accurate and this boundary
- * lags deliberately.
- */
- previous?: string
+ /** The staged value that a rotation has accepted but not yet made live. */
+ incoming?: string
version_id: string
fetched_at: string
}
@@ -57,7 +52,7 @@ export function resolveKeys(identity: CallerIdentity, mounted: MountedSecrets):
wire.value = secret.value
}
if (secret.incoming !== undefined) {
- wire.previous = secret.incoming
+ wire.incoming = secret.incoming
previousVersionServedTotal.labels({ key }).inc()
}
secrets[key] = wire
diff --git a/services/credentials-service/tests/integration/server.e2e.test.ts b/services/credentials-service/tests/integration/server.e2e.test.ts
index 2456b64a07ef..77936b896896 100644
--- a/services/credentials-service/tests/integration/server.e2e.test.ts
+++ b/services/credentials-service/tests/integration/server.e2e.test.ts
@@ -129,9 +129,13 @@ describe('credentials server end to end', () => {
// Start a rotation on the mount; the running server picks it up on reload.
await writeFile(join(dir, `${KEY}_FALLBACKS`), 'staged-value-2')
await server.reload()
- expect(await (await resolve(port, token)).json()).toMatchObject({
- secrets: { [KEY]: { state: 'rotating', value: 'current-value-1', previous: 'staged-value-2' } },
+ const rotating = (await (await resolve(port, token)).json()) as { secrets: Record<string, unknown> }
+ expect(rotating.secrets[KEY]).toMatchObject({
+ state: 'rotating',
+ value: 'current-value-1',
+ incoming: 'staged-value-2',
})
+ expect(rotating.secrets[KEY]).not.toHaveProperty('previous')
// Completing a rotation is deleting the sibling, and that has to end the
// overlap rather than serving the retired value forever.
@@ -139,6 +143,7 @@ describe('credentials server end to end', () => {
await server.reload()
const settled = (await (await resolve(port, token)).json()) as { secrets: Record<string, unknown> }
expect(settled.secrets[KEY]).toMatchObject({ state: 'steady', value: 'current-value-1' })
+ expect(settled.secrets[KEY]).not.toHaveProperty('incoming')
expect(settled.secrets[KEY]).not.toHaveProperty('previous')
await writeFile(join(dir, 'CREDENTIALS_RECOVERY_KEYS'), BURNED_KEY)
diff --git a/services/credentials-service/tests/unit/resolve.test.ts b/services/credentials-service/tests/unit/resolve.test.ts
index 7240cf7cb1d3..886384d698e3 100644
--- a/services/credentials-service/tests/unit/resolve.test.ts
+++ b/services/credentials-service/tests/unit/resolve.test.ts
@@ -39,13 +39,14 @@ describe('resolve', () => {
const response = resolveKeys(identity(['GOOGLE_ADS_APP_CLIENT_ID', 'GOOGLE_ADS_APP_CLIENT_SECRET']), MOUNTED)
expect(response.secrets['GOOGLE_ADS_APP_CLIENT_ID']).toMatchObject({ state: 'steady', value: 'ga-id' })
- // `previous` is the wire name; it carries the staged (incoming) value. The mismatch is
- // deliberate and documented on WireSecret — the boundary lags the internal rename.
expect(response.secrets['GOOGLE_ADS_APP_CLIENT_SECRET']).toMatchObject({
state: 'rotating',
value: 'ga-live',
- previous: 'ga-staged',
+ incoming: 'ga-staged',
})
+ expect(response.secrets['GOOGLE_ADS_APP_CLIENT_ID']).not.toHaveProperty('incoming')
+ expect(response.secrets['GOOGLE_ADS_APP_CLIENT_SECRET']).not.toHaveProperty('previous')
+ expect(response.secrets['GOOGLE_ADS_APP_CLIENT_ID']).not.toHaveProperty('previous')
})
// THE containment property at this layer: the scope is the identity's key list and