mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-03 07:40:28 +08:00
* Move configuration from lib/service to lib/service/servicecfg The new servicecfg package will hold only configuration for services. This will allow other packages (like tctl and tsh) to depend on servicecfg without pulling in all of lib/service (which has a number of platform-specific details). This is the first step towards being able to build tctl for Windows. * Move PAM and BPF config into servicecfg This breaks a compile-time dependency on BPF/PAM for tctl.
258 lines
7.5 KiB
Go
258 lines
7.5 KiB
Go
// Copyright 2023 Gravitational, Inc
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package servicecfg
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"net/url"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gravitational/trace"
|
|
|
|
"github.com/gravitational/teleport/api/client/webclient"
|
|
"github.com/gravitational/teleport/lib/defaults"
|
|
"github.com/gravitational/teleport/lib/limiter"
|
|
"github.com/gravitational/teleport/lib/utils"
|
|
)
|
|
|
|
// ProxyConfig specifies the configuration for Teleport's Proxy Service
|
|
type ProxyConfig struct {
|
|
// Enabled turns proxy role on or off for this process
|
|
Enabled bool
|
|
|
|
// DisableTLS is enabled if we don't want self-signed certs
|
|
DisableTLS bool
|
|
|
|
// DisableWebInterface allows turning off serving the Web UI interface
|
|
DisableWebInterface bool
|
|
|
|
// DisableWebService turns off serving web service completely, including web UI
|
|
DisableWebService bool
|
|
|
|
// DisableReverseTunnel disables reverse tunnel on the proxy
|
|
DisableReverseTunnel bool
|
|
|
|
// DisableDatabaseProxy disables database access proxy listener
|
|
DisableDatabaseProxy bool
|
|
|
|
// ReverseTunnelListenAddr is address where reverse tunnel dialers connect to
|
|
ReverseTunnelListenAddr utils.NetAddr
|
|
|
|
// EnableProxyProtocol enables proxy protocol support
|
|
EnableProxyProtocol bool
|
|
|
|
// WebAddr is address for web portal of the proxy
|
|
WebAddr utils.NetAddr
|
|
|
|
// SSHAddr is address of ssh proxy
|
|
SSHAddr utils.NetAddr
|
|
|
|
// MySQLAddr is address of MySQL proxy.
|
|
MySQLAddr utils.NetAddr
|
|
|
|
// PostgresAddr is address of Postgres proxy.
|
|
PostgresAddr utils.NetAddr
|
|
|
|
// MongoAddr is address of Mongo proxy.
|
|
MongoAddr utils.NetAddr
|
|
|
|
// PeerAddress is the proxy peering address.
|
|
PeerAddress utils.NetAddr
|
|
|
|
// PeerPublicAddr is the public address the proxy advertises for proxy
|
|
// peering clients.
|
|
PeerPublicAddr utils.NetAddr
|
|
|
|
Limiter limiter.Config
|
|
|
|
// PublicAddrs is a list of the public addresses the proxy advertises
|
|
// for the HTTP endpoint. The hosts in PublicAddr are included in the
|
|
// list of host principals on the TLS and SSH certificate.
|
|
PublicAddrs []utils.NetAddr
|
|
|
|
// SSHPublicAddrs is a list of the public addresses the proxy advertises
|
|
// for the SSH endpoint. The hosts in PublicAddr are included in the
|
|
// list of host principals on the TLS and SSH certificate.
|
|
SSHPublicAddrs []utils.NetAddr
|
|
|
|
// TunnelPublicAddrs is a list of the public addresses the proxy advertises
|
|
// for the tunnel endpoint. The hosts in PublicAddr are included in the
|
|
// list of host principals on the TLS and SSH certificate.
|
|
TunnelPublicAddrs []utils.NetAddr
|
|
|
|
// PostgresPublicAddrs is a list of the public addresses the proxy
|
|
// advertises for Postgres clients.
|
|
PostgresPublicAddrs []utils.NetAddr
|
|
|
|
// MySQLPublicAddrs is a list of the public addresses the proxy
|
|
// advertises for MySQL clients.
|
|
MySQLPublicAddrs []utils.NetAddr
|
|
|
|
// MongoPublicAddrs is a list of the public addresses the proxy
|
|
// advertises for Mongo clients.
|
|
MongoPublicAddrs []utils.NetAddr
|
|
|
|
// Kube specifies kubernetes proxy configuration
|
|
Kube KubeProxyConfig
|
|
|
|
// KeyPairs are the key and certificate pairs that the proxy will load.
|
|
KeyPairs []KeyPairPath
|
|
|
|
// KeyPairsReloadInterval is the interval between attempts to reload
|
|
// x509 key pairs. If set to 0, then periodic reloading is disabled.
|
|
KeyPairsReloadInterval time.Duration
|
|
|
|
// ACME is ACME protocol support config
|
|
ACME ACME
|
|
|
|
// IdP is the identity provider config
|
|
//
|
|
//nolint:revive // Because we want this to be IdP.
|
|
IdP IdP
|
|
|
|
// DisableALPNSNIListener allows turning off the ALPN Proxy listener. Used in tests.
|
|
DisableALPNSNIListener bool
|
|
|
|
// UI provides config options for the web UI
|
|
UI webclient.UIConfig
|
|
}
|
|
|
|
// WebPublicAddr returns the address for the web endpoint on this proxy that
|
|
// can be reached by clients.
|
|
func (c ProxyConfig) WebPublicAddr() (string, error) {
|
|
return c.getDefaultAddr(c.WebAddr.Port(defaults.HTTPListenPort)), nil
|
|
}
|
|
|
|
func (c ProxyConfig) getDefaultAddr(port int) string {
|
|
host := "<proxyhost>"
|
|
// Try to guess the hostname from the HTTP public_addr.
|
|
if len(c.PublicAddrs) > 0 {
|
|
host = c.PublicAddrs[0].Host()
|
|
}
|
|
|
|
u := url.URL{
|
|
Scheme: "https",
|
|
Host: net.JoinHostPort(host, strconv.Itoa(port)),
|
|
}
|
|
return u.String()
|
|
}
|
|
|
|
// KubeAddr returns the address for the Kubernetes endpoint on this proxy that
|
|
// can be reached by clients.
|
|
func (c ProxyConfig) KubeAddr() (string, error) {
|
|
if !c.Kube.Enabled {
|
|
return "", trace.NotFound("kubernetes support not enabled on this proxy")
|
|
}
|
|
if len(c.Kube.PublicAddrs) > 0 {
|
|
return fmt.Sprintf("https://%s", c.Kube.PublicAddrs[0].Addr), nil
|
|
}
|
|
|
|
return c.getDefaultAddr(c.Kube.ListenAddr.Port(defaults.KubeListenPort)), nil
|
|
}
|
|
|
|
// PublicPeerAddr attempts to returns the public address the proxy advertises
|
|
// for proxy peering clients if available. It falls back to PeerAddr othewise.
|
|
func (c ProxyConfig) PublicPeerAddr() (*utils.NetAddr, error) {
|
|
addr := &c.PeerPublicAddr
|
|
if addr.IsEmpty() || addr.IsHostUnspecified() {
|
|
return c.PeerAddr()
|
|
}
|
|
return addr, nil
|
|
}
|
|
|
|
// PeerAddr returns the address the proxy advertises for proxy peering clients.
|
|
func (c ProxyConfig) PeerAddr() (*utils.NetAddr, error) {
|
|
addr := &c.PeerAddress
|
|
if addr.IsEmpty() {
|
|
addr = defaults.ProxyPeeringListenAddr()
|
|
}
|
|
if !addr.IsHostUnspecified() {
|
|
return addr, nil
|
|
}
|
|
|
|
ip, err := utils.GuessHostIP()
|
|
if err != nil {
|
|
return nil, trace.Wrap(err)
|
|
}
|
|
|
|
port := addr.Port(defaults.ProxyPeeringListenPort)
|
|
addr, err = utils.ParseAddr(fmt.Sprintf("%s:%d", ip.String(), port))
|
|
if err != nil {
|
|
return nil, trace.Wrap(err)
|
|
}
|
|
|
|
return addr, nil
|
|
}
|
|
|
|
// KubeProxyConfig specifies the Kubernetes configuration for Teleport's proxy service
|
|
type KubeProxyConfig struct {
|
|
// Enabled turns kubernetes proxy role on or off for this process
|
|
Enabled bool
|
|
|
|
// ListenAddr is the address to listen on for incoming kubernetes requests.
|
|
ListenAddr utils.NetAddr
|
|
|
|
// ClusterOverride causes all traffic to go to a specific remote
|
|
// cluster, used only in tests
|
|
ClusterOverride string
|
|
|
|
// PublicAddrs is a list of the public addresses the Teleport Kube proxy can be accessed by,
|
|
// it also affects the host principals and routing logic
|
|
PublicAddrs []utils.NetAddr
|
|
|
|
// KubeconfigPath is a path to kubeconfig
|
|
KubeconfigPath string
|
|
|
|
// LegacyKubeProxy specifies that this proxy was configured using the
|
|
// legacy kubernetes section.
|
|
LegacyKubeProxy bool
|
|
}
|
|
|
|
// ACME configures ACME automatic certificate renewal
|
|
type ACME struct {
|
|
// Enabled enables or disables ACME support
|
|
Enabled bool
|
|
// Email receives notifications from ACME server
|
|
Email string
|
|
// URI is ACME server URI
|
|
URI string
|
|
}
|
|
|
|
// IdP configures identity providers.
|
|
//
|
|
//nolint:revive // Because we want this to be IdP.
|
|
type IdP struct {
|
|
// SAMLIdP is configuration options for the SAML identity provider.
|
|
SAMLIdP SAMLIdP
|
|
}
|
|
|
|
// SAMLIdP configures SAML identity providers
|
|
type SAMLIdP struct {
|
|
// Enabled enables or disables the identity provider.
|
|
Enabled bool
|
|
// BaseURL is the base URL for the identity provider.
|
|
BaseURL string
|
|
}
|
|
|
|
// KeyPairPath are paths to a key and certificate file.
|
|
type KeyPairPath struct {
|
|
// PrivateKey is the path to a PEM encoded private key.
|
|
PrivateKey string
|
|
// Certificate is the path to a PEM encoded certificate.
|
|
Certificate string
|
|
}
|