Skip to content

feat(coderd): add support for external agents to API's and provisioner #19286

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

Open
wants to merge 6 commits into
base: kacpersaw/feat-coder-attach-database
Choose a base branch
from

Conversation

kacpersaw
Copy link
Contributor

@kacpersaw kacpersaw commented Aug 11, 2025

This pull request introduces support for external workspace management, allowing users to register and manage workspaces that are provisioned and managed outside of the Coder.

Depends on: coder/terraform-provider-coder#424

  • GET /api/v2/init-script - Gets the agent initialization script
    • By default, it returns a script for Linux (amd64), but with query parameters (os and arch) you can get the init script for different platforms
  • GET /api/v2/workspaces/{workspace}/external-agent/{agent}/credentials - Gets credentials for an external agent (enterprise)
  • Updated queries to filter workspaces/templates by the has_external_agent field

Copy link
Contributor Author

kacpersaw commented Aug 11, 2025

@kacpersaw kacpersaw changed the title feat: add support for external agents to API's and provisioner feat(coderd): add support for external agents to API's and provisioner Aug 11, 2025
@kacpersaw kacpersaw force-pushed the kacpersaw/feat-coder-attach-api branch from b641ffe to 07a9c42 Compare August 11, 2025 15:40
@kacpersaw kacpersaw marked this pull request as ready for review August 12, 2025 06:43
@kacpersaw kacpersaw requested a review from deansheather August 12, 2025 06:43
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

Proto changes look fine to me 👍

@kacpersaw kacpersaw force-pushed the kacpersaw/feat-coder-attach-database branch from c012284 to 63fefbb Compare August 12, 2025 12:44
@kacpersaw kacpersaw force-pushed the kacpersaw/feat-coder-attach-api branch from 60cccc2 to 0cf5381 Compare August 12, 2025 12:44
t.Run("OK Linux", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
script, err := client.InitScript(context.Background(), "linux", "amd64")
Copy link
Member

Choose a reason for hiding this comment

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

Probably should make one of these arm64 for variety, and also assert that the string /bin/coder-OS-ARCH[.exe] shows up

})
if err != nil {
return xerrors.Errorf("update template version external auth providers: %w", err)
return xerrors.Errorf("update template version ai task and external agent: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return xerrors.Errorf("update template version ai task and external agent: %w", err)
return xerrors.Errorf("update template version flags: %w", err)

}); err != nil {
return xerrors.Errorf("update workspace build ai tasks flag: %w", err)
return xerrors.Errorf("update workspace build ai tasks and external agent flag: %w", err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return xerrors.Errorf("update workspace build ai tasks and external agent flag: %w", err)
return xerrors.Errorf("update workspace build flags: %w", err)

Comment on lines +287 to +290
HasAITask: parser.NullableBoolean(values, sql.NullBool{}, "has-ai-task"),
AuthorID: parser.UUID(values, uuid.Nil, "author_id"),
AuthorUsername: parser.String(values, "", "author"),
HasExternalAgent: parser.NullableBoolean(values, sql.NullBool{}, "has-external-agent"),
Copy link
Member

Choose a reason for hiding this comment

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

This mixes - and _. I know has-ai-task uses dashes, but it probably needs to be changed to underscores...

@@ -943,6 +952,18 @@ func (api *API) CheckBuildUsage(ctx context.Context, store database.Store, templ
// When there are no licenses installed, a noop usage checker is used
// instead.
Copy link
Member

Choose a reason for hiding this comment

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

Dude to this comment above (and the entitlements code in the function above), external agents won't be blocked if there are no licenses installed (e.g. an enterprise build in free mode). Is that what you want? If it's not, I can walk you through a few changes to fix this.

return
}

initScriptURL := fmt.Sprintf("%s/api/v2/init-script/%s/%s", api.AccessURL.String(), agent.OperatingSystem, agent.Architecture)
Copy link
Member

Choose a reason for hiding this comment

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

Judging by the code, it seems every agent that doesn't use instance identity could be used on this endpoint and successfully return the agent token. This probably should only return a value for agents that are actually marked as external.

Copy link
Member

Choose a reason for hiding this comment

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

Could you perhaps pull all the build resources and check if the agent is a child of the external agent resource?

Copy link
Member

Choose a reason for hiding this comment

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

Should also add 404 tests for non-external agents after fixing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants