Dengan mengonfigurasi sertifikat HTTPS, Anda dapat mengaktifkan enkripsi Transport Layer Security (TLS)/Secure Sockets Layer (SSL) untuk layanan yang diterapkan pada gateway MSE Ingress. Ini merupakan langkah penting untuk mengamankan data pada aplikasi web modern dan layanan API. Sertifikat HTTPS memastikan bahwa data yang ditransmisikan antara klien dan gateway dienkripsi, sehingga mencegah pihak tidak sah mencuri atau mengubah informasi sensitif, serta memberikan perlindungan kuat terhadap serangan man-in-the-middle.
Prasyarat
-
Anda telah mengekspos layanan melalui gateway MSE Ingress. Untuk informasi selengkapnya, lihat Akses layanan di Container Service for Kubernetes (ACK) melalui gateway MSE Ingress atau Akses layanan di ACK Serverless melalui gateway MSE Ingress.
-
Anda memiliki sertifikat digital tepercaya. Anda dapat memperolehnya dengan cara berikut:
-
Membeli sertifikat dari Alibaba Cloud Certificate Management Service. Untuk informasi selengkapnya, lihat Beli sertifikat SSL.
-
Menggunakan sertifikat yang dibeli dari Certificate Authority (CA) lain.
-
Membuat sertifikat tanda tangan sendiri secara lokal.
-
Metode konfigurasi
Gateway MSE Ingress mendukung dua metode untuk mengonfigurasi sertifikat HTTPS: menggunakan Kubernetes Secret atau menggunakan Konsol MSE.
|
Item |
Kubernetes Secret |
MSE console |
|
Use cases |
|
|
|
Priority |
Low |
High |
|
Cross-namespace |
Not supported. |
Supported. |
|
Certificate update |
Replace the content of the Kubernetes Secret. |
Replace the certificate on the MSE console or deploy a new certificate on the Certificate Management Service console. |
Terapkan layanan backend
-
Masuk ke Konsol Container Service for Kubernetes (ACK). Di panel navigasi kiri, klik Clusters.
-
Pada halaman Clusters, klik nama kluster target Anda. Di panel navigasi kiri, pilih .
-
Pada halaman Deployments, klik Create from YAML. Gunakan YAML berikut untuk menerapkan Deployment httpbin dan Service httpbin.
apiVersion: apps/v1 kind: Deployment metadata: name: httpbin namespace: default spec: replicas: 1 selector: matchLabels: app: httpbin template: metadata: labels: app: httpbin version: v1 spec: containers: - image: registry.cn-hangzhou.aliyuncs.com/mse-ingress/go-httpbin args: - "--version=v1" imagePullPolicy: Always name: httpbin --- apiVersion: v1 kind: Service metadata: name: httpbin namespace: default spec: ports: - port: 8080 protocol: TCP selector: app: httpbin
Konfigurasikan sertifikat HTTPS
Kubernetes Secret
Anda dapat mengonfigurasi sertifikat HTTPS untuk domain dengan mereferensikan Kubernetes Secret menggunakan semantik Ingress native.
-
Siapkan sertifikat domain. Contoh ini menggunakan sertifikat tanda tangan sendiri.
CatatanUntuk lingkungan produksi, Anda harus menggunakan kunci privat dan sertifikat asli untuk bisnis Anda. Anda dapat mengunduh kunci dan sertifikat untuk domain Anda dari Konsol Certificate Management Service.
-
Jalankan perintah berikut untuk menghasilkan file sertifikat tls.crt dan file kunci privat tls.key.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=foo.bar.com/O=foo.bar.com" -
Buat Secret untuk menyimpan sertifikat TLS.
-
Masuk ke Konsol Container Service for Kubernetes (ACK). Di panel navigasi kiri, klik Clusters.
-
Pada halaman Clusters, klik nama kluster target Anda. Di panel navigasi kiri, pilih .
-
Klik Create. Di panel Create, atur Name menjadi tls-test, pilih Type sebagai TLS Certificate, salin konten tls.crt dan tls.key yang telah dibuat ke kotak input yang sesuai, lalu klik Create.
-
-
-
Buat MSE Ingress dan konfigurasikan sertifikat HTTPS untuk domain
foo.bar.com.-
Di panel navigasi kiri, pilih Network > Ingresses.
-
Pada halaman Ingresses, klik Create Ingress. Di dialog Create Ingress, konfigurasi entri rute.
Parameter
Description
Example
Gateway type
Select MSE Ingress. For a comparison of different gateway types, see Comparison of Nginx Ingress, ALB Ingress, APIG Ingress, and MSE Ingress.
MSE Ingress
Name
Enter a custom name for the Ingress.
test
IngressClass
Select the relevant resource class.
mse
Rule
Click + Add Rule to add routing rules.
-
Domain name: A custom domain name.
-
Path mapping: Configure the following parameters.
-
Path: The URL path for accessing the service.
-
Match rule:
-
Prefix (prefix-based match): Matches the prefix of the request URL path.
-
Exact (exact match): Exactly matches the request URL path.
-
Default (implementation-specific): The behavior is determined by the specific logic of the Ingress controller.
For more information, see Advanced features of ALB Ingresses.
-
-
Service: The target Kubernetes Service.
-
Port: The port to expose for the service.
-
-
Ingress supports multiple paths under the same domain name. Click + Add Path to add more paths.
-
Domain name: foo.bar.com
-
Path mapping:
-
Path: /
-
Match rule: Prefix (prefix-based match)
-
Service: httpbin
-
Port: 8080
-
TLS configuration
Enable TLS to configure a secure routing service.
-
Domain name: A custom domain name.
-
Secret: Select the appropriate Secret.
Note
Leaving this empty enables certificate auto-discovery.
To create a new Secret:
-
To the right of the Secret field, click Create.
-
In the Create Secret dialog box, specify a Name, Cert, and Key for the Secret, and then click OK.
-
From the Secret drop-down list, select the Secret you created.
-
Click + Add TLS Configuration to configure multiple TLS settings.
-
Domain name: foo.bar.com
-
Secret: tls-test
-
-
Biarkan pengaturan lainnya tetap default dan klik OK pada halaman Create Ingress.
-
-
Uji trafik HTTPS. Jalankan perintah berikut, ganti
x.x.x.xdengan alamat IP gateway aktual Anda. Anda dapat menemukan alamat IP gateway di halaman daftar Ingresses.CatatanContoh ini menggunakan sertifikat tanda tangan sendiri dan domain yang tidak terdaftar di penyedia DNS. Oleh karena itu, Anda harus menggunakan flag
--resolveuntuk menyelesaikan nama domain ke alamat IP gateway secara manual dan flag-kuntuk melewati validasi sertifikat.curl -v -k https://foo.bar.com/version --resolve "foo.bar.com:443:x.x.x.x"Output yang diharapkan adalah sebagai berikut:
* Connected to foo.bar.com (X.X.X.X) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/cert.pem CApath: none * TLSv1.2 (OUT), TLS handshake, Client hello (1): * TLSv1.2 (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server key exchange (12): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS change cipher, Change cipher spec (1): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 * ALPN, server accepted to use http/1.1 * Server certificate: * subject: CN=foo.bar.com; O=foo.bar.com * start date: Jan 17 06:47:23 2024 GMT * expire date: Jan 16 06:47:23 2025 GMT * issuer: CN=foo.bar.com; O=foo.bar.com * SSL certificate verify result: self signed certificate (18), continuing anyway. > GET /version HTTP/1.1 > Host: foo.bar.com > User-Agent: curl/7.64.1 > Accept: */* > < HTTP/1.1 200 OK < date: Wed, 17 Jan 2024 07:49:39 GMT < content-length: 53 < content-type: text/plain; charset=utf-8 < req-cost-time: 3 < req-arrive-time: 1705477779046 < resp-start-time: 1705477779049 < x-envoy-upstream-service-time: 2 < server: istio-envoy < version: v1 hostname: httpbin-xxxxxx
MSE console
Anda dapat mengonfigurasi sertifikat untuk domain langsung di Konsol MSE. Metode ini tidak mengharuskan Anda mereferensikan Kubernetes Secret dalam objek Ingress; Anda hanya perlu mengonfigurasi aturan routing.
Untuk nama domain yang sama, metode Konsol MSE memiliki prioritas lebih tinggi daripada metode Kubernetes Secret. Jika Anda mengonfigurasi sertifikat untuk domain yang sama baik di Konsol MSE maupun pada resource Ingress Kubernetes, sertifikat dari konsol yang akan digunakan.
-
Siapkan sertifikat domain dan unggah ke Alibaba Cloud Certificate Management Service. Untuk informasi selengkapnya, lihat Unggah, sinkronkan, dan bagikan sertifikat SSL. Jika sertifikat Anda sudah dihosting di Certificate Management Service, Anda dapat melewati langkah ini.
-
Buat domain dan konfigurasikan sertifikatnya.
-
Masuk ke Konsol Manajemen Gateway MSE dan pilih wilayah di bilah navigasi atas.
-
Di panel navigasi kiri, pilih Cloud-native Gateway > Gateways, lalu klik ID instans gateway target.
-
Di panel navigasi kiri, klik Routes, lalu pilih tab Domain.
-
Klik Add domain name. Tambahkan Domain name, atur Protocol ke HTTPS, lalu pilih sertifikat yang sesuai.
-
-
Buat layanan.
-
Pada halaman Manajemen Rute instans MSE, pilih tab Service dan klik Create service.
-
Atur Service Sources ke Container service, pilih Namespaces yang sesuai, centang layanan
httpbinyang telah Anda buat sebelumnya di Service list, lalu klik OK.
-
-
Buat entri rute.
-
Pada halaman Manajemen Rute instans MSE, pilih tab Route dan klik Create route.
-
Untuk Domain name, pilih domain yang Anda tambahkan di Langkah 2. Untuk Backend service, pilih layanan yang Anda buat di Langkah 3, lalu klik Save and publish.
-
-
Uji trafik HTTPS. Jalankan perintah berikut, ganti
x.x.x.xdengan alamat IP gateway aktual Anda. Anda dapat menemukan alamat IP gateway di halaman .CatatanJika Anda menggunakan sertifikat tanda tangan sendiri dan domain tidak terdaftar di penyedia DNS, Anda harus menggunakan flag
--resolveuntuk menyelesaikan nama domain ke alamat IP gateway secara manual dan flag-kuntuk melewati validasi sertifikat.Ganti
<Your-DomainName>dengan nama domain aktual Anda.curl -v -k https://<Your-DomainName>/version --resolve "<Your-DomainName>:443:x.x.x.x"Output yang diharapkan adalah sebagai berikut:
* Connected to ********** (X.X.X.X) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/cert.pem CApath: none * TLSv1.2 (OUT), TLS handshake, Client hello (1): * TLSv1.2 (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server key exchange (12): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS change cipher, Change cipher spec (1): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 * ALPN, server accepted to use http/1.1 * Server certificate: * subject: CN=*********; O=********** * start date: Jan 17 06:47:23 2024 GMT * expire date: Jan 16 06:47:23 2025 GMT * issuer: CN=**********; O=********** * SSL certificate verify result: self signed certificate (18), continuing anyway. > GET /version HTTP/1.1 > Host: ********** > User-Agent: curl/7.64.1 > Accept: */* > < HTTP/1.1 200 OK < date: Wed, 17 Jan 2024 08:16:27 GMT < content-length: 46 < content-type: text/plain; charset=utf-8 < req-cost-time: 5 < req-arrive-time: 1705479387567 < resp-start-time: 1705479387573 < x-envoy-upstream-service-time: 4 < server: istio-envoy < version: v1 hostname: httpbin-xxxxxx