feat: add GET /api/v2/workspaceagents/me endpoint - #23088
Closed
andrewhamon wants to merge 3 commits into
Closed
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
cdrci2
added a commit
to coder/cla
that referenced
this pull request
Mar 15, 2026
andrewhamon
marked this pull request as ready for review
March 16, 2026 00:41
Add a REST endpoint that allows a workspace agent to query its own
metadata using its session token. This returns the same response as
the existing GET /api/v2/workspaceagents/{id} endpoint but
authenticates via the agent token instead of requiring a user API key.
This enables scripts and services running on workspace instances to
retrieve agent metadata (environment variables, workspace info, etc.)
using simple HTTP calls, without needing to speak the dRPC protocol
used by the agent's manifest API.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Extract the common logic between workspaceAgent and workspaceAgentMe into writeWorkspaceAgentResponse to reduce duplication. Co-Authored-By: Claude Opus 4.6 <[email protected]>
andrewhamon
force-pushed
the
feat/workspaceagent-me-endpoint
branch
from
March 18, 2026 04:58
e28d2ab to
9b4d3bf
Compare
Member
|
@andrewhamon can you rebase this off |
Emyrk
requested changes
Mar 25, 2026
| // response also needs the workspace and owner username. Fetch them | ||
| // using the authenticated agent's ID. | ||
| //nolint:gocritic // The agent RBAC scope may not cover this cross-table query. | ||
| waws, err := api.Database.GetWorkspaceAgentAndWorkspaceByID(dbauthz.AsSystemRestricted(ctx), agent.ID) |
Member
There was a problem hiding this comment.
We should not escalate permissions. If the agent cannot fetch this metadata, then the api should fail.
Suggested change
| waws, err := api.Database.GetWorkspaceAgentAndWorkspaceByID(dbauthz.AsSystemRestricted(ctx), agent.ID) | |
| waws, err := api.Database.GetWorkspaceAgentAndWorkspaceByID(ctx, agent.ID) |
Under normal conditions, the agent can fetch this data.
Member
|
Overall LGTM. Needs a rebase and remove the |
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.
Add a REST endpoint that allows a workspace agent to query its own metadata using its session token. This returns the same response as the existing
GET /api/v2/workspaceagents/{id}endpoint but authenticates via the agent token instead of requiring a user API key.This enables scripts and services running on workspace instances to retrieve agent metadata (environment variables, workspace info, etc.) using simple HTTP calls, without needing to speak the dRPC protocol used by the agent's manifest API.
I have described my use case for this here: #23086
tl;dr in my case, i want to be able to read workspace environment variables from other systemd services that don't inherit the agent processes environment.
AI disclosure
claude code wrote all code under my supervision
Manual Testing
I've ran
make testand I believe all relevant tests are passing. Some tests are failing for me both on main and on this branch. Since they fail on main too I assume that's just an issue with my dev environment.I tested the new API endpoint in a test workspace and it functions as I expect it to: