mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
chore: make authz recorder opt in (#20310)
The authz recorder is causing a lot of memory to be allocated, and is a memory leak for websocket connections. This change makes it opt-in on a per request basis (ontop of `isDev`). To get the authz headers, use `Copy as cURL` on chrome and append the header `x-authz-checks=true`.
This commit is contained in:
Generated
+3
@@ -13977,6 +13977,9 @@ const docTemplate = `{
|
||||
"docs_url": {
|
||||
"$ref": "#/definitions/serpent.URL"
|
||||
},
|
||||
"enable_authz_recording": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"enable_terraform_debug_mode": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
Generated
+3
@@ -12595,6 +12595,9 @@
|
||||
"docs_url": {
|
||||
"$ref": "#/definitions/serpent.URL"
|
||||
},
|
||||
"enable_authz_recording": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"enable_terraform_debug_mode": {
|
||||
"type": "boolean"
|
||||
},
|
||||
|
||||
+1
-1
@@ -493,7 +493,7 @@ func New(options *Options) *API {
|
||||
// We add this middleware early, to make sure that authorization checks made
|
||||
// by other middleware get recorded.
|
||||
if buildinfo.IsDev() {
|
||||
r.Use(httpmw.RecordAuthzChecks)
|
||||
r.Use(httpmw.RecordAuthzChecks(options.DeploymentValues.EnableAuthzRecording.Value()))
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
+17
-6
@@ -4,6 +4,7 @@ package httpmw
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
|
||||
@@ -39,14 +40,24 @@ func AsAuthzSystem(mws ...func(http.Handler) http.Handler) func(http.Handler) ht
|
||||
}
|
||||
}
|
||||
|
||||
// RecordAuthzChecks enables recording all of the authorization checks that
|
||||
// RecordAuthzChecks enables recording all the authorization checks that
|
||||
// occurred in the processing of a request. This is mostly helpful for debugging
|
||||
// and understanding what permissions are required for a given action.
|
||||
//
|
||||
// Can either be toggled on by a deployment wide configuration value, or opt-in on
|
||||
// a per-request basis by setting the `x-record-authz-checks` header to a truthy value.
|
||||
//
|
||||
// Requires using a Recorder Authorizer.
|
||||
func RecordAuthzChecks(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
r = r.WithContext(rbac.WithAuthzCheckRecorder(r.Context()))
|
||||
next.ServeHTTP(rw, r)
|
||||
})
|
||||
//
|
||||
//nolint:revive
|
||||
func RecordAuthzChecks(always bool) func(next http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
if enabled, _ := strconv.ParseBool(r.Header.Get("x-record-authz-checks")); enabled || always {
|
||||
r = r.WithContext(rbac.WithAuthzCheckRecorder(r.Context()))
|
||||
}
|
||||
|
||||
next.ServeHTTP(rw, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -487,6 +487,7 @@ type DeploymentValues struct {
|
||||
Sessions SessionLifetime `json:"session_lifetime,omitempty" typescript:",notnull"`
|
||||
DisablePasswordAuth serpent.Bool `json:"disable_password_auth,omitempty" typescript:",notnull"`
|
||||
Support SupportConfig `json:"support,omitempty" typescript:",notnull"`
|
||||
EnableAuthzRecording serpent.Bool `json:"enable_authz_recording,omitempty" typescript:",notnull"`
|
||||
ExternalAuthConfigs serpent.Struct[[]ExternalAuthConfig] `json:"external_auth,omitempty" typescript:",notnull"`
|
||||
SSHConfig SSHConfig `json:"config_ssh,omitempty" typescript:",notnull"`
|
||||
WgtunnelHost serpent.String `json:"wgtunnel_host,omitempty" typescript:",notnull"`
|
||||
@@ -3293,6 +3294,19 @@ Write out the current server config as YAML to stdout.`,
|
||||
YAML: "key",
|
||||
Hidden: true,
|
||||
},
|
||||
{
|
||||
Name: "Enable Authorization Recordings",
|
||||
Description: "All api requests will have a header including all authorization calls made during the request. " +
|
||||
"This is used for debugging purposes and only available for dev builds.",
|
||||
Required: false,
|
||||
Flag: "enable-authz-recordings",
|
||||
Env: "CODER_ENABLE_AUTHZ_RECORDINGS",
|
||||
Default: "false",
|
||||
Value: &c.EnableAuthzRecording,
|
||||
// Do not show this option ever. It is a developer tool only, and not to be
|
||||
// used externally.
|
||||
Hidden: true,
|
||||
},
|
||||
}
|
||||
|
||||
return opts
|
||||
|
||||
Generated
+1
@@ -237,6 +237,7 @@ curl -X GET http://coder-server:8080/api/v2/deployment/config \
|
||||
"scheme": "string",
|
||||
"user": {}
|
||||
},
|
||||
"enable_authz_recording": true,
|
||||
"enable_terraform_debug_mode": true,
|
||||
"ephemeral_deployment": true,
|
||||
"experiments": [
|
||||
|
||||
Generated
+3
@@ -2892,6 +2892,7 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o
|
||||
"scheme": "string",
|
||||
"user": {}
|
||||
},
|
||||
"enable_authz_recording": true,
|
||||
"enable_terraform_debug_mode": true,
|
||||
"ephemeral_deployment": true,
|
||||
"experiments": [
|
||||
@@ -3397,6 +3398,7 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o
|
||||
"scheme": "string",
|
||||
"user": {}
|
||||
},
|
||||
"enable_authz_recording": true,
|
||||
"enable_terraform_debug_mode": true,
|
||||
"ephemeral_deployment": true,
|
||||
"experiments": [
|
||||
@@ -3731,6 +3733,7 @@ CreateWorkspaceRequest provides options for creating a new workspace. Only one o
|
||||
| `disable_password_auth` | boolean | false | | |
|
||||
| `disable_path_apps` | boolean | false | | |
|
||||
| `docs_url` | [serpent.URL](#serpenturl) | false | | |
|
||||
| `enable_authz_recording` | boolean | false | | |
|
||||
| `enable_terraform_debug_mode` | boolean | false | | |
|
||||
| `ephemeral_deployment` | boolean | false | | |
|
||||
| `experiments` | array of string | false | | |
|
||||
|
||||
Generated
+1
@@ -1755,6 +1755,7 @@ export interface DeploymentValues {
|
||||
readonly session_lifetime?: SessionLifetime;
|
||||
readonly disable_password_auth?: boolean;
|
||||
readonly support?: SupportConfig;
|
||||
readonly enable_authz_recording?: boolean;
|
||||
readonly external_auth?: SerpentStruct<ExternalAuthConfig[]>;
|
||||
readonly config_ssh?: SSHConfig;
|
||||
readonly wgtunnel_host?: string;
|
||||
|
||||
Reference in New Issue
Block a user