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(admin): show duckgres warehouse password once after provisioning (#65671)

Eric Duong50b5dd161e0a
diff --git a/posthog/admin/admins/duckgres_server_admin.py b/posthog/admin/admins/duckgres_server_admin.py
index 6ec43ae6b18b..83f0cd3b3d2c 100644
--- a/posthog/admin/admins/duckgres_server_admin.py
+++ b/posthog/admin/admins/duckgres_server_admin.py
@@ -147,9 +147,34 @@ class DuckgresServerAdmin(admin.ModelAdmin):
resp = managed_warehouse.provision(
team.organization_id, database_name, team.id, table_name, require_enabled=False
)
- self._report(request, resp, f"Provisioned managed warehouse for org {team.organization_id}")
if 200 <= resp.status_code < 300:
- return redirect(reverse("admin:posthog_duckgresserver_changelist"))
+ # The control plane returns the root password exactly once, in this
+ # response; afterwards it's stored only encrypted and can't be read
+ # back. Show it once here. Deliberately NOT routed through the message
+ # framework (which persists to the session/cookie store) or the audit
+ # log — only the action + actor are logged, never the credential.
+ user = cast(User, request.user)
+ logger.info(
+ "admin_managed_warehouse_action",
+ action=f"Provisioned managed warehouse for org {team.organization_id}",
+ triggered_by=user.email,
+ )
+ body = resp.data if isinstance(resp.data, dict) else {}
+ return render(
+ request,
+ "admin/posthog/duckgres_server/provision_result.html",
+ {
+ **self.admin_site.each_context(request),
+ "title": "Managed warehouse provisioned",
+ "organization_id": str(team.organization_id),
+ "team_id": team.id,
+ "connection": managed_warehouse._present_connection(
+ {"database": database_name, "username": body.get("username", "root")}
+ ),
+ "password": body.get("password", ""),
+ },
+ )
+ self._report(request, resp, f"Provisioned managed warehouse for org {team.organization_id}")
return redirect(reverse("admin:posthog_duckgresserver_provision"))
def enable_backfill_view(self, request: HttpRequest, object_id: str) -> HttpResponse:
diff --git a/posthog/admin/test_duckgres_server_admin.py b/posthog/admin/test_duckgres_server_admin.py
index b3181f84813a..d98d7659c635 100644
--- a/posthog/admin/test_duckgres_server_admin.py
+++ b/posthog/admin/test_duckgres_server_admin.py
@@ -92,13 +92,36 @@ class TestDuckgresServerAdminProvision(BaseTest):
"table_name": "prod_events",
},
)
- with patch(f"{MW}.provision", return_value=Response({"status": "ok"}, status=202)) as mock_provision:
- self.admin.provision_view(request)
+ body = {"username": "root", "password": "sup3r-secret-pw"}
+ with patch(f"{MW}.provision", return_value=Response(body, status=202)) as mock_provision:
+ response = self.admin.provision_view(request)
mock_provision.assert_called_once_with(
self.organization.id, "my-warehouse", self.team.id, "prod_events", require_enabled=False
)
- assert any("Provisioned managed warehouse" in m for m in _messages(request))
+ # Success renders the credentials once, in the page body...
+ assert response.status_code == 200
+ assert b"sup3r-secret-pw" in response.content
+ # ...and the password must NOT leak into the message framework (it persists
+ # to the session/cookie store).
+ assert all("sup3r-secret-pw" not in m for m in _messages(request))
+
+ def test_provision_failure_surfaces_error_without_rendering_password(self) -> None:
+ request = self._post(
+ "/admin/posthog/duckgresserver/provision/",
+ {
+ "organization_id": str(self.organization.id),
+ "team_id": str(self.team.id),
+ "database_name": "my-warehouse",
+ "table_name": "prod_events",
+ },
+ )
+ with patch(f"{MW}.provision", return_value=Response({"error": "nope"}, status=400)):
+ response = self.admin.provision_view(request)
+
+ # Failures still flash the error and redirect back to the form.
+ assert response.status_code == 302
+ assert any("Failed (status 400): nope" in m for m in _messages(request))
def test_provision_rejects_team_org_mismatch(self) -> None:
other_org = Organization.objects.create(name="Other")
diff --git a/posthog/templates/admin/posthog/duckgres_server/provision_result.html b/posthog/templates/admin/posthog/duckgres_server/provision_result.html
new file mode 100644
index 000000000000..0ac729a79877
--- /dev/null
+++ b/posthog/templates/admin/posthog/duckgres_server/provision_result.html
@@ -0,0 +1,37 @@
+{% extends "admin/base_site.html" %}
+{% load i18n %}
+
+{% block content %}
+<div style="max-width: 640px;">
+ <p>Provisioned a managed warehouse for organization <code>{{ organization_id }}</code>
+ (first team <code>{{ team_id }}</code>).</p>
+
+ <p style="background: #fff3cd; border: 1px solid #ffe69c; border-radius: 4px; padding: 12px 16px; color: #664d03;">
+ <strong>Save the password now.</strong> The root password is returned by the control plane
+ only once and is stored encrypted afterwards &mdash; it <strong>cannot be retrieved later</strong>.
+ If you lose it, the warehouse must be re-provisioned or its credentials rotated.
+ </p>
+
+ <h2>Connection</h2>
+ <table style="border-collapse: collapse; margin-bottom: 20px;">
+ <tr><th style="text-align: left; padding: 4px 16px 4px 0;">Host</th><td><code>{{ connection.host }}</code></td></tr>
+ <tr><th style="text-align: left; padding: 4px 16px 4px 0;">Port</th><td><code>{{ connection.port }}</code></td></tr>
+ <tr><th style="text-align: left; padding: 4px 16px 4px 0;">Database</th><td><code>{{ connection.database }}</code></td></tr>
+ <tr><th style="text-align: left; padding: 4px 16px 4px 0;">Username</th><td><code>{{ connection.username }}</code></td></tr>
+ </table>
+
+ <h2>Password</h2>
+ {% if password %}
+ <p>Copy this now:</p>
+ <input type="text" readonly value="{{ password }}" onclick="this.select()"
+ style="width: 100%; padding: 8px; font-family: monospace; font-size: 14px;" />
+ {% else %}
+ <p><em>The control plane did not return a password in this response. Retrieve the credentials
+ via the duckgres control plane / 1Password onboarding flow.</em></p>
+ {% endif %}
+
+ <p style="margin-top: 24px;">
+ <a href="{% url 'admin:posthog_duckgresserver_changelist' %}" class="default" style="padding: 8px 16px;">Done</a>
+ </p>
+</div>
+{% endblock %}