2021-07-30 17:46:38 +02:00
|
|
|
package server
|
|
|
|
|
2021-09-02 14:41:54 +02:00
|
|
|
import (
|
2022-05-13 14:11:21 +02:00
|
|
|
"net/url"
|
|
|
|
|
2022-03-26 12:08:54 +01:00
|
|
|
"github.com/netbirdio/netbird/management/server/idp"
|
|
|
|
"github.com/netbirdio/netbird/util"
|
2021-09-02 14:41:54 +02:00
|
|
|
)
|
|
|
|
|
2021-07-30 17:46:38 +02:00
|
|
|
type Protocol string
|
2022-05-08 11:04:57 +02:00
|
|
|
type Provider string
|
2021-07-30 17:46:38 +02:00
|
|
|
|
|
|
|
const (
|
|
|
|
UDP Protocol = "udp"
|
|
|
|
DTLS Protocol = "dtls"
|
|
|
|
TCP Protocol = "tcp"
|
|
|
|
HTTP Protocol = "http"
|
|
|
|
HTTPS Protocol = "https"
|
2022-08-24 14:37:18 +02:00
|
|
|
NONE Provider = "none"
|
2021-07-30 17:46:38 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config of the Management service
|
|
|
|
type Config struct {
|
2021-09-02 14:41:54 +02:00
|
|
|
Stuns []*Host
|
|
|
|
TURNConfig *TURNConfig
|
|
|
|
Signal *Host
|
2021-07-30 17:46:38 +02:00
|
|
|
|
2021-08-07 13:35:52 +02:00
|
|
|
Datadir string
|
2021-08-07 12:26:07 +02:00
|
|
|
|
|
|
|
HttpConfig *HttpServerConfig
|
2022-01-24 11:21:30 +01:00
|
|
|
|
|
|
|
IdpManagerConfig *idp.Config
|
2022-05-08 11:04:57 +02:00
|
|
|
|
|
|
|
DeviceAuthorizationFlow *DeviceAuthorizationFlow
|
2021-08-07 12:26:07 +02:00
|
|
|
}
|
|
|
|
|
2021-09-02 14:41:54 +02:00
|
|
|
// TURNConfig is a config of the TURNCredentialsManager
|
|
|
|
type TURNConfig struct {
|
|
|
|
TimeBasedCredentials bool
|
|
|
|
CredentialsTTL util.Duration
|
2021-09-03 17:47:40 +02:00
|
|
|
Secret string
|
2021-09-02 14:41:54 +02:00
|
|
|
Turns []*Host
|
|
|
|
}
|
|
|
|
|
2021-08-07 13:35:52 +02:00
|
|
|
// HttpServerConfig is a config of the HTTP Management service server
|
2021-08-07 12:26:07 +02:00
|
|
|
type HttpServerConfig struct {
|
2021-08-07 13:35:52 +02:00
|
|
|
LetsEncryptDomain string
|
2021-09-25 19:22:49 +02:00
|
|
|
//CertFile is the location of the certificate
|
|
|
|
CertFile string
|
|
|
|
//CertKey is the location of the certificate private key
|
|
|
|
CertKey string
|
2021-08-12 12:49:10 +02:00
|
|
|
// AuthAudience identifies the recipients that the JWT is intended for (aud in JWT)
|
|
|
|
AuthAudience string
|
|
|
|
// AuthIssuer identifies principal that issued the JWT.
|
|
|
|
AuthIssuer string
|
|
|
|
// AuthKeysLocation is a location of JWT key set containing the public keys used to verify JWT
|
|
|
|
AuthKeysLocation string
|
2022-08-23 15:46:12 +02:00
|
|
|
// OIDCConfigEndpoint is the endpoint of an IDP manager to get OIDC configuration
|
|
|
|
OIDCConfigEndpoint string
|
2021-07-30 17:46:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Host represents a Wiretrustee host (e.g. STUN, TURN, Signal)
|
|
|
|
type Host struct {
|
|
|
|
Proto Protocol
|
|
|
|
// URI e.g. turns://stun.wiretrustee.com:4430 or signal.wiretrustee.com:10000
|
|
|
|
URI string
|
|
|
|
Username string
|
2021-09-03 17:47:40 +02:00
|
|
|
Password string
|
2021-07-30 17:46:38 +02:00
|
|
|
}
|
2022-05-05 20:02:15 +02:00
|
|
|
|
2022-05-08 11:04:57 +02:00
|
|
|
// DeviceAuthorizationFlow represents Device Authorization Flow information
|
|
|
|
// that can be used by the client to login initiate a Oauth 2.0 device authorization grant flow
|
|
|
|
// see https://datatracker.ietf.org/doc/html/rfc8628
|
|
|
|
type DeviceAuthorizationFlow struct {
|
|
|
|
Provider string
|
|
|
|
ProviderConfig ProviderConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
// ProviderConfig has all attributes needed to initiate a device authorization flow
|
|
|
|
type ProviderConfig struct {
|
|
|
|
// ClientID An IDP application client id
|
|
|
|
ClientID string
|
|
|
|
// ClientSecret An IDP application client secret
|
|
|
|
ClientSecret string
|
|
|
|
// Domain An IDP API domain
|
2022-08-23 15:46:12 +02:00
|
|
|
// Deprecated. Use TokenEndpoint and DeviceAuthEndpoint
|
2022-05-08 11:04:57 +02:00
|
|
|
Domain string
|
|
|
|
// Audience An Audience for to authorization validation
|
|
|
|
Audience string
|
2022-08-23 15:46:12 +02:00
|
|
|
// TokenEndpoint is the endpoint of an IDP manager where clients can obtain access token
|
|
|
|
TokenEndpoint string
|
|
|
|
// DeviceAuthEndpoint is the endpoint of an IDP manager where clients can obtain device authorization code
|
|
|
|
DeviceAuthEndpoint string
|
2022-05-08 11:04:57 +02:00
|
|
|
}
|
|
|
|
|
2022-05-05 20:02:15 +02:00
|
|
|
// validateURL validates input http url
|
|
|
|
func validateURL(httpURL string) bool {
|
|
|
|
_, err := url.ParseRequestURI(httpURL)
|
2022-05-12 11:17:24 +02:00
|
|
|
return err == nil
|
2022-05-05 20:02:15 +02:00
|
|
|
}
|