feat: Add TURN proxying to enable offline deployments (#1000)

* Add turnconn

* Add option for passing ICE servers

* Log TURN remote address

* Add TURN server to coder start
This commit is contained in:
Kyle Carberry
2022-04-18 22:40:25 +00:00
committed by GitHub
parent e5a1c305d3
commit d202f20fdb
25 changed files with 603 additions and 112 deletions
+17 -10
View File
@@ -9,6 +9,7 @@ import (
"time"
"github.com/go-chi/chi/v5"
"github.com/pion/webrtc/v3"
"google.golang.org/api/idtoken"
chitrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi.v5"
@@ -20,23 +21,25 @@ import (
"github.com/coder/coder/coderd/gitsshkey"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/coderd/httpmw"
"github.com/coder/coder/coderd/turnconn"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/site"
)
// Options are requires parameters for Coder to start.
type Options struct {
AccessURL *url.URL
Logger slog.Logger
Database database.Store
Pubsub database.Pubsub
AgentConnectionUpdateFrequency time.Duration
AccessURL *url.URL
Logger slog.Logger
Database database.Store
Pubsub database.Pubsub
AWSCertificates awsidentity.Certificates
GoogleTokenValidator *idtoken.Validator
SecureAuthCookie bool
SSHKeygenAlgorithm gitsshkey.Algorithm
AWSCertificates awsidentity.Certificates
GoogleTokenValidator *idtoken.Validator
ICEServers []webrtc.ICEServer
SecureAuthCookie bool
SSHKeygenAlgorithm gitsshkey.Algorithm
TURNServer *turnconn.Server
}
// New constructs the Coder API into an HTTP handler.
@@ -175,6 +178,8 @@ func New(options *Options) (http.Handler, func()) {
r.Use(httpmw.ExtractWorkspaceAgent(options.Database))
r.Get("/", api.workspaceAgentListen)
r.Get("/gitsshkey", api.agentGitSSHKey)
r.Get("/turn", api.workspaceAgentTurn)
r.Get("/iceservers", api.workspaceAgentICEServers)
})
r.Route("/{workspaceagent}", func(r chi.Router) {
r.Use(
@@ -183,6 +188,8 @@ func New(options *Options) (http.Handler, func()) {
)
r.Get("/", api.workspaceAgent)
r.Get("/dial", api.workspaceAgentDial)
r.Get("/turn", api.workspaceAgentTurn)
r.Get("/iceservers", api.workspaceAgentICEServers)
})
})
r.Route("/workspaceresources/{workspaceresource}", func(r chi.Router) {