Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions python/envctl_engine/pr_preview_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1967,8 +1967,12 @@ def start(

started_at = utc_now()
expires_at = label_added_at + timedelta(minutes=self.config.ttl_minutes)
repository_preview_env: dict[str, str] = {}
self.apply_repository_preview_env(repository_preview_env, pr_number=pr.number)

def run_import() -> CommandResult:
import_env = self.envctl_command_env(keep_github_tokens=True)
import_env.update(repository_preview_env)
return self.runner.run(
[
self.config.envctl_bin,
Expand All @@ -1981,7 +1985,7 @@ def run_import() -> CommandResult:
],
cwd=self.config.control_repo,
check=False,
env=self.envctl_command_env(keep_github_tokens=True),
env=import_env,
)

import_result = run_import()
Expand Down Expand Up @@ -2081,6 +2085,7 @@ def run_import() -> CommandResult:

start_env = self.envctl_command_env()
start_env.update(pr_preview_start_env_overrides())
start_env.update(repository_preview_env)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve configured preview source secrets

In previews where the runner already exports an ENVCTL_SOURCE_<NAME> that is also listed in the PR's ENVCTL_PREVIEW_GENERATED_SECRETS, this update replaces that configured value with the newly generated one. Before this change apply_repository_preview_env ran against start_env and used setdefault, so supplied source values were preserved; now the helper is called on an empty dict and this line overlays the random values after envctl_command_env()/pr_preview_start_env_overrides(). That breaks pinned or rotated secrets by starting and importing with credentials other than the ones configured on the preview runner.

Useful? React with 👍 / 👎.

start_env.update(self.external_dependency_start_env(external_dependencies))
python_setup_error = ""
try:
Expand All @@ -2105,8 +2110,6 @@ def run_import() -> CommandResult:
start_env["ENVCTL_FRONTEND_ENV__VITE_BACKEND_URL"] = public_urls["backend"]
if public_urls.get("supabase"):
start_env["ENVCTL_FRONTEND_ENV__VITE_SUPABASE_URL"] = public_urls["supabase"]
self.apply_repository_preview_env(start_env, pr_number=pr.number)

start_argv = [
self.config.envctl_bin,
"start",
Expand Down
10 changes: 10 additions & 0 deletions tests/python/runtime/test_pr_preview_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,16 @@ def test_repository_envctl_config_drives_dynamic_public_service_and_secrets(
assert len(generated) == 3
assert all(len(value) >= 48 for value in generated)

import_call = next(call for call in runner.calls if call["argv"][:2] == ["envctl", "import"])
import_env = import_call["env"]
for name in (
"PIPECAT_SERVICE_TOKEN",
"PIPECAT_WEBHOOK_SECRET",
"PIPECAT_STREAM_TOKEN_SECRET",
):
key = f"ENVCTL_SOURCE_{name}"
assert import_env[key] == start_env[key]

state = instance.load_state(789)
assert state is not None
runtime = state.endpoints["additional_services"]["voice-runtime"]
Expand Down
Loading