保护 OpenReplay
限制对节点的访问
Section titled 限制对节点的访问强烈建议使用安全组仅允许向该机器开放 80/443 端口。为了简化网络通信,有一些组件会监听 0.0.0.0 地址,例如 k3s 服务器 api、flannel api 等。
配置 SSL
Section titled 配置 SSL如果您要使用自己的证书,请使用以下命令创建一个 SSL secret:kubectl create secret tls openreplay-ssl -n app --key="private_key_file.pem" --cert="certificate.crt"。
注意: 如果您没有证书,请使用 Let’s Encrypt 为您的子域名(安装过程中提供的那个)生成一个可自动续期的证书。只需连接到 OpenReplay 实例,运行
cd openreplay/scripts/helmcharts && bash certmanager.sh并按照步骤操作即可。
如果您希望启用 http 到 https 的重定向(推荐),请使用 openreplay -e 编辑配置,然后在 ingress-nginx 部分下取消注释以下代码块:
ingress-nginx: &ingress-nginx
controller:
config:
ssl-redirect: true
force-ssl-redirect: true
注意: 我们的
ingress-nginx默认在80|443端口上运行,但如果需要,可以在vars.yaml中轻松更改:
ingress-nginx: &ingress-nginx
controller:
service:
ports:
http: 80
https: 443
使用 :wq 保存并退出,以便服务重新加载。
加固 X-Frame-Options
Section titled 加固 X-Frame-Options为了指示浏览器是否应允许在 <frame>, <iframe>, <embed> 或 <object> 中渲染页面,并防止点击劫持(click-jacking)攻击,请使用 openreplay -e 编辑配置以设置 X-Frame-Options 响应头:
ingress-nginx: &ingress-nginx
controller:
addHeaders:
X-Frame-Options: "SAMEORIGIN"
然后,使用 :wq 保存并退出,以便服务重新加载。
设置 reCaptcha
Section titled 设置 reCaptchaOpenReplay 支持 reCaptcha (v2) 以提供额外的安全性。要启用此保护:
- 从 Google 获取一个 v2 reCaptcha 密钥,并启用
invisible模式,即不提示tick I am not a human。 - 打开
/var/lib/openreplay/vars.yaml,然后在chalice部分取消注释并更新以下环境变量:
captcha_server:您的 reCaptcha 服务的 URL(例如 https://www.google.com/recaptcha/api/siteverify)captcha_key:您的 reCaptcha 密钥
- 编辑
openreplay/frontend/中的.env(如果不存在,请复制.env.sample),并将CAPTCHA_SITE_KEY变量替换为您的 reCaptcha 站点密钥。 - 重新构建前端:
cd openreplay/frontend
IMAGE_TAG=my-custom-image PUSH_IMAGE=1 DOCKER_REPO=my-docker-user-name bash -x build.sh
- 打开
/var/lib/openreplay/vars.yaml,并在frontend代码块中指定您新构建的前端镜像:
frontend:
image:
repository: "my-docker-username/frontend"
tag: "my-custom-image"
- 重启前端和 Web 服务器服务,使更改生效:
openreplay -R
内容安全策略 (CSP)
Section titled 内容安全策略 (CSP)以下是一个允许 OpenReplay 录制会话的策略 (CSP) 示例。需要根据您的域名和安全要求进行调整:
worker-src ‘self’ blob: https://openreplay.mycompany.com https://*.openreplay.com; script-src ‘self’ https://openreplay.mycompany.com https://*.openreplay.com;
要将您的 CSP 应用到 NGINX,请连接到您的 OpenReplay 实例并按照以下步骤操作:
- 运行
openreplay -e并在frontend代码块中添加您的 CSP。请确保更新
frontend:
ingress:
cspSnippet: |
add_header Content-Security-Policy "worker-src 'self' blob: https://openreplay.mycompany.com https://*.openreplay.com; script-src 'self' https://openreplay.mycompany.com https://*.openreplay.com;";
注意: 请务必将上述 CSP 中出现的
https://openreplay.mycompany.com替换为您的 OpenReplay 域名。该值应与/var/lib/openreplay/vars.yaml文件中的DOMAIN_NAME相同。
- 使用
:wq保存并退出,以应用您新添加的 CSP
启用 CORS
Section titled 启用 CORS默认情况下,跨域请求允许来自所有来源(Access-Control-Allow-Origin: *)。如果您希望仅限制录制来自少数几个域名,请运行 openreplay -e 并通过添加以下注解来更新 http 代码块:
http:
ingress:
annotations:
nginx.ingress.kubernetes.io/cors-allow-methods: POST
nginx.ingress.kubernetes.io/cors-allow-headers: Content-Type,Authorization,Content-Encoding
nginx.ingress.kubernetes.io/cors-allow-origin: https://app1.mycompany.com,https://app2.mycompany.com,https://*.mycompany.com
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-expose-headers: "Content-Length"
然后使用 :wq 保存并退出,以应用您新添加的 CSP。