Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add GET /api/v2/workspaceagents/me endpoint - #23088

Closed
andrewhamon wants to merge 3 commits into
coder:mainfrom
andrewhamon:feat/workspaceagent-me-endpoint
Closed

feat: add GET /api/v2/workspaceagents/me endpoint#23088
andrewhamon wants to merge 3 commits into
coder:mainfrom
andrewhamon:feat/workspaceagent-me-endpoint

Conversation

@andrewhamon

@andrewhamon andrewhamon commented Mar 15, 2026

Copy link
Copy Markdown

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 test and 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:

CleanShot 2026-03-15 at 17 39 43@2x

@github-actions

github-actions Bot commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@andrewhamon

Copy link
Copy Markdown
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
andrewhamon marked this pull request as ready for review March 16, 2026 00:41
@andrewhamon andrewhamon changed the title feat(coderd): add GET /api/v2/workspaceagents/me endpoint feat: add GET /api/v2/workspaceagents/me endpoint Mar 17, 2026
@matifali matifali added the community Pull Requests and issues created by the community. label Mar 17, 2026
andrewhamon and others added 3 commits March 18, 2026 04:54
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
andrewhamon force-pushed the feat/workspaceagent-me-endpoint branch from e28d2ab to 9b4d3bf Compare March 18, 2026 04:58
@Emyrk

Emyrk commented Mar 25, 2026

Copy link
Copy Markdown
Member

@andrewhamon can you rebase this off main and fix the swagger conflicts?

Comment thread coderd/workspaceagents.go
// 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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@Emyrk

Emyrk commented Mar 25, 2026

Copy link
Copy Markdown
Member

Overall LGTM. Needs a rebase and remove the AsSystemRestricted

@matifali matifali removed the community Pull Requests and issues created by the community. label Mar 26, 2026
@github-actions github-actions Bot added the stale This issue is like stale bread. label Apr 3, 2026
@github-actions github-actions Bot closed this Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale This issue is like stale bread.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants