Commit Graph

1862 Commits

Author SHA1 Message Date
Steven Masley eeb3d63be6
chore: merge authorization contexts (#12816)
* chore: merge authorization contexts

Instead of 2 auth contexts from apikey and dbauthz, merge them to
just use dbauthz. It is annoying to have two.

* fixup authorization reference
2024-03-29 10:14:27 -05:00
Steven Masley 8cf1e84bb5
chore: ensure root handler has sudomain app mw (#12812)
Enterprise routes like scim touch this.
2024-03-28 15:49:43 -05:00
Mathias Fredriksson 79441e3609
perf(coderd/database): optimize `GetWorkspaceAgentAndLatestBuildByAuthToken` (#12809) 2024-03-28 19:38:16 +02:00
Mathias Fredriksson d50c20c453
fix(coderd/database): add fk index for `workspace_agent_scripts` (#12791) 2024-03-28 14:31:58 +02:00
Danny Kopping d734f3fb74
chore: reduce azure CA cert validity check period to 2 months (#12788)
Signed-off-by: Danny Kopping <danny@coder.com>
2024-03-28 11:17:02 +02:00
Mathias Fredriksson 539d6b0f3b
test(coderd): fix template name too long in TestPatchTemplateMeta (#12781) 2024-03-27 18:25:42 +02:00
Mathias Fredriksson 421bf7e785
fix(coderd): use insights for DAUs, simplify metricscache (#12775)
Fixes #12134
Fixes https://github.com/coder/customers/issues/384
Refs #12122
2024-03-27 18:10:14 +02:00
Mathias Fredriksson 47fd190064
fix(coderd/database): improve perf of `GetTemplateInsightsByInterval` (#12773)
Refs #12122
2024-03-27 14:10:46 +02:00
Mathias Fredriksson ba1eaceda4
feat(coderd): add sftp to insights apps (#12675) 2024-03-27 14:09:29 +02:00
Mathias Fredriksson 0da29d74ac
fix(coderd/database): improve query perf of `GetTemplateAppInsights` (#12767)
Refs #12122
2024-03-27 12:28:36 +02:00
Ammar Bandukwala 0d9010e150
chore: fix 30% startup time hit from userpassword (#12769)
pbkdf2 is too expensive to run in init, so this change makes it load
lazily. I introduced a lazy package that I hope to use more in my
`GODEBUG=inittrace=1` adventure.


Benchmark results:

```
$ hyperfine "coder --help" "coder-new --help"
Benchmark 1: coder --help
  Time (mean ± σ):      82.1 ms ±   3.8 ms    [User: 93.3 ms, System: 30.4 ms]
  Range (min … max):    72.2 ms …  90.7 ms    35 runs
 
Benchmark 2: coder-new --help
  Time (mean ± σ):      52.0 ms ±   4.3 ms    [User: 62.4 ms, System: 30.8 ms]
  Range (min … max):    41.9 ms …  62.2 ms    52 runs
 
Summary
  coder-new --help ran
    1.58 ± 0.15 times faster than coder --help
```
2024-03-26 20:47:14 -05:00
Colin Adler 4d5a7b2d56
chore(codersdk): move all tailscale imports out of `codersdk` (#12735)
Currently, importing `codersdk` just to interact with the API requires
importing tailscale, which causes builds to fail unless manually using
our fork.
2024-03-26 12:44:31 -05:00
Mathias Fredriksson ae0ee622bb
fix(coderd/database): improve data exclusion in `UpsertTemplateUsageStats` (#12764)
The PostgreSQL query analyzer wasn't able to eliminate the agent stats without re-introducing this filter.

Before: https://explain.dalibo.com/plan/21h7gb4f4bef391g
After: https://explain.dalibo.com/plan/721ec1cccee91egc
2024-03-26 17:21:05 +02:00
Colin Adler 5f28220eec
fix(coderd): add timeout to websocket waitgroup on shutdown (#12754) 2024-03-26 03:04:15 +00:00
Asher 40e5ad5499
feat: make OAuth2 provider not enterprise-only (#12732) 2024-03-25 11:52:22 -08:00
Kyle Carberry 03ab37b343
chore: remove middleware to request version and entitlement warnings (#12750)
This cleans up `root.go` a bit, adds tests for middleware HTTP transport
functions, and removes two HTTP requests we always always performed previously
when executing *any* client command.

It should improve CLI performance (especially for users with higher latency).
2024-03-25 15:01:42 -04:00
Mathias Fredriksson 7e183db199
test(coderd): fix todo for increased accuracy in insights test (#12727)
This PR updates the tests in `insights_test.go` to enable commented-out scenarios. This behavior was fixed by previous PRs in this stack. Note that the updated golden files are correct since they are "second template only" meaning that the newly introduced data is considered as expected. In other golden files there is no change since "only count once" is applied.
2024-03-25 17:55:53 +02:00
Mathias Fredriksson b183236482
feat(coderd/database): use `template_usage_stats` in `*ByTemplate` insights queries (#12668)
This PR updates the `*ByTempalte` insights queries used for generating Prometheus metrics to behave the same way as the new rollup query and re-written insights queries that utilize the rolled up data.
2024-03-25 17:42:02 +02:00
Mathias Fredriksson 2332d8197a
feat(coderd/database): use `template_usage_stats` in `GetUserActivityInsights` query (#12672)
This PR updates the `GetUserActivityInsights` query to use rolled up `template_usage_stats` instead of raw agent and app stats.
2024-03-25 16:16:41 +02:00
Mathias Fredriksson a8ed689bda
feat(coderd/database): use `template_usage_stats` in `GetUserLatencyInsights` query (#12671)
This PR updates the `GetUserLatencyInsights` query to use rolled up `template_usage_stats` instead of raw agent and app stats.
2024-03-25 16:07:40 +02:00
Mathias Fredriksson 5738a03930
feat(coderd/database): use `template_usage_stats` in `GetTemplateAppInsights` query (#12669)
This PR updates the `GetTemplateAppInsights` query to use rolled up `template_usage_stats` instead of raw agent and app stats.
2024-03-25 15:58:37 +02:00
Mathias Fredriksson 5f3be62c83
feat(coderd/database): use `template_usage_stats` in `GetTemplateInsightsByInterval` query (#12667)
This PR updates the `GetTemplateInsightsByInterval` query to use rolled up `template_usage_stats` instead of raw agent and app stats.
2024-03-25 15:45:49 +02:00
Mathias Fredriksson 35d08434a9
feat(coderd/database): use `template_usage_stats` in `GetTemplateInsights` query (#12666)
This PR updates the `GetTemplateInsights` query to use rolled up `template_usage_stats` instead of raw agent and app stats.
2024-03-25 15:33:31 +02:00
Mathias Fredriksson f34592f45d
fix(coderd): skip logging error for cancelled query in agent report stats (#12730) 2024-03-25 12:20:16 +02:00
Jon Ayers 951dfaa99c
feat: add workspace_id to workspace_build audit logs (#12718) 2024-03-22 15:10:32 -05:00
Steven Masley c674128105
chore: allow search by build params in workspace search filter (#12694)
* chore: workspace search filter allow search by params
* has_param will return all workspaces with the param existance
* exact matching
2024-03-22 14:22:47 -05:00
Mathias Fredriksson b4fd819f0d
test(coderd): enable `dbrollup` service for insights tests (#12673) 2024-03-22 20:18:20 +02:00
Mathias Fredriksson 12e6fbf11e
feat(coderd/database): add `dbrollup` service to rollup insights (#12665)
Add `dbrollup` service that runs the `UpsertTemplateUsageStats` query
every 5 minutes, on the minute. This allows us to have fairly real-time
insights data when viewing "today".
2024-03-22 18:42:43 +02:00
Mathias Fredriksson 04f0510b09
feat(coderd/database): add `template_usage_stats` table and rollup query (#12664)
Add `template_usage_stats` table for aggregating tempalte usage data.
Data is rolled up by the `UpsertTemplateUsageStats` query, which fetches
data from the `workspace_agent_stats` and `workspace_app_stats` tables.
2024-03-22 18:33:34 +02:00
Colin Adler 37a05372fa
fix: disable relay if built-in DERP is disabled (#12654)
Fixes https://github.com/coder/coder/issues/12493
2024-03-21 16:53:41 -05:00
Cian Johnston 28730ca3d8
fix(support): sanitize manifest (#12711) 2024-03-21 19:55:34 +00:00
Cian Johnston 8ea5fb7115
chore(coderd/workspaceapps/apptest): fix test flake due to concurrent usage of same deployment (#12700)
- Updates existing tests under workspaceapps/apptest to not reuse existing appDetails as assertWorkspaceLastUsed(Not)?Updated calls FlushStats() which was causing racy test behaviour and incorrect test assertions.
- Expands scope of assertWorkspaceLastUsedAtUpdated and its counterpart to ProxySubdomain tests.
2024-03-21 15:38:38 +00:00
Cian Johnston 5454f4997b
chore(ci): clean up databases after test finishes in CI (#12702) 2024-03-21 14:53:16 +00:00
Mathias Fredriksson 9c84fb7fb1
fix(coderd/agentapi): always write agent stats when provided (#12699) 2024-03-21 16:47:06 +02:00
Steven Masley b4492fffba
chore: support multiple key:value search query params (#12690)
This more closely aligns with GitHub's label search style. Actual search params need to be converted to allow this format, by default they will throw an error if they do not support listing.
2024-03-21 08:37:19 -05:00
Dean Sheather 2b773f9034
fix: allow proxy version mismatch (with warning) (#12433) 2024-03-20 18:24:18 +00:00
Garrett Delfosse 4d9fe05f5a
feat: add awsiamrds db auth driver (#12566) 2024-03-20 13:14:43 -04:00
Cian Johnston 92aa1eba97
fix(cli): port-forward: update workspace last_used_at (#12659)
This PR updates the coder port-forward command to periodically inform coderd that the workspace is being used:

- Adds workspaceusage.Tracker which periodically batch-updates workspace LastUsedAt
- Adds coderd endpoint to signal workspace usage
- Updates coder port-forward to periodically hit this endpoint
- Modifies BatchUpdateWorkspacesLastUsedAt to avoid overwriting with stale data

Co-authored-by: Danny Kopping <danny@coder.com>
2024-03-20 16:44:12 +00:00
Steven Masley d789a60d47
chore: remove max_ttl from templates (#12644)
* chore: remove max_ttl from templates

Completely removing max_ttl as a feature on template scheduling. Must use other template scheduling features to achieve autostop.
2024-03-20 10:37:57 -05:00
Danny Kopping 9cfd5baa91
feat(coderd): export metric indicating each experiment's status (#12657) 2024-03-19 14:11:27 +02:00
Danny Kopping ab95ae827d
feat(coderd): add enabled experiments to telemetry (#12656) 2024-03-19 11:05:29 +02:00
Steven Masley f0f9569d51
chore: enforce that provisioners can only acquire jobs in their own organization (#12600)
* chore: add org ID as optional param to AcquireJob
* chore: plumb through organization id to provisioner daemons
* add org id to provisioner domain key
* enforce org id argument
* dbgen provisioner jobs defaults to default org
2024-03-18 12:48:13 -05:00
Marcin Tojek cae769eac0
fix: implicit schema in dump (#12646) 2024-03-18 16:25:08 +01:00
Marcin Tojek 15845d1a65
chore: use sqlc-vet to verify schema (#12642) 2024-03-18 15:23:25 +01:00
Steven Masley c189cc93e4
chore: bump gopkg.in/DataDog/dd-trace-go.v1 from 1.57.0 to 1.61.0 (#12610)
* chore: bump gopkg.in/DataDog/dd-trace-go.v1 from 1.57.0 to 1.61.0

* Fix tracer implementation
* Use alias vs 2 structs
2024-03-17 22:08:32 -05:00
Gábor 9c69672382
fix(migration): removed hardcoded public (#12620) 2024-03-16 10:11:14 -04:00
Ammar Bandukwala 496232446d
chore(cli): replace clibase with external `coder/serpent` (#12252) 2024-03-15 11:24:38 -05:00
Cian Johnston 2fc9f097ed
chore: apply linter auto-fixes (#12605) 2024-03-15 14:39:25 +00:00
Kyle Carberry 895df54051
fix: separate signals for passive, active, and forced shutdown (#12358)
* fix: separate signals for passive, active, and forced shutdown

`SIGTERM`: Passive shutdown stopping provisioner daemons from accepting new
jobs but waiting for existing jobs to successfully complete.

`SIGINT` (old existing behavior): Notify provisioner daemons to cancel in-flight jobs, wait 5s for jobs to be exited, then force quit.

`SIGKILL`: Untouched from before, will force-quit.

* Revert dramatic signal changes

* Rename

* Fix shutdown behavior for provisioner daemons

* Add test for graceful shutdown
2024-03-15 13:16:36 +00:00
Garrett Delfosse 0723dd3abf
fix: ensure agent token is from latest build in middleware (#12443) 2024-03-14 12:27:32 -04:00
Steven Masley 4cba83b30f
test: apptest was accidently choosing ports in use (#12580)
Apptest requires a port without a listening server to test failure
cases. This port was chosen and had a chance of actually being
provisioned. To prevent this accident, a port <1k is chosen,
since those will never be allocated.
2024-03-14 08:54:12 -05:00
Danny Kopping da54c8a51f
fix: fix data race in TestLabelsAggregation tests (#12578) 2024-03-13 13:47:22 +02:00
Danny Kopping 7a7105ad66
feat: make agent stats' cardinality configurable (#12535) 2024-03-13 12:03:36 +02:00
Cian Johnston 47cb584052
fix(support): sanitize agent env (#12554) 2024-03-12 15:23:11 +00:00
Steven Masley 597694fbdd
chore: bump migration file (#12556) 2024-03-12 14:55:45 +00:00
Steven Masley e11d3ca0ee
chore: move default everyone group to a migration (#12435) 2024-03-12 09:27:36 -05:00
Spike Curtis 51707446d0
fix: stop holding Pubsub mutex while calling pq.Listener (#12518)
fixes #11950

https://github.com/coder/coder/issues/11950#issuecomment-1987756088 explains the bug

We were also calling into `Unlisten()` and `Close()` while holding the mutex.  I don't believe that `Close()` depends on the notification loop being unblocked, but it's hard to be sure, and the safest thing to do is assume it could block.

So, I added a unit test that fakes out `pq.Listener` and sends a bunch of notifies every time we call into it to hopefully prevent regression where we hold the mutex while calling into these functions.

It also removes the use of a `context.Context` to stop the PubSub -- it must be explicitly `Closed()`.  This simplifies a bunch of the logic, and is how we use the pubsub anyway.
2024-03-12 09:44:12 +04:00
Cian Johnston d704ff4570
chore(codersdk): explain format of codersdk.UpdateWorkspaceAutostartRequest.Schedule (#12539) 2024-03-11 22:50:38 +00:00
Steven Masley e3051dff0c
chore: add workspace id filter on api (#12483)
* chore: add workspace id filter on api
2024-03-11 11:37:15 -05:00
Cian Johnston 8f40ee3465
Revert "feat: make agent stats' cardinality configurable (#12468)" (#12533)
This reverts commit 21d1873d97.
2024-03-11 14:33:36 +00:00
Cian Johnston bed61f7d2a
fix(coderd): correctly handle tar dir entries with missing path separator (#12479)
* coderd: add test to reproduce trailing directory issue
* coderd: add trailing path separator to dir entries when converting to zip
* provisionersdk: add trailing path separator to directory entries
2024-03-11 14:06:41 +00:00
Danny Kopping 21d1873d97
feat: make agent stats' cardinality configurable (#12468)
Closes #12221
2024-03-11 16:04:08 +02:00
Cian Johnston 0647ec1960
fix(coderd): prevent nil err deref (#12475) 2024-03-11 14:03:58 +00:00
Cian Johnston b1ecc53033
chore(coderd): improve tests for tar<->zip conversion (#12477)
* improve tests for tar<->zip conversion
* set mode and modtime correctly when converting from zip to tar (#12476)
2024-03-11 13:29:57 +00:00
Mathias Fredriksson bae0a747ed
test(coderd): skip flaky dau test (#12517)
* test(coderd): skip flaky dau test

* chore(coderd/database/dbpurge): fix failing test (#12530)

---------

Co-authored-by: Cian Johnston <cian@coder.com>
2024-03-11 12:54:38 +00:00
Colin Adler 66154f937e
fix(coderd): pass block endpoints into servertailnet (#12149) 2024-03-08 05:29:54 +00:00
Cian Johnston c8aa99a5b8
feat(coderd/database/dbfake): allow specifying fileID in TemplateVersionBuilder (#12450) 2024-03-07 12:36:11 +00:00
Dean Sheather 662be56d72
chore: rename migrations to fix main (#12442) 2024-03-06 18:28:53 +00:00
Steven Masley b5f866c1cb
chore: add organization_id column to provisioner daemons (#12356)
* chore: add organization_id column to provisioner daemons
* Update upsert to include organization id on set
2024-03-06 12:04:50 -06:00
Dean Sheather 46a2ff1061
feat: allow setting port share protocol (#12383)
Co-authored-by: Garrett Delfosse <garrett@coder.com>
2024-03-06 09:23:57 -05:00
Steven Masley 23ff807a27
chore: remove autocreate orgs on CreateUser (#12434)
New users must be explictly given an organization to join.
Organizations should not be auto created as a side effect of
creating a new user.
2024-03-06 07:29:28 -06:00
Steven Masley 17c486c5e6
chore: ensure default org always exists (#12412)
* chore: ensure default org always exists

First user just joins the org created by the migration
2024-03-05 14:06:35 -06:00
Garrett Delfosse 61bd341a36
chore: change max share level on existing port shares (#12411) 2024-03-05 13:47:01 -05:00
Cian Johnston 4343998c37
chore(coderd): add tests for big oidc tokens (#12424)
- Adds two test cases for a 64k+ ID token and a 64k+ userinfo payload.
- Reformats the entire test cases array as instructed by CI
2024-03-05 14:46:00 +00:00
Marcin Tojek b1f9a6dc31
fix: use timestamptz instead of timestamp (#12425)
* fix: use timestampz instead of timestamp

* fix: timestamptz
2024-03-05 14:16:29 +00:00
Marcin Tojek 3e99c0373f
fix: improve pagination parser (#12422) 2024-03-05 14:05:15 +00:00
Marcin Tojek e4fa212164
fix: always return count of workspaces (#12407) 2024-03-05 09:24:43 +01:00
Steven Masley 5c6974e55f
feat: implement provisioner auth middleware and proper org params (#12330)
* feat: provisioner auth in mw to allow ExtractOrg

Step to enable org scoped provisioner daemons

* chore: handle default org handling for provisioner daemons
2024-03-04 15:15:41 -06:00
Alex 320c2eac6f
Entra External Auth for ADO (#12201) 2024-03-04 12:12:46 -06:00
Colin Adler 4439a920e4
Merge pull request from GHSA-7cc2-r658-7xpf
This fixes a vulnerability with the `CODER_OIDC_EMAIL_DOMAIN` option,
where users with a superset of the allowed email domain would be allowed
to login. For example, given `CODER_OIDC_EMAIL_DOMAIN=google.com`, a
user would be permitted entry if their email domain was
`colin-google.com`.
2024-03-04 12:52:03 -05:00
Garrett Delfosse 8f190b2016
fix: disallow out of range ports (#12414) 2024-03-04 12:25:06 -05:00
Colin Adler e5d911462f
fix(tailnet): enforce valid agent and client addresses (#12197)
This adds the ability for `TunnelAuth` to also authorize incoming wireguard node IPs, preventing agents from reporting anything other than their static IP generated from the agent ID.
2024-03-01 09:02:33 -06:00
Colin Adler 7fbca62e08
chore: fix `Test_parseInsightsStartAndEndTime` flake (#12377)
Fixes https://github.com/coder/coder/issues/10600
2024-02-29 18:20:25 -06:00
Steven Masley cbcf4ef2c4
chore: add faking 429 responses from fake idp (#12365)
Required to trigger error condition in fe.
See pull (#12367)
2024-02-29 09:45:53 -06:00
Cian Johnston 4f87ba46f9
chore: update provisioner tag documentation with suggestions from #12315 (#12347)
- Adds more testcases to TestAcquirer_MatchTags
- Adds functionality to generate a table from above test
- Update provisioner tag documentation with generated table
- Apply other feedback from #12315
2024-02-29 12:31:11 +00:00
Dean Sheather bedd2c5922
fix: avoid race between replicas on start (#12344)
DERP mesh key setup would do a SELECT and then an INSERT on failure, without a lock. During some testing with multiple replicas, I managed to cause a replica to crash due to them initializing simultaneously.

Fixes:

Encountered an error running "coder server"
create coder API: insert mesh key: pq: duplicate key value violates unique constraint "site_configs_key_key"

Co-authored-by: Cian Johnston <cian@coder.com>
2024-02-28 16:14:11 +00:00
Cian Johnston 1465ee2ed1
fix(coderd): use database.IsQueryCanceledError instead of xerrors.Is(err, context.Canceled) (#12325) 2024-02-28 21:19:57 +10:00
Kayla Washburn-Love b2413a593c
chore: reimplement activity status and autostop improvements (#12175) 2024-02-27 11:06:26 -07:00
Cian Johnston b9e2d0a400
fix(coderd): mark provisioner daemon psk as secret (#12322)
* fix(coderd): mark provisioner daemon psk as secret

Marks provisioner daemon PSK with the secret annotation.
This ensures it will be scrubbed from API requests to
/api/v2/deployment/config.

* make gen
2024-02-27 16:33:32 +00:00
Asher f74532ff50
feat: audit oauth2 app management (#12275)
* Audit oauth2 app management
* Use 201 for creating secrets
2024-02-26 23:52:08 +00:00
Steven Masley 6b866b3f48
feat: set sane default for gitea external auth (#12306)
* feat: external auth defaults for gitea

Add some sane defaults for gitea to make it easier to configure
2024-02-26 12:35:18 -06:00
Steven Masley d2998c6b7b
feat: implement organization context in the cli (#12259)
* feat: implement organization context in the cli

`coder org show current`
2024-02-26 10:03:49 -06:00
Steven Masley f44c89d200
chore: enforce orgid in audit logs where required (#12283)
* chore: enforce orgid in audit logs where required
2024-02-26 08:27:33 -06:00
Cian Johnston 74b749b890
chore(coderd): add test to assert agent token invalid when workspace deleted (#12290) 2024-02-26 13:27:00 +00:00
Steven Masley 13359aa16f
chore: drop github per user rate limit tracking (#12286)
* chore: drop github per user rate limit tracking

Rate limits for authenticated requests are per user.
This would be an excessive number of prometheus labels,
so we only track the unauthorized limit.
2024-02-23 11:17:52 -06:00
Marcin Tojek 90db6683c4
fix: refresh entitlements after creating first user (#12285) 2024-02-23 16:48:24 +00:00
Cian Johnston 2cb9bfd517
refactor(coderd): move healthcheck report structs to codersdk (#12279)
Moves healthcheck report-related structs from coderd/healthcheck to codersdk
This prevents an import cycle when adding a codersdk.Client method to hit /api/v2/debug/health.
2024-02-23 13:13:28 +00:00
Spike Curtis af3fdc68c3
chore: refactor agent routines that use the v2 API (#12223)
In anticipation of needing the `LogSender` to run on a context that doesn't get immediately canceled when you `Close()` the agent, I've undertaken a little refactor to manage the goroutines that get run against the Tailnet and Agent API connection.

This handles controlling two contexts, one that gets canceled right away at the start of graceful shutdown, and another that stays up to allow graceful shutdown to complete.
2024-02-23 11:04:23 +04:00
Cian Johnston 53e8f9c0f9
fix(coderd): only allow untagged provisioners to pick up untagged jobs (#12269)
Alternative solution to #6442

Modifies the behaviour of AcquireProvisionerJob and adds a special case for 'un-tagged' jobs such that they can only be picked up by 'un-tagged' provisioners.

Also adds comprehensive test coverage for AcquireJob given various combinations of tags.
2024-02-22 15:04:31 +00:00
Steven Masley d4d8424ce0
fix: fix GetOrganizationsByUserID error when multiple organizations exist (#12257)
* test: fetching user orgs fails if multi orgs in pg db
* fix: GetOrganizationsByUserID fixed if multi orgs exist
2024-02-22 08:14:48 -06:00