-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: add --chat-hook-allow-insecure to allow plain HTTP chat hook URLs #27896
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
72573e6
feat: add --chat-hook-allow-insecure to allow plain HTTP chat hook URLs
ibetitsmike 779e11f
feat: warn that plain HTTP chat hook responses can be forged
ibetitsmike 31b466d
fix(coderd): redact hook URL in startup warning
ibetitsmike 8126f28
fix(codersdk): reject hostless chat hook URLs with a port at startup
ibetitsmike 8bf7fec
docs: state the insecure escape hatch in the chat hook URL description
ibetitsmike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,18 +78,25 @@ func TestDispatcherRejectsCleartextURL(t *testing.T) { | |
| _, _, err := dispatcher.Dispatch(testutil.Context(t, testutil.WaitShort), event) | ||
| require.ErrorContains(t, err, "must use HTTPS") | ||
|
|
||
| require.NoError(t, validateHookURL("")) | ||
| require.NoError(t, validateHookURL("https://hooks.example.com/coder")) | ||
| require.NoError(t, validateHookURL("http://localhost:8080/hooks")) | ||
| require.NoError(t, validateHookURL("http://127.0.0.1:8080/hooks")) | ||
| require.NoError(t, validateHookURL("http://[::1]:8080/hooks")) | ||
| require.Error(t, validateHookURL("http://10.0.0.5/hooks")) | ||
| require.Error(t, validateHookURL("ftp://hooks.example.com/coder")) | ||
| require.ErrorContains(t, validateHookURL("https:///coder"), "must include a host") | ||
| require.ErrorContains(t, validateHookURL("https:hooks.example.com"), "must include a host") | ||
| require.ErrorContains(t, validateHookURL("http:///hooks"), "must include a host") | ||
| require.ErrorContains(t, validateHookURL("https://hooks.example.com/coder#frag"), "must not contain a fragment") | ||
| require.ErrorContains(t, validateHookURL("https://user:[email protected]/coder"), "must not contain userinfo") | ||
| require.NoError(t, validateHookURL("", false)) | ||
| require.NoError(t, validateHookURL("https://hooks.example.com/coder", false)) | ||
| require.NoError(t, validateHookURL("http://localhost:8080/hooks", false)) | ||
| require.NoError(t, validateHookURL("http://127.0.0.1:8080/hooks", false)) | ||
| require.NoError(t, validateHookURL("http://[::1]:8080/hooks", false)) | ||
| require.Error(t, validateHookURL("http://10.0.0.5/hooks", false)) | ||
| require.Error(t, validateHookURL("ftp://hooks.example.com/coder", false)) | ||
| require.ErrorContains(t, validateHookURL("https:///coder", false), "must include a host") | ||
| require.ErrorContains(t, validateHookURL("https:hooks.example.com", false), "must include a host") | ||
| require.ErrorContains(t, validateHookURL("http:///hooks", false), "must include a host") | ||
| require.ErrorContains(t, validateHookURL("https://hooks.example.com/coder#frag", false), "must not contain a fragment") | ||
| require.ErrorContains(t, validateHookURL("https://user:[email protected]/coder", false), "must not contain userinfo") | ||
|
|
||
| require.NoError(t, validateHookURL("http://10.0.0.5/hooks", true)) | ||
| require.NoError(t, validateHookURL("http://hooks.example.com/coder", true)) | ||
| require.Error(t, validateHookURL("ftp://hooks.example.com/coder", true)) | ||
| require.ErrorContains(t, validateHookURL("http:///hooks", true), "must include a host") | ||
| require.ErrorContains(t, validateHookURL("http://hooks.example.com/coder#frag", true), "must not contain a fragment") | ||
| require.ErrorContains(t, validateHookURL("http://user:[email protected]/coder", true), "must not contain userinfo") | ||
| } | ||
|
|
||
| func TestDispatcherDeny(t *testing.T) { | ||
|
|
@@ -566,7 +573,7 @@ func TestDispatcherRejectedResponseIsNotObserved(t *testing.T) { | |
|
|
||
| registry := prometheus.NewRegistry() | ||
| dispatcher := New( | ||
| testutil.Logger(t), server.Client(), server.URL, testSecret, time.Second, | ||
| testutil.Logger(t), server.Client(), server.URL, false, testSecret, time.Second, | ||
| testDeploymentID, testVersion, registry, | ||
| ) | ||
| _, _, err := dispatcher.Dispatch(testutil.Context(t, testutil.WaitLong), event) | ||
|
|
@@ -655,6 +662,7 @@ func newTestDispatcher( | |
| testutil.Logger(t), | ||
| client, | ||
| hookURL, | ||
| false, | ||
| testSecret, | ||
| timeout, | ||
| testDeploymentID, | ||
|
|
@@ -738,7 +746,7 @@ func TestDispatcherAdmissionReserve(t *testing.T) { | |
| t.Cleanup(server.Close) | ||
|
|
||
| dispatcher := New( | ||
| testutil.Logger(t), server.Client(), server.URL, testSecret, testutil.WaitShort, | ||
| testutil.Logger(t), server.Client(), server.URL, false, testSecret, testutil.WaitShort, | ||
| testDeploymentID, testVersion, prometheus.NewRegistry(), | ||
| ) | ||
| event := newTestEvent(t, agenthooks.EventUserPromptSubmit, agenthooks.UserPromptSubmitData{Prompt: "hi"}) | ||
|
|
@@ -797,7 +805,7 @@ func TestDispatcherAdmissionReserve(t *testing.T) { | |
| t.Cleanup(server.Close) | ||
|
|
||
| dispatcher := New( | ||
| testutil.Logger(t), server.Client(), server.URL, testSecret, testutil.WaitShort, | ||
| testutil.Logger(t), server.Client(), server.URL, false, testSecret, testutil.WaitShort, | ||
| testDeploymentID, testVersion, prometheus.NewRegistry(), | ||
| ) | ||
| fill(t, dispatcher.admission, maxAdmissionDispatches) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -791,12 +791,13 @@ func TestDeploymentValues_Validate_ChatHooks(t *testing.T) { | |
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| disabled bool | ||
| url string | ||
| secret string | ||
| timeout time.Duration | ||
| wantErr string | ||
| name string | ||
| disabled bool | ||
| url string | ||
| secret string | ||
| timeout time.Duration | ||
| allowInsecure bool | ||
| wantErr string | ||
| }{ | ||
| { | ||
| name: "NoURL", | ||
|
|
@@ -821,20 +822,73 @@ func TestDeploymentValues_Validate_ChatHooks(t *testing.T) { | |
| timeout: 1500 * time.Millisecond, | ||
| wantErr: "chat hook URL must use HTTPS", | ||
| }, | ||
| { | ||
| name: "HTTPURLAllowInsecure", | ||
| url: "http://hooks.example.com/agent", | ||
| secret: "0123456789abcdef0123456789abcdef", | ||
| timeout: 1500 * time.Millisecond, | ||
| allowInsecure: true, | ||
| }, | ||
| { | ||
| name: "NonHTTPSchemeAllowInsecure", | ||
| url: "ftp://hooks.example.com/agent", | ||
| secret: "0123456789abcdef0123456789abcdef", | ||
| timeout: 1500 * time.Millisecond, | ||
| allowInsecure: true, | ||
| wantErr: "chat hook URL must use HTTPS", | ||
| }, | ||
| { | ||
| name: "AllowInsecureStillRequiresSecret", | ||
| url: "http://hooks.example.com/agent", | ||
| timeout: 1500 * time.Millisecond, | ||
| allowInsecure: true, | ||
| wantErr: "chat hook secret is required", | ||
| }, | ||
| { | ||
| name: "HostlessURL", | ||
| url: "https:///hook", | ||
| secret: "0123456789abcdef0123456789abcdef", | ||
| timeout: 1500 * time.Millisecond, | ||
| wantErr: "must include a host", | ||
| }, | ||
| { | ||
| name: "HostlessHTTPURLAllowInsecure", | ||
| url: "http:///hook", | ||
| secret: "0123456789abcdef0123456789abcdef", | ||
| timeout: 1500 * time.Millisecond, | ||
| allowInsecure: true, | ||
| wantErr: "set --chat-hook-url to a complete URL", | ||
| }, | ||
| { | ||
| name: "PortOnlyHTTPURLAllowInsecure", | ||
| url: "http://:8080/hooks", | ||
| secret: "0123456789abcdef0123456789abcdef", | ||
| timeout: 1500 * time.Millisecond, | ||
| allowInsecure: true, | ||
| wantErr: "must include a host", | ||
| }, | ||
| { | ||
| name: "PortOnlyHTTPSURL", | ||
| url: "https://:8080/hooks", | ||
| secret: "0123456789abcdef0123456789abcdef", | ||
| timeout: 1500 * time.Millisecond, | ||
| wantErr: "must include a host", | ||
| }, | ||
| { | ||
| name: "FragmentURL", | ||
| url: "https://hooks.example.com/agent#frag", | ||
| secret: "0123456789abcdef0123456789abcdef", | ||
| timeout: 1500 * time.Millisecond, | ||
| wantErr: "must not contain a fragment or userinfo", | ||
| }, | ||
| { | ||
| name: "FragmentHTTPURLAllowInsecure", | ||
| url: "http://hooks.example.com/agent#frag", | ||
| secret: "0123456789abcdef0123456789abcdef", | ||
| timeout: 1500 * time.Millisecond, | ||
| allowInsecure: true, | ||
| wantErr: "set --chat-hook-url to a URL without a fragment or userinfo", | ||
| }, | ||
| { | ||
| name: "UserinfoURL", | ||
| url: "https://user:[email protected]/agent", | ||
|
|
@@ -892,6 +946,7 @@ func TestDeploymentValues_Validate_ChatHooks(t *testing.T) { | |
| dv.AI.Chat.HookEnabled = serpent.Bool(!tt.disabled) | ||
| dv.AI.Chat.HookSecret = serpent.String(tt.secret) | ||
| dv.AI.Chat.HookTimeout = serpent.Duration(tt.timeout) | ||
| dv.AI.Chat.HookAllowInsecure = serpent.Bool(tt.allowInsecure) | ||
| if tt.url != "" { | ||
| require.NoError(t, dv.AI.Chat.HookURL.Set(tt.url)) | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.