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.

feat(hobby): give recording-api a dedicated jwt key (#122981)

Tom Piccirello3dcce7bc7490
diff --git a/bin/deploy-hobby b/bin/deploy-hobby
index a5cf2184e1a6..d5ac67b4c0d5 100755
--- a/bin/deploy-hobby
+++ b/bin/deploy-hobby
@@ -166,11 +166,14 @@ else
BROWSERLESS_SECRET=$(openssl rand -hex 32)
# Dedicated token for Django -> feature-flags calls, for the same reason.
INTERNAL_REQUEST_TOKEN=$(openssl rand -hex 32)
+ # Dedicated key for the tokens Django signs for recording-api, for the same reason.
+ RECORDING_API_JWT_SECRET=$(openssl rand -hex 32)
cat > .env <<EOF
POSTHOG_SECRET=$POSTHOG_SECRET
ENCRYPTION_SALT_KEYS=$ENCRYPTION_SALT_KEYS
BROWSERLESS_SECRET=$BROWSERLESS_SECRET
INTERNAL_REQUEST_TOKEN=$INTERNAL_REQUEST_TOKEN
+RECORDING_API_JWT_SECRET=$RECORDING_API_JWT_SECRET
DOMAIN=$DOMAIN
TLS_BLOCK=$TLS_BLOCK
REGISTRY_URL=$REGISTRY_URL
diff --git a/bin/hobby-installer/core/env.go b/bin/hobby-installer/core/env.go
index 071a05dae666..360afffb5c5f 100644
--- a/bin/hobby-installer/core/env.go
+++ b/bin/hobby-installer/core/env.go
@@ -11,7 +11,7 @@ import (
// Service-to-service secrets that each get their own random value, so a leak from one
// container cannot yield POSTHOG_SECRET, which is Django's SECRET_KEY.
-var dedicatedSecretKeys = []string{"INTERNAL_REQUEST_TOKEN", "BROWSERLESS_SECRET"}
+var dedicatedSecretKeys = []string{"INTERNAL_REQUEST_TOKEN", "BROWSERLESS_SECRET", "RECORDING_API_JWT_SECRET"}
type EnvConfig struct {
PosthogSecret string
diff --git a/bin/hobby-installer/core/env_test.go b/bin/hobby-installer/core/env_test.go
index 86fe09f49eab..0f02de094dbd 100644
--- a/bin/hobby-installer/core/env_test.go
+++ b/bin/hobby-installer/core/env_test.go
@@ -7,7 +7,7 @@ import (
)
func TestDedicatedSecretsAreGeneratedAndKept(t *testing.T) {
- for _, key := range []string{"INTERNAL_REQUEST_TOKEN", "BROWSERLESS_SECRET"} {
+ for _, key := range []string{"INTERNAL_REQUEST_TOKEN", "BROWSERLESS_SECRET", "RECORDING_API_JWT_SECRET"} {
cases := []struct {
name string
existing string
diff --git a/bin/upgrade-hobby b/bin/upgrade-hobby
index d018d6704572..3fd9f3e59b05 100755
--- a/bin/upgrade-hobby
+++ b/bin/upgrade-hobby
@@ -164,7 +164,7 @@ fi
# Service-to-service secrets that each get their own random value, so a leak from one container
# cannot yield POSTHOG_SECRET (Django's SECRET_KEY). Installs from before a secret existed have
# none, so add it. Keep this list in step with dedicatedSecretKeys in bin/hobby-installer.
-for key in INTERNAL_REQUEST_TOKEN BROWSERLESS_SECRET; do
+for key in INTERNAL_REQUEST_TOKEN BROWSERLESS_SECRET RECORDING_API_JWT_SECRET; do
if ! grep -qE "^$key=.+" .env; then
echo "$key=$(openssl rand -hex 32)" >> .env
echo "Added missing $key to .env file"
diff --git a/docker-compose.hobby.yml b/docker-compose.hobby.yml
index 43a6cb61d42f..55779d970747 100644
--- a/docker-compose.hobby.yml
+++ b/docker-compose.hobby.yml
@@ -110,6 +110,7 @@ services:
OBJECT_STORAGE_ENABLED: true
RECORDING_API_URL: http://recording-api:6738
INTERNAL_API_SECRET: ${INTERNAL_API_SECRET:-$POSTHOG_SECRET}
+ RECORDING_API_JWT_SECRET: ${RECORDING_API_JWT_SECRET:-}
ENCRYPTION_SALT_KEYS: $ENCRYPTION_SALT_KEYS
POSTHOG_SKIP_MIGRATION_CHECKS: '1'
PERSONHOG_ADDR: 'personhog-router:50052'
@@ -176,6 +177,7 @@ services:
OBJECT_STORAGE_ENABLED: true
RECORDING_API_URL: http://recording-api:6738
INTERNAL_API_SECRET: ${INTERNAL_API_SECRET:-$POSTHOG_SECRET}
+ RECORDING_API_JWT_SECRET: ${RECORDING_API_JWT_SECRET:-}
ENCRYPTION_SALT_KEYS: $ENCRYPTION_SALT_KEYS
OTEL_SERVICE_NAME: 'posthog'
OTEL_EXPORTER_OTLP_ENDPOINT: ''
@@ -309,9 +311,11 @@ services:
SESSION_RECORDING_V2_S3_SECRET_ACCESS_KEY: 'any'
SESSION_RECORDING_V2_S3_ENDPOINT: http://seaweedfs:8333
ENCRYPTION_SALT_KEYS: $ENCRYPTION_SALT_KEYS
- # Must resolve to the same value as the web and worker services, which send it as
- # X-Internal-Api-Secret. The JWT signing secret is deliberately left unset here, so hobby
- # stays on the legacy shared secret until that scheme is rolled out.
+ # Both must resolve to the same values as on the web, worker and temporal-django-worker
+ # services. Those services sign a team-scoped token with RECORDING_API_JWT_SECRET, and
+ # this service verifies it. They also send INTERNAL_API_SECRET as X-Internal-Api-Secret,
+ # which this service still accepts in place of a token.
+ RECORDING_API_JWT_SECRET: ${RECORDING_API_JWT_SECRET:-}
INTERNAL_API_SECRET: ${INTERNAL_API_SECRET:-$POSTHOG_SECRET}
depends_on:
- db
@@ -520,10 +524,11 @@ services:
HEATMAP_BROWSERLESS_TOKEN: ${BROWSERLESS_SECRET:-$POSTHOG_SECRET}
HEATMAP_BROWSERLESS_SCREENSHOT_COOKIES_ENABLED: ${HEATMAP_BROWSERLESS_SCREENSHOT_COOKIES_ENABLED:-false}
# This worker runs the recording deletion Temporal activities, which call
- # recording-api. Without these two the calls go out unauthenticated and
- # recording-api rejects them with a 401.
+ # recording-api. Without the URL and a credential the calls go out unauthenticated
+ # and recording-api rejects them with a 401.
RECORDING_API_URL: http://recording-api:6738
INTERNAL_API_SECRET: ${INTERNAL_API_SECRET:-$POSTHOG_SECRET}
+ RECORDING_API_JWT_SECRET: ${RECORDING_API_JWT_SECRET:-}
PERSONHOG_ADDR: 'personhog-router:50052'
PERSONHOG_ENABLED: 'true'
# Point Django at the Rust feature-flags container; the setting