fix(machine-identity): fall back to .infisical.json for project ID - #368
fix(machine-identity): fall back to .infisical.json for project ID#368akramcodez wants to merge 1 commit into
Conversation
📝 Contributor License Agreement requiredBefore this PR can merge, every contributor must sign the Infisical CLA. Still needs to sign: Once everyone has signed, the check updates automatically — no need to close and reopen the PR. |
|
| Filename | Overview |
|---|---|
| packages/util/config.go | Adds explicit-ID-first workspace resolution with existing directory-based and ancestor-search config readers; no actionable defect found. |
| packages/util/secrets.go | Uses the shared fallback before universal-auth secret retrieval while leaving service-token and interactive-login behavior unchanged. |
| packages/util/folders.go | Adds equivalent workspace fallback for universal-auth folder retrieval; the current command path correctly uses cwd/ancestor discovery. |
| packages/models/cli.go | Adds an optional project-config directory field to folder retrieval parameters without changing serialized contracts. |
| packages/util/config_test.go | Covers explicit precedence, local and parent discovery, custom directories, and missing or empty configuration. |
| packages/util/machine_identity_test.go | Verifies the resolved project identifier sent by secret and folder requests and confirms explicit IDs take precedence. |
Reviews (1): Last reviewed commit: "fix(machine-identity): fall back to .inf..." | Re-trigger Greptile
|
PTAL @saifsmailbox98 thanks :) |

Description 📣
Fixes #365
When authenticating with machine identity (via
INFISICAL_UNIVERSAL_AUTH_ACCESS_TOKENor a universal-auth access token) without passing--projectId, the CLI was unconditionally exiting with:This was wrong. The human-login path already falls back to
.infisical.jsonwhen--projectIdis missing - the machine identity path was the only one that didn't, forcing every machine-identity user to always pass--projectIdeven after runninginfisical init.Changes:
ResolveWorkspaceIdForMachineIdentity(projectConfigFilePath, explicitWorkspaceId string)helper inconfig.go- returns the explicit value if set, otherwise readsworkspaceIdfrom.infisical.json(walking up from cwd), and errors if neither resolvesUniversalAuthAccessTokenbranch ofGetAllEnvironmentVariables(secrets.go)GetAllFolders(folders.go)ProjectConfigFilePathfield toGetAllFoldersParametersfor parity with the secrets pathType ✨
Tests 🛠️
Unit tests -
packages/util/config_test.go(TestResolveWorkspaceIdForMachineIdentity, 8 subtests):--projectIdwins over file.infisical.jsonin cwd.infisical.jsonprojectConfigFilePathwhen providedworkspaceIdfield is empty in fileIntegration tests -
packages/util/machine_identity_test.go(3 tests usinghttptest.NewServerto assert what the API actually receives on the wire):TestGetAllEnvironmentVariables_MachineIdentityFallsBackToConfig- no--projectId, workspace id is read from.infisical.jsonand forwarded to APITestGetAllEnvironmentVariables_MachineIdentityFlagWins- explicit--projectIdoverrides the fileTestGetAllFolders_MachineIdentityFallsBackToConfig- same fallback verified for the folders endpointAlso verified: