-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit fixes #5177 Initial implementation uses dir backend as a cache and is OK for small clusters, but will be a problem for many proxies. This implementation uses Go autocert that is quite limited compared to Caddy's certmagic or lego. Autocert has no OCSP stapling and no locking for cache for example. However, it is much simpler and has no dependencies. It will be easier to extend to use Teleport backend as a cert cache. ```yaml proxy_service: public_addr: ['example.com'] # ACME - automatic certificate management environment. # # It provisions certificates for domains and # valid subdomains in public_addr section. # # The sudomains are valid if there is a registered application. # For example, app.example.com will get a cert if app is a regsitered # application access app. The sudomain cookie.example.com is not. # # Teleport acme is using TLS-ALPN-01 challenge: # # https://letsencrypt.org/docs/challenge-types/#tls-alpn-01 # acme: # By default acme is disabled. enabled: true # Use a custom URI, for example staging is # # https://acme-staging-v02.api.letsencrypt.org/directory # # Default is letsencrypt.org production URL: # # https://acme-v02.api.letsencrypt.org/directory uri: '' # Set email to receive alerts and other correspondence # from your certificate authority. email: '[email protected]' ```
- Loading branch information
1 parent
96019ce
commit c0bb732
Showing
20 changed files
with
4,557 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
Copyright 2015-2020 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 service | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"strings" | ||
|
||
"github.com/gravitational/teleport/lib/reversetunnel" | ||
"github.com/gravitational/teleport/lib/utils" | ||
"github.com/gravitational/teleport/lib/web/app" | ||
|
||
"github.com/gravitational/trace" | ||
) | ||
|
||
type hostPolicyCheckerConfig struct { | ||
// publicAddrs is a list of pubic addresses to support acme for | ||
publicAddrs []utils.NetAddr | ||
// clt is used to get the list of registered applications | ||
clt app.Getter | ||
// tun is a reverse tunnel | ||
tun reversetunnel.Tunnel | ||
// clusterName is a name of this cluster | ||
clusterName string | ||
} | ||
|
||
type hostPolicyChecker struct { | ||
dnsNames []string | ||
cfg hostPolicyCheckerConfig | ||
} | ||
|
||
// checkHost approves getting certs for hosts specified in public_addr | ||
// and their subdomains, if there is a valid application name registered | ||
func (h *hostPolicyChecker) checkHost(ctx context.Context, host string) error { | ||
if ip := net.ParseIP(host); ip != nil { | ||
return trace.BadParameter( | ||
"with proxy_service.acme on, IP URL https://%v is not supported, use one of the domains in proxy_service.public_addr: %v", | ||
host, strings.Join(h.dnsNames, ",")) | ||
} | ||
|
||
var couldNotMatchApp bool | ||
for _, dnsName := range h.dnsNames { | ||
if dnsName == host { | ||
return nil | ||
} | ||
// if it's a subdomain, allow it if application access | ||
// has the name that matches the fqdn | ||
if strings.HasSuffix(host, "."+dnsName) { | ||
_, _, _, err := app.ResolveFQDN(ctx, h.cfg.clt, h.cfg.tun, h.cfg.clusterName, host) | ||
if err == nil { | ||
return nil | ||
} | ||
if !trace.IsNotFound(err) { | ||
return trace.Wrap(err) | ||
} | ||
couldNotMatchApp = true | ||
} | ||
} | ||
|
||
if couldNotMatchApp { | ||
return trace.BadParameter( | ||
"acme can't get a cert for %v, there is no app with this name", host) | ||
} | ||
|
||
return trace.BadParameter( | ||
"acme can't get a cert for domain %v, add it to the proxy_service.public_addr, or use one of the domains: %v", | ||
host, strings.Join(h.dnsNames, ",")) | ||
} | ||
|
||
func newHostPolicyChecker(cfg hostPolicyCheckerConfig) (*hostPolicyChecker, error) { | ||
dnsNames, err := cfg.CheckAndSetDefaults() | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
|
||
return &hostPolicyChecker{ | ||
dnsNames: dnsNames, | ||
cfg: cfg, | ||
}, nil | ||
} | ||
|
||
func (h *hostPolicyCheckerConfig) CheckAndSetDefaults() ([]string, error) { | ||
if h.clt == nil { | ||
return nil, trace.BadParameter("missing parameter clt") | ||
} | ||
|
||
if h.tun == nil { | ||
return nil, trace.BadParameter("missing parameter tun") | ||
} | ||
|
||
dnsNames := make([]string, 0, len(h.publicAddrs)) | ||
|
||
for _, addr := range h.publicAddrs { | ||
host, err := utils.Host(addr.Addr) | ||
if err != nil { | ||
return nil, trace.Wrap(err) | ||
} | ||
if ip := net.ParseIP(host); ip == nil { | ||
dnsNames = append(dnsNames, host) | ||
} | ||
} | ||
|
||
if len(dnsNames) == 0 { | ||
return nil, trace.BadParameter( | ||
"acme is enabled, set at least one valid DNS name in public_addr section of proxy_service") | ||
} | ||
|
||
return dnsNames, nil | ||
} |
This file contains 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 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 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 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
Oops, something went wrong.