mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
feat: allow bypassing current CORS magic based on template config (#18706)
Solves https://github.com/coder/coder/issues/15096 This is a slight rework/refactor of the earlier PRs from @dannykopping and @Emyrk: - https://github.com/coder/coder/pull/15669 - https://github.com/coder/coder/pull/15684 - https://github.com/coder/coder/pull/17596 Rather than having a per-app CORS behaviour setting and additionally a template level setting for ports, this PR adds a single template level CORS behaviour setting that is then used by all apps/ports for workspaces created from that template. The main changes are in `proxy.go` and `request.go` to: a) get the CORS behaviour setting from the template b) have `HandleSubdomain` bypass the CORS middleware handler if the selected behaviour is `passthru` c) in `proxyWorkspaceApp`, do not modify the response if the selected behaviour is `passthru` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for configuring CORS behavior ("simple" or "passthru") at the template level for all shared ports. * Introduced a new "CORS Behavior" setting in the template creation and settings forms. * API endpoints and responses now include the optional `cors_behavior` property for templates. * Workspace apps and proxy now honor the specified CORS behavior, enabling conditional CORS middleware application. * Enhanced workspace app tests with comprehensive scenarios covering CORS behaviors and authentication states. * **Bug Fixes** * None. * **Documentation** * Updated API and admin documentation to describe the new `cors_behavior` property and its usage. * Added examples and schema references for CORS behavior in relevant API docs. * **Tests** * Extended automated tests to cover different CORS behavior scenarios for templates and workspace apps. * **Chores** * Updated audit logging to track changes to the `cors_behavior` field on templates. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Callum Styan <callumstyan@gmail.com>
This commit is contained in:
Generated
+19
@@ -1056,6 +1056,21 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
|
||||
| `vscode_connection` |
|
||||
| `jetbrains_connection` |
|
||||
|
||||
## codersdk.CORSBehavior
|
||||
|
||||
```json
|
||||
"simple"
|
||||
```
|
||||
|
||||
### Properties
|
||||
|
||||
#### Enumerated Values
|
||||
|
||||
| Value |
|
||||
|------------|
|
||||
| `simple` |
|
||||
| `passthru` |
|
||||
|
||||
## codersdk.ChangePasswordWithOneTimePasscodeRequest
|
||||
|
||||
```json
|
||||
@@ -1475,6 +1490,7 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
|
||||
],
|
||||
"weeks": 0
|
||||
},
|
||||
"cors_behavior": "simple",
|
||||
"default_ttl_ms": 0,
|
||||
"delete_ttl_ms": 0,
|
||||
"description": "string",
|
||||
@@ -1501,6 +1517,7 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
|
||||
| `allow_user_cancel_workspace_jobs` | boolean | false | | Allow users to cancel in-progress workspace jobs. *bool as the default value is "true". |
|
||||
| `autostart_requirement` | [codersdk.TemplateAutostartRequirement](#codersdktemplateautostartrequirement) | false | | Autostart requirement allows optionally specifying the autostart allowed days for workspaces created from this template. This is an enterprise feature. |
|
||||
| `autostop_requirement` | [codersdk.TemplateAutostopRequirement](#codersdktemplateautostoprequirement) | false | | Autostop requirement allows optionally specifying the autostop requirement for workspaces created from this template. This is an enterprise feature. |
|
||||
| `cors_behavior` | [codersdk.CORSBehavior](#codersdkcorsbehavior) | false | | Cors behavior allows optionally specifying the CORS behavior for all shared ports. |
|
||||
| `default_ttl_ms` | integer | false | | Default ttl ms allows optionally specifying the default TTL for all workspaces created from this template. |
|
||||
| `delete_ttl_ms` | integer | false | | Delete ttl ms allows optionally specifying the max lifetime before Coder permanently deletes dormant workspaces created from this template. |
|
||||
| `description` | string | false | | Description is a description of what the template contains. It must be less than 128 bytes. |
|
||||
@@ -6970,6 +6987,7 @@ Only certain features set these fields: - FeatureManagedAgentLimit|
|
||||
"p95": 146
|
||||
}
|
||||
},
|
||||
"cors_behavior": "simple",
|
||||
"created_at": "2019-08-24T14:15:22Z",
|
||||
"created_by_id": "9377d689-01fb-4abf-8450-3368d2c1924f",
|
||||
"created_by_name": "string",
|
||||
@@ -7009,6 +7027,7 @@ Only certain features set these fields: - FeatureManagedAgentLimit|
|
||||
| `autostart_requirement` | [codersdk.TemplateAutostartRequirement](#codersdktemplateautostartrequirement) | false | | |
|
||||
| `autostop_requirement` | [codersdk.TemplateAutostopRequirement](#codersdktemplateautostoprequirement) | false | | Autostop requirement and AutostartRequirement are enterprise features. Its value is only used if your license is entitled to use the advanced template scheduling feature. |
|
||||
| `build_time_stats` | [codersdk.TemplateBuildTimeStats](#codersdktemplatebuildtimestats) | false | | |
|
||||
| `cors_behavior` | [codersdk.CORSBehavior](#codersdkcorsbehavior) | false | | |
|
||||
| `created_at` | string | false | | |
|
||||
| `created_by_id` | string | false | | |
|
||||
| `created_by_name` | string | false | | |
|
||||
|
||||
Generated
+13
@@ -57,6 +57,7 @@ To include deprecated templates, specify `deprecated:true` in the search query.
|
||||
"p95": 146
|
||||
}
|
||||
},
|
||||
"cors_behavior": "simple",
|
||||
"created_at": "2019-08-24T14:15:22Z",
|
||||
"created_by_id": "9377d689-01fb-4abf-8450-3368d2c1924f",
|
||||
"created_by_name": "string",
|
||||
@@ -113,6 +114,7 @@ Restarts will only happen on weekdays in this list on weeks which line up with W
|
||||
|`»» [any property]`|[codersdk.TransitionStats](schemas.md#codersdktransitionstats)|false|||
|
||||
|`»»» p50`|integer|false|||
|
||||
|`»»» p95`|integer|false|||
|
||||
|`» cors_behavior`|[codersdk.CORSBehavior](schemas.md#codersdkcorsbehavior)|false|||
|
||||
|`» created_at`|string(date-time)|false|||
|
||||
|`» created_by_id`|string(uuid)|false|||
|
||||
|`» created_by_name`|string|false|||
|
||||
@@ -141,6 +143,8 @@ Restarts will only happen on weekdays in this list on weeks which line up with W
|
||||
|
||||
| Property | Value |
|
||||
|------------------------|-----------------|
|
||||
| `cors_behavior` | `simple` |
|
||||
| `cors_behavior` | `passthru` |
|
||||
| `max_port_share_level` | `owner` |
|
||||
| `max_port_share_level` | `authenticated` |
|
||||
| `max_port_share_level` | `organization` |
|
||||
@@ -182,6 +186,7 @@ curl -X POST http://coder-server:8080/api/v2/organizations/{organization}/templa
|
||||
],
|
||||
"weeks": 0
|
||||
},
|
||||
"cors_behavior": "simple",
|
||||
"default_ttl_ms": 0,
|
||||
"delete_ttl_ms": 0,
|
||||
"description": "string",
|
||||
@@ -238,6 +243,7 @@ curl -X POST http://coder-server:8080/api/v2/organizations/{organization}/templa
|
||||
"p95": 146
|
||||
}
|
||||
},
|
||||
"cors_behavior": "simple",
|
||||
"created_at": "2019-08-24T14:15:22Z",
|
||||
"created_by_id": "9377d689-01fb-4abf-8450-3368d2c1924f",
|
||||
"created_by_name": "string",
|
||||
@@ -387,6 +393,7 @@ curl -X GET http://coder-server:8080/api/v2/organizations/{organization}/templat
|
||||
"p95": 146
|
||||
}
|
||||
},
|
||||
"cors_behavior": "simple",
|
||||
"created_at": "2019-08-24T14:15:22Z",
|
||||
"created_by_id": "9377d689-01fb-4abf-8450-3368d2c1924f",
|
||||
"created_by_name": "string",
|
||||
@@ -790,6 +797,7 @@ To include deprecated templates, specify `deprecated:true` in the search query.
|
||||
"p95": 146
|
||||
}
|
||||
},
|
||||
"cors_behavior": "simple",
|
||||
"created_at": "2019-08-24T14:15:22Z",
|
||||
"created_by_id": "9377d689-01fb-4abf-8450-3368d2c1924f",
|
||||
"created_by_name": "string",
|
||||
@@ -846,6 +854,7 @@ Restarts will only happen on weekdays in this list on weeks which line up with W
|
||||
|`»» [any property]`|[codersdk.TransitionStats](schemas.md#codersdktransitionstats)|false|||
|
||||
|`»»» p50`|integer|false|||
|
||||
|`»»» p95`|integer|false|||
|
||||
|`» cors_behavior`|[codersdk.CORSBehavior](schemas.md#codersdkcorsbehavior)|false|||
|
||||
|`» created_at`|string(date-time)|false|||
|
||||
|`» created_by_id`|string(uuid)|false|||
|
||||
|`» created_by_name`|string|false|||
|
||||
@@ -874,6 +883,8 @@ Restarts will only happen on weekdays in this list on weeks which line up with W
|
||||
|
||||
| Property | Value |
|
||||
|------------------------|-----------------|
|
||||
| `cors_behavior` | `simple` |
|
||||
| `cors_behavior` | `passthru` |
|
||||
| `max_port_share_level` | `owner` |
|
||||
| `max_port_share_level` | `authenticated` |
|
||||
| `max_port_share_level` | `organization` |
|
||||
@@ -990,6 +1001,7 @@ curl -X GET http://coder-server:8080/api/v2/templates/{template} \
|
||||
"p95": 146
|
||||
}
|
||||
},
|
||||
"cors_behavior": "simple",
|
||||
"created_at": "2019-08-24T14:15:22Z",
|
||||
"created_by_id": "9377d689-01fb-4abf-8450-3368d2c1924f",
|
||||
"created_by_name": "string",
|
||||
@@ -1120,6 +1132,7 @@ curl -X PATCH http://coder-server:8080/api/v2/templates/{template} \
|
||||
"p95": 146
|
||||
}
|
||||
},
|
||||
"cors_behavior": "simple",
|
||||
"created_at": "2019-08-24T14:15:22Z",
|
||||
"created_by_id": "9377d689-01fb-4abf-8450-3368d2c1924f",
|
||||
"created_by_name": "string",
|
||||
|
||||
Reference in New Issue
Block a user