TLS 对 omega-alpha 开启TLS通信

Saga 现在支持在omega和alpha服务之间采用 TLS 通信.同样客户端方面的认证(双向认证)。

准备证书 (Certificates)

你可以用下面的命令去生成一个用于测试的自签名的证书。如果你想采用双向认证的方式,只需要客户端证书。

  1. # Changes these CN's to match your hosts in your environment if needed.
  2. SERVER_CN=localhost
  3. CLIENT_CN=localhost # Used when doing mutual TLS
  4. echo Generate CA key:
  5. openssl genrsa -passout pass:1111 -des3 -out ca.key 4096
  6. echo Generate CA certificate:
  7. # Generates ca.crt which is the trustCertCollectionFile
  8. openssl req -passin pass:1111 -new -x509 -days 365 -key ca.key -out ca.crt -subj "/CN=${SERVER_CN}"
  9. echo Generate server key:
  10. openssl genrsa -passout pass:1111 -des3 -out server.key 4096
  11. echo Generate server signing request:
  12. openssl req -passin pass:1111 -new -key server.key -out server.csr -subj "/CN=${SERVER_CN}"
  13. echo Self-signed server certificate:
  14. # Generates server.crt which is the certChainFile for the server
  15. openssl x509 -req -passin pass:1111 -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt
  16. echo Remove passphrase from server key:
  17. openssl rsa -passin pass:1111 -in server.key -out server.key
  18. echo Generate client key
  19. openssl genrsa -passout pass:1111 -des3 -out client.key 4096
  20. echo Generate client signing request:
  21. openssl req -passin pass:1111 -new -key client.key -out client.csr -subj "/CN=${CLIENT_CN}"
  22. echo Self-signed client certificate:
  23. # Generates client.crt which is the clientCertChainFile for the client (need for mutual TLS only)
  24. openssl x509 -passin pass:1111 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt
  25. echo Remove passphrase from client key:
  26. openssl rsa -passin pass:1111 -in client.key -out client.key
  27. echo Converting the private keys to X.509:
  28. # Generates client.pem which is the clientPrivateKeyFile for the Client (needed for mutual TLS only)
  29. openssl pkcs8 -topk8 -nocrypt -in client.key -out client.pem
  30. # Generates server.pem which is the privateKeyFile for the Server
  31. openssl pkcs8 -topk8 -nocrypt -in server.key -out server.pem

TLS为Alpha服务开启TLS

1.为alpha-server修改application.yaml文件,在alpha.server部门增加ssl配置。

  1. alpha:
  2. server:
  3. ssl:
  4. enable: true
  5. cert: server.crt
  6. key: server.pem
  7. mutualAuth: true
  8. clientCert: client.crt
  • 将server.crt 和 server.pem 文件放到alpha-server的root 目录。如果你想双向认证,合并所有client证书到一个client.crt文件,并把client.crt文件放到root目录.

  • 重新启动alpha服务器.

为Omega启用TLS

  • 获取CA证书串(chain), 如果你是将alpha服务运行在集群中,你可能需要去合并多个CA证书到一个文件中.

  • 为客户端应用修改application.yaml文件, 在alpha.cluster 部分增加ssl配置.

  1. alpha:
  2. cluster:
  3. address: alpha-server.servicecomb.io:8080
  4. ssl:
  5. enable: false
  6. certChain: ca.crt
  7. mutualAuth: false
  8. cert: client.crt
  9. key: client.pem
  • 把ca.crt文件放到客户端应用程序的root目录 file under the client application root directory.如果你想用双向认证,仍需要把client.crt和client.pem放到root目录下.

  • 重新启动客户端应用程序.