Skip to content

Commit 03ec0f3

Browse files
committed
Merge remote-tracking branch 'origin/main' into authzquerier_layer
2 parents 797e749 + e663eaa commit 03ec0f3

File tree

23 files changed

+417
-284
lines changed

23 files changed

+417
-284
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"afero",
44
"apps",
55
"ASKPASS",
6+
"autostop",
67
"awsidentity",
78
"bodyclose",
89
"buildinfo",
@@ -117,6 +118,7 @@
117118
"tailnet",
118119
"tailnettest",
119120
"Tailscale",
121+
"tbody",
120122
"TCGETS",
121123
"tcpip",
122124
"TCSETS",
@@ -128,6 +130,7 @@
128130
"tfjson",
129131
"tfplan",
130132
"tfstate",
133+
"thead",
131134
"tios",
132135
"tmpdir",
133136
"tparallel",

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ gen: \
418418
provisionerd/proto/provisionerd.pb.go \
419419
site/src/api/typesGenerated.ts \
420420
docs/admin/prometheus.md \
421+
docs/admin/audit-logs.md \
421422
coderd/apidoc/swagger.json \
422423
.prettierignore.include \
423424
.prettierignore \
@@ -436,6 +437,7 @@ gen/mark-fresh:
436437
provisionerd/proto/provisionerd.pb.go \
437438
site/src/api/typesGenerated.ts \
438439
docs/admin/prometheus.md \
440+
docs/admin/audit-logs.md \
439441
coderd/apidoc/swagger.json \
440442
.prettierignore.include \
441443
.prettierignore \
@@ -490,6 +492,11 @@ docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/me
490492
cd site
491493
yarn run format:write:only ../docs/admin/prometheus.md
492494

495+
docs/admin/audit-logs.md: scripts/auditdocgen/main.go enterprise/audit/table.go
496+
go run scripts/auditdocgen/main.go
497+
cd site
498+
yarn run format:write:only ../docs/admin/audit-logs.md
499+
493500
coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen $(FIND_EXCLUSIONS) -type f) $(wildcard coderd/*.go) $(wildcard enterprise/coderd/*.go) $(wildcard codersdk/*.go) .swaggo docs/manifest.json
494501
./scripts/apidocgen/generate.sh
495502
yarn run --cwd=site format:write:only ../docs/api ../docs/manifest.json ../coderd/apidoc/swagger.json

coderd/apidoc/docs.go

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/audit.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,6 @@ func auditSearchQuery(query string) (database.GetAuditLogsOffsetParams, []coders
452452

453453
func resourceTypeFromString(resourceTypeString string) string {
454454
switch codersdk.ResourceType(resourceTypeString) {
455-
case codersdk.ResourceTypeOrganization:
456-
return resourceTypeString
457455
case codersdk.ResourceTypeTemplate:
458456
return resourceTypeString
459457
case codersdk.ResourceTypeTemplateVersion:

coderd/audit/diff.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
// AuditableResources, then add it to this interface.
1010
type Auditable interface {
1111
database.APIKey |
12-
database.Organization |
13-
database.OrganizationMember |
1412
database.Template |
1513
database.TemplateVersion |
1614
database.User |

coderd/audit/request.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ type BuildAuditParams[T Auditable] struct {
4949

5050
func ResourceTarget[T Auditable](tgt T) string {
5151
switch typed := any(tgt).(type) {
52-
case database.Organization:
53-
return typed.Name
5452
case database.Template:
5553
return typed.Name
5654
case database.TemplateVersion:
@@ -73,8 +71,6 @@ func ResourceTarget[T Auditable](tgt T) string {
7371

7472
func ResourceID[T Auditable](tgt T) uuid.UUID {
7573
switch typed := any(tgt).(type) {
76-
case database.Organization:
77-
return typed.ID
7874
case database.Template:
7975
return typed.ID
8076
case database.TemplateVersion:
@@ -96,8 +92,6 @@ func ResourceID[T Auditable](tgt T) uuid.UUID {
9692

9793
func ResourceType[T Auditable](tgt T) database.ResourceType {
9894
switch any(tgt).(type) {
99-
case database.Organization:
100-
return database.ResourceTypeOrganization
10195
case database.Template:
10296
return database.ResourceTypeTemplate
10397
case database.TemplateVersion:

coderd/workspaceagents.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,6 @@ func (api *API) workspaceAgentListeningPorts(rw http.ResponseWriter, r *http.Req
402402

403403
func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (*codersdk.AgentConn, error) {
404404
clientConn, serverConn := net.Pipe()
405-
go func() {
406-
<-r.Context().Done()
407-
_ = clientConn.Close()
408-
_ = serverConn.Close()
409-
}()
410405

411406
derpMap := api.DERPMap.Clone()
412407
for _, region := range derpMap.Regions {
@@ -453,7 +448,16 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (*
453448
}
454449

455450
sendNodes, _ := tailnet.ServeCoordinator(clientConn, func(node []*tailnet.Node) error {
456-
return conn.UpdateNodes(node)
451+
err := conn.RemoveAllPeers()
452+
if err != nil {
453+
return xerrors.Errorf("remove all peers: %w", err)
454+
}
455+
456+
err = conn.UpdateNodes(node)
457+
if err != nil {
458+
return xerrors.Errorf("update nodes: %w", err)
459+
}
460+
return nil
457461
})
458462
conn.SetNodeCallback(sendNodes)
459463
go func() {
@@ -465,6 +469,10 @@ func (api *API) dialWorkspaceAgentTailnet(r *http.Request, agentID uuid.UUID) (*
465469
}()
466470
return &codersdk.AgentConn{
467471
Conn: conn,
472+
CloseFunc: func() {
473+
_ = clientConn.Close()
474+
_ = serverConn.Close()
475+
},
468476
}, nil
469477
}
470478

codersdk/audit.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
type ResourceType string
1515

1616
const (
17-
ResourceTypeOrganization ResourceType = "organization"
1817
ResourceTypeTemplate ResourceType = "template"
1918
ResourceTypeTemplateVersion ResourceType = "template_version"
2019
ResourceTypeUser ResourceType = "user"
@@ -27,8 +26,6 @@ const (
2726

2827
func (r ResourceType) FriendlyString() string {
2928
switch r {
30-
case ResourceTypeOrganization:
31-
return "organization"
3229
case ResourceTypeTemplate:
3330
return "template"
3431
case ResourceTypeTemplateVersion:
@@ -122,7 +119,7 @@ type AuditLogResponse struct {
122119

123120
type CreateTestAuditLogRequest struct {
124121
Action AuditAction `json:"action,omitempty" enums:"create,write,delete,start,stop"`
125-
ResourceType ResourceType `json:"resource_type,omitempty" enums:"organization,template,template_version,user,workspace,workspace_build,git_ssh_key,api_key,group"`
122+
ResourceType ResourceType `json:"resource_type,omitempty" enums:"template,template_version,user,workspace,workspace_build,git_ssh_key,auditable_group"`
126123
ResourceID uuid.UUID `json:"resource_id,omitempty" format:"uuid"`
127124
Time time.Time `json:"time,omitempty" format:"date-time"`
128125
BuildReason BuildReason `json:"build_reason,omitempty" enums:"autostart,autostop,initiator"`

docs/admin/audit-logs.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,23 @@ their deployment.
55

66
## Tracked Events
77

8-
We track **create, update and delete** events for the following resources:
9-
10-
- GitSSHKey
11-
- Template
12-
- TemplateVersion
13-
- Workspace
14-
- WorkspaceBuild
15-
- User
16-
- Group
8+
We track the following resources:
9+
10+
<!-- Code generated by 'make docs/admin/audit-logs.md'. DO NOT EDIT -->
11+
12+
| <b>Resource<b> | |
13+
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
14+
| AuditableGroup | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>avatar_url</td><td>true</td></tr><tr><td>id</td><td>true</td></tr><tr><td>members</td><td>true</td></tr><tr><td>name</td><td>true</td></tr><tr><td>organization_id</td><td>false</td></tr><tr><td>quota_allowance</td><td>true</td></tr></tbody></table> |
15+
| GitSSHKey | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>created_at</td><td>false</td></tr><tr><td>private_key</td><td>true</td></tr><tr><td>public_key</td><td>true</td></tr><tr><td>updated_at</td><td>false</td></tr><tr><td>user_id</td><td>true</td></tr></tbody></table> |
16+
| Organization | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>created_at</td><td>false</td></tr><tr><td>description</td><td>true</td></tr><tr><td>id</td><td>true</td></tr><tr><td>name</td><td>true</td></tr><tr><td>updated_at</td><td>false</td></tr></tbody></table> |
17+
| OrganizationMember | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>created_at</td><td>false</td></tr><tr><td>organization_id</td><td>true</td></tr><tr><td>roles</td><td>true</td></tr><tr><td>updated_at</td><td>false</td></tr><tr><td>user_id</td><td>true</td></tr></tbody></table> |
18+
| Template | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>active_version_id</td><td>true</td></tr><tr><td>allow_user_cancel_workspace_jobs</td><td>true</td></tr><tr><td>created_at</td><td>false</td></tr><tr><td>created_by</td><td>true</td></tr><tr><td>default_ttl</td><td>true</td></tr><tr><td>deleted</td><td>false</td></tr><tr><td>description</td><td>true</td></tr><tr><td>display_name</td><td>true</td></tr><tr><td>group_acl</td><td>true</td></tr><tr><td>icon</td><td>true</td></tr><tr><td>id</td><td>true</td></tr><tr><td>is_private</td><td>true</td></tr><tr><td>min_autostart_interval</td><td>true</td></tr><tr><td>name</td><td>true</td></tr><tr><td>organization_id</td><td>false</td></tr><tr><td>provisioner</td><td>true</td></tr><tr><td>updated_at</td><td>false</td></tr><tr><td>user_acl</td><td>true</td></tr></tbody></table> |
19+
| TemplateVersion | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>created_at</td><td>false</td></tr><tr><td>created_by</td><td>true</td></tr><tr><td>id</td><td>true</td></tr><tr><td>job_id</td><td>false</td></tr><tr><td>name</td><td>true</td></tr><tr><td>organization_id</td><td>false</td></tr><tr><td>readme</td><td>true</td></tr><tr><td>template_id</td><td>true</td></tr><tr><td>updated_at</td><td>false</td></tr></tbody></table> |
20+
| User | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>avatar_url</td><td>false</td></tr><tr><td>created_at</td><td>false</td></tr><tr><td>deleted</td><td>true</td></tr><tr><td>email</td><td>true</td></tr><tr><td>hashed_password</td><td>true</td></tr><tr><td>id</td><td>true</td></tr><tr><td>last_seen_at</td><td>false</td></tr><tr><td>login_type</td><td>false</td></tr><tr><td>rbac_roles</td><td>true</td></tr><tr><td>status</td><td>true</td></tr><tr><td>updated_at</td><td>false</td></tr><tr><td>username</td><td>true</td></tr></tbody></table> |
21+
| Workspace | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>autostart_schedule</td><td>true</td></tr><tr><td>created_at</td><td>false</td></tr><tr><td>deleted</td><td>false</td></tr><tr><td>id</td><td>true</td></tr><tr><td>last_used_at</td><td>false</td></tr><tr><td>name</td><td>true</td></tr><tr><td>organization_id</td><td>false</td></tr><tr><td>owner_id</td><td>true</td></tr><tr><td>template_id</td><td>true</td></tr><tr><td>ttl</td><td>true</td></tr><tr><td>updated_at</td><td>false</td></tr></tbody></table> |
22+
| WorkspaceBuild | <table><thead><tr><th>Field</th><th>Tracked</th></tr></thead><tbody><tr><td>build_number</td><td>false</td></tr><tr><td>created_at</td><td>false</td></tr><tr><td>daily_cost</td><td>false</td></tr><tr><td>deadline</td><td>false</td></tr><tr><td>id</td><td>false</td></tr><tr><td>initiator_id</td><td>false</td></tr><tr><td>job_id</td><td>false</td></tr><tr><td>provisioner_state</td><td>false</td></tr><tr><td>reason</td><td>false</td></tr><tr><td>template_version_id</td><td>true</td></tr><tr><td>transition</td><td>false</td></tr><tr><td>updated_at</td><td>false</td></tr><tr><td>workspace_id</td><td>false</td></tr></tbody></table> |
23+
24+
<!-- End generated by 'make docs/admin/audit-logs.md'. -->
1725

1826
## Filtering logs
1927

docs/api/audit.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ curl -X GET http://coder-server:8080/api/v2/audit?q=string \
5454
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
5555
"resource_link": "string",
5656
"resource_target": "string",
57-
"resource_type": "organization",
57+
"resource_type": "template",
5858
"status_code": 0,
5959
"time": "2019-08-24T14:15:22Z",
6060
"user": {
@@ -108,7 +108,7 @@ curl -X POST http://coder-server:8080/api/v2/audit/testgenerate \
108108
"action": "create",
109109
"build_reason": "autostart",
110110
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
111-
"resource_type": "organization",
111+
"resource_type": "template",
112112
"time": "2019-08-24T14:15:22Z"
113113
}
114114
```

docs/api/schemas.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@
330330
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
331331
"resource_link": "string",
332332
"resource_target": "string",
333-
"resource_type": "organization",
333+
"resource_type": "template",
334334
"status_code": 0,
335335
"time": "2019-08-24T14:15:22Z",
336336
"user": {
@@ -406,7 +406,7 @@
406406
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
407407
"resource_link": "string",
408408
"resource_target": "string",
409-
"resource_type": "organization",
409+
"resource_type": "template",
410410
"status_code": 0,
411411
"time": "2019-08-24T14:15:22Z",
412412
"user": {
@@ -785,7 +785,7 @@ CreateParameterRequest is a structure used to create a new parameter value for a
785785
"action": "create",
786786
"build_reason": "autostart",
787787
"resource_id": "4d5215ed-38bb-48ed-879a-fdb9ca58522f",
788-
"resource_type": "organization",
788+
"resource_type": "template",
789789
"time": "2019-08-24T14:15:22Z"
790790
}
791791
```
@@ -812,15 +812,13 @@ CreateParameterRequest is a structure used to create a new parameter value for a
812812
| `build_reason` | `autostart` |
813813
| `build_reason` | `autostop` |
814814
| `build_reason` | `initiator` |
815-
| `resource_type` | `organization` |
816815
| `resource_type` | `template` |
817816
| `resource_type` | `template_version` |
818817
| `resource_type` | `user` |
819818
| `resource_type` | `workspace` |
820819
| `resource_type` | `workspace_build` |
821820
| `resource_type` | `git_ssh_key` |
822-
| `resource_type` | `api_key` |
823-
| `resource_type` | `group` |
821+
| `resource_type` | `auditable_group` |
824822

825823
## codersdk.CreateTokenRequest
826824

@@ -3739,7 +3737,7 @@ Parameter represents a set value for the scope.
37393737
## codersdk.ResourceType
37403738

37413739
```json
3742-
"organization"
3740+
"template"
37433741
```
37443742

37453743
### Properties
@@ -3748,7 +3746,6 @@ Parameter represents a set value for the scope.
37483746

37493747
| Value |
37503748
| ------------------ |
3751-
| `organization` |
37523749
| `template` |
37533750
| `template_version` |
37543751
| `user` |

0 commit comments

Comments
 (0)