文档首页/ 企业主机安全 HSS/ API参考/ API说明/ 集群管理/ 查询集群组件防护策略模板 - ShowClusterProtectPolicyTemplate
更新时间:2025-10-31 GMT+08:00
分享

查询集群组件防护策略模板 - ShowClusterProtectPolicyTemplate

功能介绍

查询集群防护策略模板

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项
  • 如果使用身份策略授权,当前API调用无需身份策略权限。

URI

GET /v5/{project_id}/container/clusters/protection-policy-templates/{policy_template_id}

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:

项目ID,用于明确项目归属,配置后可通过该ID查询项目下资产。获取方式请参见获取项目ID

约束限制:

不涉及

取值范围:

字符长度1-256位

默认取值:

不涉及

policy_template_id

String

策略模板ID

表2 Query参数

参数

是否必选

参数类型

描述

enterprise_project_id

String

主机所属的企业项目ID。

开通企业项目功能后才需要配置企业项目。

企业项目ID默认取值为“0”,表示默认企业项目。如果需要查询所有企业项目下的主机,请传参“all_granted_eps”。如果您只有某个企业项目的权限,则需要传递该企业项目ID,查询该企业项目下的主机,否则会因权限不足而报错。

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:

用户Token,包含了用户的身份、权限等信息,在调用API接口时,可通过Token进行身份认证。获取方式请参见获取用户Token

约束限制:

不涉及

取值范围:

字符长度1-32768位

默认取值:

不涉及

响应参数

状态码:200

表4 响应Body参数

参数

参数类型

描述

id

String

模板ID

template_name

String

模板名称

template_type

String

模板类型

description

String

描述

target_kind

String

策略模板应用资源类型,多个资源类型通过分号份隔连接

tag

String

标签

level

String

推荐级别

constraint_template

String

策略模板内容

请求示例

响应示例

状态码:200

请求已成功

{
  "id" : "string",
  "template_name" : "string",
  "template_type" : "string",
  "description" : "string",
  "target_kind" : "Deployment;ReplicaSet;CornJob",
  "tag" : "string",
  "level" : "strin",
  "constraint_template" : {
    "kind" : "ConstraintTemplate",
    "apiVersion" : "templates.gatekeeper.sh/v1",
    "metadata" : {
      "name" : "k8spspprocmount",
      "creationTimestamp" : null,
      "annotations" : {
        "description" : "Controls the allowed `procMount` types for the container. Corresponds to the `allowedProcMountTypes` field in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#allowedprocmounttypes",
        "description-chinese" : "限制Pod允许挂载的Proc类型",
        "level" : "3",
        "metadata.gatekeeper.sh/title" : "Proc Mount",
        "metadata.gatekeeper.sh/version" : "1.0.0",
        "name-chinese" : "K8sPSPProcMount",
        "tag" : "Container/ApplicationSecurityPolicies",
        "tag-chinese" : "容器/应用安全策略",
        "targetKind" : "Pod",
        "type" : "security"
      }
    },
    "spec" : {
      "crd" : {
        "spec" : {
          "names" : {
            "kind" : "K8sPSPProcMount"
          },
          "validation" : {
            "openAPIV3Schema" : {
              "description" : "Controls the allowed `procMount` types for the container. Corresponds to the `allowedProcMountTypes` field in a PodSecurityPolicy. For more information, see https://kubernetes.io/docs/concepts/policy/pod-security-policy/#allowedprocmounttypes",
              "type" : "object",
              "properties" : {
                "exemptImages" : {
                  "description" : "Any container that uses an image that matches an entry in this list will be excluded from enforcement. Prefix-matching can be signified with `*`. For example: `my-image-*`.\nIt is recommended that users use the fully-qualified Docker image name (e.g. start with a domain name) in order to avoid unexpectedly exempting images from an untrusted repository.",
                  "type" : "array",
                  "items" : {
                    "type" : "string"
                  }
                },
                "procMount" : {
                  "description" : "Defines the strategy for the security exposure of certain paths in `/proc` by the container runtime. Setting to `Default` uses the runtime defaults, where `Unmasked` bypasses the default behavior.",
                  "type" : "string",
                  "enum" : [ "Default", "Unmasked" ]
                }
              }
            }
          }
        }
      },
      "targets" : [ {
        "target" : "admission.k8s.gatekeeper.sh",
        "rego" : "package k8spspprocmount\nimport data.lib.exempt_container.is_exempt\nviolation[{\"msg\": msg, \"details\": {}}] {\n    c := input_containers[_]\n    not is_exempt(c)\n    allowedProcMount := get_allowed_proc_mount(input)\n    not input_proc_mount_type_allowed(allowedProcMount, c)\n    msg := sprintf(\"ProcMount type is not allowed, container: %v. Allowed procMount types: %v\", [c.name, allowedProcMount])\n}\ninput_proc_mount_type_allowed(allowedProcMount, c) {\n    allowedProcMount == \"default\"\n    lower(c.securityContext.procMount) == \"default\"\n}\ninput_proc_mount_type_allowed(allowedProcMount, c) {\n    allowedProcMount == \"unmasked\"\n}\ninput_containers[c] {\n    c := input.review.object.spec.containers[_]\n    c.securityContext.procMount\n}\ninput_containers[c] {\n    c := input.review.object.spec.initContainers[_]\n    c.securityContext.procMount\n}\ninput_containers[c] {\n    c := input.review.object.spec.ephemeralContainers[_]\n    c.securityContext.procMount\n}\nget_allowed_proc_mount(arg) = out {\n    not arg.parameters\n    out = \"default\"\n}\nget_allowed_proc_mount(arg) = out {\n    not arg.parameters.procMount\n    out = \"default\"\n}\nget_allowed_proc_mount(arg) = out {\n    not valid_proc_mount(arg.parameters.procMount)\n    out = \"default\"\n}\nget_allowed_proc_mount(arg) = out {\n    out = lower(arg.parameters.procMount)\n}\nvalid_proc_mount(str) {\n    lower(str) == \"default\"\n}\nvalid_proc_mount(str) {\n    lower(str) == \"unmasked\"\n}",
        "libs" : [ "package lib.exempt_container\nis_exempt(container) {\n    exempt_images := object.get(object.get(input, \"parameters\", {}), \"exemptImages\", [])\n    img := container.image\n    exemption := exempt_images[_]\n    _matches_exemption(img, exemption)\n}\n_matches_exemption(img, exemption) {\n    not endswith(exemption, \"*\")\n    exemption == img\n}\n_matches_exemption(img, exemption) {\n    endswith(exemption, \"*\")\n    prefix := trim_suffix(exemption, \"*\")\n    startswith(img, prefix)\n}" ]
      } ]
    },
    "status" : { }
  }
}

状态码

状态码

描述

200

请求已成功

错误码

请参见错误码

相关文档