Repository navigation
PC-5090: don't let a packaged .env override job-injected env vars - #1965
Draft
al3xanndru wants to merge 1 commit into
Draft
al3xanndru wants to merge 1 commit into
al3xanndru wants to merge 1 commit into
Conversation
In a robot/Serverless job (UIPATH_JOB_KEY set), load the project .env with override=False so a .env shipped in the package cannot replace the injected UIPATH_URL / access token, and warn naming the conflicting keys. Local runs keep override=True.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Problem
PC-5090: the
uipathCLI loads<cwd>/.envwithload_dotenv(..., override=True)(packages/uipath/src/uipath/_cli/__init__.py,load_environment_variables). When a coded package ships a developer'scontent/.env, that filereplaces the identity Serverless/the robot injects for the job (
UIPATH_URL,UIPATH_ACCESS_TOKEN, …).Seen on EU staging (DRI triages SRE-669104, SRE-673154, SRE-673289, SRE-674307, SRE-679241,
SRE-688965):
Invoice.processing.Agent.update-invoice-status(1.0.0 / 1.0.2 / 1.0.14) in 4 tenantsacross 2 orgs ships a
.env. The job's environment had the rightUIPATH_URL=https://staging.uipath.com/<job-org>/<job-tenant>, but every SDK call went tostaging.uipath.com/invoiceprocessing/{dennis,WilcoAP,E2ePR618R}with a developer JWT that hadexpired in June. The result was elements_ 401/404 and llmopstenant_ 401. These processes have never
succeeded (one has 14,222 faults since 2026-06-30). The error looks like a wrong-tenant 404/401, not
like a configuration problem. With a live token, the job would have authenticated in another
organization as that developer.
Root cause
override=Trueis right on a developer machine: afteruipath authrewrites.env, it wins overstale values exported in the shell. In a job it is wrong. The platform-injected environment is the
source of truth there, and the
.envcomes from whoever built the package.Change
load_environment_variables()checksUIPATH_JOB_KEYin the process environment before it readsthe
.env. The robot and Serverless set that variable for every job.load_dotenv(override=False). Injected variables win, and.envkeys thejob did not inject still load, so package settings like
MY_SETTINGkeep working.override=True)..envsets a key to a value that differs from the injected one, the CLI logs onewarning (logger
uipath._cli, to stderr). The warning names the keys but not the values, sono token reaches the job logs:
Ignoring 2 values in /…/.env that differ from the job's environment: UIPATH_ACCESS_TOKEN, UIPATH_URL. Remove the .env from the package.uipathversion goes from 2.14.44 to 2.14.45 (pyproject.tomlanduv.lock).The job check uses the environment as it was before the
.envloads. AUIPATH_JOB_KEYwritteninto a
.env(for example for remote debugging) therefore does not switch a local run into jobmode.
Tests
New file:
packages/uipath/tests/cli/test_load_environment_variables.py..envstill overrides the shell.envUIPATH_URLand token are kept; non-conflicting.envkeys still load; one warning lists the keys and contains no values.envagrees.envResults:
pytest tests/cli(packages/uipath): 1535 passed, 1 xfailed (pre-existing, unrelated marker intest_server_job_core.py); the 4 new tests pass alone and in the suiteruff check .,ruff format --check .,mypyon the changed files: all clean (All checks passed!,345 files already formatted, mypyno issues found,scripts/lint_httpx_client.pyno violations)Risks and open questions
.envto replace an injected variable will now get theplatform value. That is the intent of this change. Anyone who really needs a different value
should set it through the process/job environment variables, not a packaged
.env.uipath server(pooled mode): the.envis read once at import time, from the server'sworking directory. This PR does not change that path.
uipath packtime when.envor.uipath/.auth.jsonwould be packaged. The triage tracks that separately (PC-5091).Drafted by the wabbit-dri draft-fixes loop for PC-5090 (draft #1), for a human to review: not ready to merge as is.
🤖 Generated with Claude Code