Skip to content

feat: share workspace state within a project - #3939

Open
ktella wants to merge 3 commits into
terrakube-io:mainfrom
ktella:kiran-tella-crdn-project-state-sharing
Open

ktella wants to merge 3 commits into
terrakube-io:mainfrom
ktella:kiran-tella-crdn-project-state-sharing

Conversation

@ktella

@ktella ktella commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What changed and why?

Fixes #3937.

  • Add an opt-in project-wide state-sharing setting and a Liquibase migration defaulting it to false, preserving existing workspace settings.

  • Authorize same-organization, same-project workspace runners in both direct state and Terraform-compatible read paths. Include project members in the effective consumer list and deduplicate existing individual grants.

  • Make project and organization sharing mutually exclusive. Individual grants remain additive and survive scope changes; reject newly added individual grants already covered by project access while preserving existing overlapping grants.

  • Add the project setting and scope switching to the workspace UI, disable already-covered picker options, and clarify removal behavior. Correct the workspace-to-project mapping to allow multiple workspaces in one project.

  • Add focused security, HTTP integration, and UI tests.

  • Disable project access for workspaces without a project and reject new project-sharing enablement without a project in the API. Workspaces can still leave a project and turn off an existing setting.

Testing

Ran:
docker exec -w /workspaces/terrakube kiran-tella-crdn-musical-telegram_devcontainer-terrakube-dev-1 mvn -B -pl api -am '-Dtest=StateServiceSecurityTest,RemoteTfeServiceTest,NewSecurityChecksTest,ProjectStateSharingIntegrationTest' -Dsurefire.failIfNoSpecifiedTests=false test
  PASS before the review fix: 187 tests, 0 failures, 0 errors, 0 skipped.
docker exec -w /workspaces/terrakube/ui kiran-tella-crdn-musical-telegram_devcontainer-terrakube-dev-1 yarn test --runInBand src/domain/Workspaces/Settings/__tests__/SshKeyLockingStateShared.test.tsx
  PASS before the review fix: 14 tests.
git diff --check origin/main...HEAD
  PASS.
Checked:
Local UI/API and Terraform runs against disposable projects and workspaces, as detailed below.

Review fix validation

  • docker exec -w /workspaces/terrakube kiran-tella-crdn-musical-telegram_devcontainer-terrakube-dev-1 mvn -q -pl api -am '-Dtest=NewSecurityChecksTest,ProjectStateSharingIntegrationTest' -Dsurefire.failIfNoSpecifiedTests=false test — PASS: 24 tests.
  • docker exec -w /workspaces/terrakube/ui kiran-tella-crdn-musical-telegram_devcontainer-terrakube-dev-1 yarn test --runInBand src/domain/Workspaces/Settings/__tests__/SshKeyLockingStateShared.test.tsx — PASS: 17 tests.
  • docker exec -w /workspaces/terrakube/ui kiran-tella-crdn-musical-telegram_devcontainer-terrakube-dev-1 yarn eslint src/domain/Workspaces/Settings/StateShared.tsx src/domain/Workspaces/Settings/__tests__/SshKeyLockingStateShared.test.tsx — PASS with one existing console warning.

These tests cover enabling without a project, API and UI behavior, workspace reassignment, disabling an existing setting after project removal, and read-only users.

# Local scenario Result
1 Project access A same-project consumer read the expected output; a different-project consumer was denied.
2 Picker Same-project workspace was disabled; another-project workspace could be added. The API rejected a redundant same-project addition.
3 Individual access A separately granted workspace read the expected output alongside project access.
4 Existing grant An existing same-project grant survived enabling project access, and the workspace read the output.
5 Remove overlapping grant Removing the individual grant left project access effective and the read succeeded.
6 Disable project access The same-project workspace was denied; the separately granted workspace could still read.
7 Organization access Same-organization workspaces in both projects read the output; the cross-organization run was denied during organization discovery, before reaching the state endpoint.
8 Switch scopes Selecting either organization or project access deselected the other; the API rejected enabling both.

Terraform runs used normal executor-issued workspace credentials and an output-only source configuration; disposable workspaces and projects were removed after testing. A dedicated upgrade test against an existing production database was not run.

Visual changes (if applicable)

The State shared settings page adds a project-access checkbox and marks already-covered picker options.

image image image image

Comment on lines +229 to +231
extra="All workspaces in this project, including future workspaces, can read this workspace's state."
>
<Checkbox>{"Share this workspace's state with all workspaces in this project"}</Checkbox>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Projects are optional, so this checkbox also shows up (enabled) on a workspace that isn't in any project. Ticking it clears "Organization access" through onValuesChange, and saving sends globalRemoteState: false, projectRemoteState: true. The backend accepts that, but with getProject() == null neither StateService nor validateWorkspaceIdTokenCanAccessState grants anyone access, so every terraform_remote_state consumer that relied on org-wide sharing starts getting refused, with nothing in the UI saying why.

I'd disable it when there's no project, while still letting someone untick it if it's already on (e.g. the workspace was moved out of its project). !manageWorkspace has to stay in there because an explicit disabled on the Checkbox overrides the form-level disabled.

Suggested change
extra="All workspaces in this project, including future workspaces, can read this workspace's state."
>
<Checkbox>{"Share this workspace's state with all workspaces in this project"}</Checkbox>
extra={
projectId
? "All workspaces in this project, including future workspaces, can read this workspace's state."
: "This workspace is not in a project. Add it to a project to share its state with the project."
}
>
<Checkbox disabled={!manageWorkspace || (!projectId && !workspace.attributes.projectRemoteState)}>
{"Share this workspace's state with all workspaces in this project"}
</Checkbox>

I checked this locally with a small jest test against the PR head. Without a project the checkbox is enabled (that's the bug). With the change it's disabled without a project, enabled inside one, disabled when manageWorkspace is false, and still enabled when it's already on without a project. yarn jest src/domain/Workspaces (18 suites / 158 tests) and prettier/eslint are clean once the fixture below is updated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. Fixed in 23e5274: project access is disabled when the workspace has no project, while an existing setting can still be turned off after project removal. The API also rejects new project-sharing enablement without a project. Added coverage for both paths and manage permissions, and included your co-author credit.

Comment on lines +173 to +178
render(
<WorkspaceStateShared
workspace={workspace({ globalRemoteState: true, projectRemoteState: false })}
manageWorkspace
/>
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test toggles project access on a workspace with no project relationship, which is the exact case above. With that change applied, the fixture needs a project (same pattern as the current.relationships.project test further down):

Suggested change
render(
<WorkspaceStateShared
workspace={workspace({ globalRemoteState: true, projectRemoteState: false })}
manageWorkspace
/>
);
const current = workspace({ globalRemoteState: true, projectRemoteState: false });
current.relationships.project = { data: { id: "project-1" } };
render(<WorkspaceStateShared workspace={current} manageWorkspace />);

@ktella ktella Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the fixture to include a project in 23e5274. I also added UI coverage for workspaces without a project and for disabling an existing setting after project removal.

image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jakegroves @alfespa17 Please review.

@dhananjay6561

Copy link
Copy Markdown
Contributor

@ktella if the suggestion above looks good, applying it with "Commit suggestion" keeps the attribution automatically. If you'd rather write it your own way, could you add this trailer to that commit so I'm credited as co-author?

Co-authored-by: dhananjay6561 <133662894+dhananjay6561@users.noreply.github.com>

@ktella
ktella force-pushed the kiran-tella-crdn-project-state-sharing branch 2 times, most recently from 43f9293 to 56190f7 Compare November 18, 2026 00:21
@dhananjay6561

Copy link
Copy Markdown
Contributor

@ktella thanks for taking the project check and adding the co-author credit, appreciate it! The no-project handling looks good from my side.

@alfespa17

Copy link
Copy Markdown
Member

@ktella this has some merge conflicts, can you help me fixing those?

Kiran Tella and others added 3 commits November 27, 2026 17:16
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: dhananjay6561 <133662894+dhananjay6561@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@ktella
ktella force-pushed the kiran-tella-crdn-project-state-sharing branch from 56190f7 to 78ce32d Compare November 27, 2026 22:18
@ktella
ktella requested a review from Macbet as a code owner November 27, 2026 22:18
@github-actions github-actions Bot added terrakube-ui terrakube-api area/db-migration Touches Liquibase changelogs area/security Touches authentication, tokens or authorization author/contributor Authored by a returning contributor size/L 250-999 lines changed type/feature New functionality labels Nov 27, 2026
@ktella

ktella commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@ktella this has some merge conflicts, can you help me fixing those?

@alfespa17 taken care. Please review now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/db-migration Touches Liquibase changelogs area/security Touches authentication, tokens or authorization author/contributor Authored by a returning contributor size/L 250-999 lines changed terrakube-api terrakube-ui type/feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add project-level remote state sharing

3 participants