Skip to content

fix: allow dynamic parameters without requiring org membership #18531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 24, 2025

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Jun 24, 2025

Test failure on main

POST http://localhost:36481/api/v2/users/e27d2233-85fb-4c8d-b063-f69da3cbb07c/workspaces: unexpected status code 400: Unable to validate parameters
        	            		Error: Failed to fetch workspace owner; Please check your permissions or the user may not exist.

@johnstcn johnstcn changed the title fix: dynamic parameters to not require org membership fix: allow dynamic parameters without requiring org membership Jun 24, 2025
@Emyrk Emyrk force-pushed the stevenmasley/fix_owner_fetch branch from 153faf8 to fb9664e Compare June 24, 2025 15:15
Comment on lines +246 to +269
user, err := r.db.GetUserByID(ctx, ownerID)
if err != nil {
return err
}
// If the user failed to read, we also try to read the user from their
// organization member. You only need to be able to read the organization member
// to get the owner data.
//
// Only the terraform files can therefore leak more information than the
// caller should have access to. All this info should be public assuming you can
// read the user though.
mem, err := database.ExpectOne(r.db.OrganizationMembers(ctx, database.OrganizationMembersParams{
OrganizationID: r.data.templateVersion.OrganizationID,
UserID: ownerID,
IncludeSystem: true,
}))
if err != nil {
return xerrors.Errorf("fetch user: %w", err)
}

// User data is required for the form. Org member is checked above
// nolint:gocritic
user, err := r.db.GetUserByID(dbauthz.AsProvisionerd(ctx), mem.OrganizationMember.UserID)
if err != nil {
return xerrors.Errorf("fetch user: %w", err)
// Org member fetched, so use the provisioner context to fetch the user.
//nolint:gocritic // Has the correct permissions, and matches the provisioning flow.
user, err = r.db.GetUserByID(dbauthz.AsProvisionerd(ctx), mem.OrganizationMember.UserID)
if err != nil {
return xerrors.Errorf("fetch user: %w", err)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

If the Renderer had the authz object, we could fetch the user with elevated perms, then check the user's perms. Removing 1 sql query round trip 😢

@Emyrk Emyrk requested review from SasSwart and johnstcn June 24, 2025 15:17
@Emyrk
Copy link
Member Author

Emyrk commented Jun 24, 2025

Follow up issue made: #18536

@Emyrk Emyrk merged commit 341b54e into main Jun 24, 2025
34 checks passed
@Emyrk Emyrk deleted the stevenmasley/fix_owner_fetch branch June 24, 2025 15:33
@github-actions github-actions bot locked and limited conversation to collaborators Jun 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants