HTTPS 加密#

SkyServe 支持通过 HTTPS 安全地部署模型服务,这对于处理敏感数据或需要与其他服务进行安全通信的模型至关重要。目前,SkyServe 支持 HTTPS 加密端点(用于客户端和负载均衡器之间的通信);负载均衡器和服务副本之间的 HTTPS 尚未支持。

提示

要了解有关 TLS 和 HTTPS 的更多信息,请参阅此处

HTTPS 加密端点#

要创建 HTTPS 加密端点,您需要提供证书和私钥。从受信任的证书颁发机构 (CA) 获取这些是更安全的方法。Let’s Encrypt 是最受欢迎的免费解决方案之一。但是,出于开发和测试目的,您可以使用 openssl 命令行工具生成自签名证书和私钥。以下是生成它们的示例:

$ openssl req -x509 -newkey rsa:2048 -days 36500 -nodes -keyout <key-path> -out <cert-path>

您可以将其作为文件提供

# https.yaml
service:
  readiness_probe: /
  tls:
    keyfile: <key-path>
    certfile: <cert-path>

resources:
  ports: 8080

run: python3 -m http.server 8080

要部署服务,请运行以下命令

$ sky serve up https.yaml -n my-service

如果您使用的是自签名证书,您可能需要在 curl 命令中添加 -k 标志以绕过证书检查。

$ ENDPOINT=$(sky serve status --endpoint my-service)
$ curl -k $ENDPOINT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Directory listing for /?</title>
</head>
<body>
<h1>Directory listing for /?</h1>
<hr>
<ul>
</ul>
<hr>
</body>
</html>

如果您使用的方案错误(HTTP 而非 HTTPS),或者自签名证书没有 -k 标志,您将看到错误消息。

$ curl $ENDPOINT
curl: (60) SSL certificate problem: self signed certificate
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
$ curl "${ENDPOINT/https:/http:}"
curl: (52) Empty reply from server