运用 K8s Istio Cert-manager 和 Vault 保障应用的 Tls 安全
Vault 是安全应用维护人员最喜欢的 hashcorp 产品之一 。Vault 是存储机密、证书、管理策略、加密数据等内容的安全工具。Vault 使用受信任的身份集中密码和控制访问权限,以此减少对静态、硬编码凭证的需求。它使用集中托管和受保护的加密密钥来动态和静态加密敏感数据,所有一切均可通过单个工作流和 API 实现。 Istio 非常重要的一个功能是能够锁定并且保护网格内的来往流量。本文的目的是基于 TLS 启动一个简单的 Web 应用程序,然后使用 Vault 生成对应的安全证书,从而保证 Istio 管理的服务安全。 下载 kind 后,我们可以定义一个 kind 配置文件来启动 4 个 worker。我们还可以配置一些端口映射,以确保我们可以直接访问入口网关。 kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane extraPortMappings: - containerPort: 30725 hostPort: 8080 listenAddress: "127.0.0.1" protocol: TCP - containerPort: 32652 hostPort: 8443 listenAddress: "127.0.0.1" protocol: TCP - role: worker - role: worker - role: worker - role: worker 使用 kind 来创建我们的集群 kind create cluster --name chris --config ~/kube.cfg 节点已启动 kubectl get nodes NAME STATUS ROLES AGE VERSION chris-control-plane Ready control-plane 21h v1.24.0 chris-worker Ready <none> 21h v1.24.0 chris-worker2 Ready <none> 21h v1.24.0 chris-worker3 Ready <none> 21h v1.24.0 chris-worker4 Ready <none> 21h v1.24.0 使用istioctl (https://github.com/istio/istio/releases) 命令安装 istio 。首先让我们定义一下配置内容。因为我们在本地运行,所以我们降低了一些资源要求。 --- apiVersion: install.istio.io/v1alpha1 kind: IstioOperator metadata: namespace: istio-system name: installed-state spec: components: ingressGateways: - enabled: name: istio-ingressgateway namespace: istio-system pilot: k8s: hpaSpec: maxReplicas: 2 minReplicas: 1 resources: requests: cpu: 512m memory: 512Mi profile: default values: global: istioNamespace: istio-system 安装 istio istioctl manifest install -f ~/istio.cfg 删除默认类型的 istio-ingressgateway 的 service。 kubectl delete svc istio-ingressgateway -n istio-system 创建一个 NodePort 服务,从而实现从节点端口访问 istio-ingressgateway 。 apiVersion: v1 kind: Service metadata: labels: app: istio-ingressgateway istio: ingressgateway name: istio-ingressgateway namespace: istio-system spec: type: NodePort ports: - name: http nodePort: 30725 port: 8080 protocol: TCP targetPort: 8080 - name: https nodePort: 32652 port: 443 protocol: TCP targetPort: 8443 selector: app: istio-ingressgateway 应用一下 kubectl apply -f svc.yml 此时,istio 应该正常运行。 kubectl get pods -n istio-system NAME READY STATUS RESTARTS AGE istio-ingressgateway-5f86977657-qfxrs 1/1 Running 0 21h istiod-67db665bd9-4d8nl 1/1 Running 0 21h 我们将创建一个虚拟网关进行测试 apiVersion: networking.istio.io/v1alpha3 kind: Gateway metadata: name: gateway namespace: istio-system spec: selector: app: istio-ingressgateway servers: - port: number: 8080 name: http protocol: HTTP hosts: - "*" 同时应用 kubectl apply -f gateway.yml 使用 curl,我们能够从我们客户端去访问 istio 入口。注意:404 是预期的结果,因为我们还没有配置任何应用程序或 istio 虚拟服务。 curl localhost:8080 -vs * Trying 127.0.0.1... * TCP_NODELAY set * Connected to localhost (127.0.0.1) port 8080 (#0) > GET / HTTP/1.1 > Host: localhost:8080 > User-Agent: curl/7.64.1 > Accept: */* > < HTTP/1.1 404 Not Found < date: Thu, 28 Jul 2022 21:44:50 GMT < server: istio-envoy < content-length: 0 < * Connection #0 to host localhost left intact * Closing connection 0 我们不仅连接了(即使我们得到了 404 ),而且您可以看到服务器是 istio-envoy 响应,这意味着 envoy 正在处理流量。 (编辑:银川站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |