博客
关于我
Istio安全-认证(实操二)
阅读量:421 次
发布时间:2019-03-06

本文共 2348 字,大约阅读时间需要 7 分钟。

Istio安全认证指南

安全认证策略

配置概述

本节将介绍如何启用、配置和使用Istio的安全认证策略,深入了解其底层概念。首先,我们需要理解Istio的核心组件及其安全机制,然后通过示例配置来实现需求。

安全认证类型

Istio 提供了两种主要的安全认证类型:

  • 对等认证(Mutual TLS):基于TLS证书的双向认证,适用于服务间通信。
  • 终端用户认证(JWT认证):基于JSON Web Token的认证,适用于用户身份验证。
  • 配置步骤

    1. 安装Istio

    首先,确保Istio已正确安装并配置。以下命令创建命名空间和部署示例:

    kubectl create ns fookubectl apply -f $(istioctl kube-inject -f samples/httpbin/httpbin.yaml) -n fookubectl apply -f $(istioctl kube-inject -f samples/sleep/sleep.yaml) -n foo

    2. 启用对等认证

    默认情况下,Istio会自动配置客户端代理发送mutual TLS流量到目标负载。为了确保所有通信使用加密传输,需在网格范围内设置严格的对等认证策略:

    kubectl apply -n istio-system -f - <

    3. 验证配置

    通过执行以下命令验证配置是否正确:

    for from in "foo" "bar" "legacy"; do  for to in "foo" "bar" "legacy"; do    kubectl exec $(kubectl get pod -l app=sleep -n ${from} -o jsonpath={.items..metadata.name}) -c sleep -n ${from} \      -- curl "http://httpbin.${to}:8000/ip" -s -o /dev/null -w "sleep.${from} to httpbin.${to}: %{http_code}\n"  donedone

    4. 卸载配置

    若需卸载对等认证策略,可执行以下命令:

    kubectl delete peerauthentication -n istio-system default

    终端用户认证

    配置JWT认证

    为了实现终端用户认证,需配置JWT策略并暴露服务。以下步骤说明:

  • 部署Ingress Gateway:
  • kubectl apply -n istio-system -f samples/addons/ingressgateway/ingressgateway.yaml
    1. 获取Ingress信息:
    2. INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')INGRESS_HOST=$(kubectl get po -l istio=ingressgateway -n istio-system -o jsonpath='{.items[0].status.hostIP}')
      1. 应用JWT认证策略:
      2. kubectl apply -n istio-system -f - <

        验证JWT认证

      3. 使用有效token:
      4. TOKEN=$(curl https://raw.githubusercontent.com/istio/istio/release-1.7/security/tools/jwt/samples/demo.jwt -s)curl --header "Authorization: Bearer $TOKEN" "$INGRESS_HOST:$INGRESS_PORT/headers" -s -o /dev/null -w "%{http_code}\n" 200
        1. 使用无效token:
        2. curl --header "Authorization: Bearer deadbeef" "$INGRESS_HOST:$INGRESS_PORT/headers" -s -o /dev/null -w "%{http_code}\n" 401

          验证路径授权

          为确保每个路径都需要有效token,可以修改策略:

          kubectl apply -n istio-system -f - <

          验证结果:

          curl "$INGRESS_HOST:$INGRESS_PORT/headers" -s -o /dev/null -w "%{http_code}\n" 403curl "$INGRESS_HOST:$INGRESS_PORT/ip" -s -o /dev/null -w "%{http_code}\n" 200

          卸载步骤

          移除JWT策略

          kubectl -n istio-system delete requestauthentication jwt-examplekubectl -n istio-system delete authorizationpolicy frontend-ingress

          移除命名空间

          kubectl delete ns foo bar legacy

          总结

          本章详细介绍了Istio的安全认证机制,包括对等认证和终端用户认证。通过合理配置,可以实现服务间的安全通信和用户身份验证。Istio的灵活配置使其适用于多种场景,确保系统安全性和可靠性。

    转载地址:http://ulakz.baihongyu.com/

    你可能感兴趣的文章
    NMAP网络扫描工具的安装与使用
    查看>>
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>
    NO.23 ZenTaoPHP目录结构
    查看>>
    NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
    查看>>
    Node JS: < 一> 初识Node JS
    查看>>
    Node-RED中使用JSON数据建立web网站
    查看>>
    Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
    查看>>
    Node-RED中实现HTML表单提交和获取提交的内容
    查看>>
    Node.js 实现类似于.php,.jsp的服务器页面技术,自动路由
    查看>>