Kubernetes Policy YAML Code Syntax Guide
This document is written based on QueryPie Enterprise 9.20.0.
QueryPie Access Control Policy Overview
Access control policies defined in QueryPie operate based on EABAC (Enhanced Attribute Based Access Control). EABAC is a policy control method that can control access to resources registered in QueryPie and perform permission management based on the roles and attributes of QueryPie users. It provides more flexible and sophisticated access control by combining the functions of RBAC (Role-Based Access Control) and ABAC (Attribute-Based Access Control). All policies operate on the premise of All Deny.
EABAC operates in two ways: Role and Policy. Role settings are done through GUI, and Policy definitions are managed through code (YAML).
For Kubernetes policies, the specification was created as a comprehensive model that can accommodate both Role limited to namespaces that actually exist in Kubernetes and ClusterRole that supports resources outside the namespace scope.
Kubernetes Policy YAML Basic Structure
Wildcard (”*”) and regular expression (RE2 format : ^$ explicit required) patterns are supported in general policy code except for some items.
Category  | Property  | Required  | Description  | Valid Values  | 
|---|---|---|---|---|
  | O  | This is the version of the written YAML Code. It is a value managed by the system and does not need to be modified.  | 
  | |
  | O  | This is the type of the written YAML Code. It is a value managed by the system and does not need to be modified.  | 
  | |
  | O  | Specifies whether to allow or deny specific rules of the policy. 
  | 
  | |
  | O  | Specifies resources to allow/deny access. [Wildcard and regular expressions allowed]  | 
  | |
  | O  | Specifies Kubernetes users/groups to impersonate Kubernetes commands. 
  | 
  | |
  | O  | Specifies the Resource API list to allow/deny within the Kubernetes cluster API server. [Wildcard and regular expressions allowed] 
  | 
  | |
  | Controls the target in detail by applying conditions for whether to apply resource access policies. 
  | 
  | 
Resources Specification Method
resources defines resources for Kubernetes clusters registered in QueryPie, not Kubernetes resources.
- Definition for the 
resourcesfield is required. [required] - Enter based on the Kubernetes cluster name.
"cluster:{Kubernetes Cluster Name in QueryPie}"
 - Kubernetes cluster names are established based on the following criteria.
- Character length limit of 100 characters
 - Only alphabetic case-sensitive, numbers and the following special symbols are allowed
- underscore (_)
 - hyphen (-)
 
 - Names must start and end with alphabetic case-sensitive or numbers
 - Cluster names are limited to prevent duplication
 
 - Multiple Kubernetes clusters can be specified in a single policy.
- "cluster:kubepie-dev-1"- "cluster:kubepie-dev-2"["cluster:kubepie-dev-1", "cluster:kubepie-dev-2"]
 - Paths allow wildcards.
"cluster:kubepie-dev-*"
 - Paths allow regular expressions.
"cluster:^kubepie-dev-.*$"
 
Subjects Specification Method
subjects defines users/groups within Kubernetes to impersonate Kubernetes commands. subjects is a field that needs to be applied only in spec:allow, and is not syntactically allowed in spec:deny.
kubernetesGroups: [required]- Defines the kubernetes group account that QueryPie Proxy will impersonate to perform APIs on resources.
- These subjects must be definable at the Policy-wide level and must be defined to assign at least one.
- These subjects for Impersonation can be nested with other Policies within one Role.
 
 - Defines kubernetes-side groups (single or multiple) that can perform permissions on resources specified in Resources.
 - In kubernetesGroups, Querypie User’s Group can be entered in reserved word format. In this case, User’s Group must be entered without double quotes (”) and when users view the Policy, the actual user Group value is displayed.
 
 - These subjects must be definable at the Policy-wide level and must be defined to assign at least one.
 
- Defines the kubernetes group account that QueryPie Proxy will impersonate to perform APIs on resources.
 impersonation: [OPTIONAL]- When users attempt impersonation (—as, —as-group) in kubectl commands with permissions of specific serviceaccounts, etc. within kubernetes from the client side, defines the call allowance list for this.
users: Lists values allowed in the “—as” parameter with users/service accounts existing within Kubernetes.groups: Lists values allowed in the “—as-group” parameter with group accounts existing within Kubernetes.- Wildcards are allowed. (
"*") 
 
- When users attempt impersonation (—as, —as-group) in kubectl commands with permissions of specific serviceaccounts, etc. within kubernetes from the client side, defines the call allowance list for this.
 
Actions Specification Method
Specifies the Resource API list to allow within the cluster API server. Each action requires apiGroups, resources, namespace, name, verbs entries.
apiGroups: Defines the Kubernetes API group list.- By defining API groups, more detailed permission control is possible for each API group.
 - When control over custom resources is needed, it can be specified in apiGroups to control only custom resources.
 - Reference:
 - Wildcards are allowed to comprehensively specify all API groups.
apiGroups: ["*"]
 
resources: Defines the Kubernetes resource list.- Commonly used resources are as follows:
pods,pods/exec,pods/log,pods/portforward,services,ingresses,deployments,replicasets,statefulsets,daemonsets,configmaps,secrets,namespaces,nodes,persistentvolumes,persistentvolumeclaims,jobs,cronjobs,serviceaccounts,endpoints,roles,rolebindings,clusterroles,clusterrolebindings
 - Resources not listed above are also acceptable in policies.
 - Even if you grant permissions only to namespace sub-resources, ReadOnly permissions for Namespace are also granted. Therefore, cases where you need to specify the namespace every time when calling resources do not occur. If you want to prevent granting permissions to specific namespaces, you can set access denial for namespace resources in 
spec:deny. - Multiple resources can be specified in a single policy action.
 - Wildcards are allowed. (
"*") 
- Commonly used resources are as follows:
 namespace: Defines the target namespace.- By defining namespaces in actions, you can control allowed namespaces within the cluster for each resource.
 - Both wildcards and regular expressions are allowed.
namespace: "*"
 - For resources that do not exist in namespaces other than namespaces, you do not need to write the namespace.
- Target examples) 
persistentvolumes,persistentvolumeclaims,serviceaccounts,customresourcedefinitions,endpoints,nodes,clusterroles,clusterrolebindings, etc. 
 - Target examples) 
 
name: By defining target resource names, you can control based on naming among allowed resources within the cluster.- Both wildcards and regular expressions are allowed.
name: "pods-*"
 
- Both wildcards and regular expressions are allowed.
 verbs: Specifies API permissions within Kubernetes to allow or deny operations.- Commonly called verbs are as follows:
get: Resource information retrievallist: Resource list enumerationwatch: Resource change monitoringcreate: New resource creationupdate: Existing resource updatepatch: Resource partial modificationdelete: Resource deletiondeletecollection: Multiple resource deletion in a single operation
 - Even if there are special verbs not listed above, they can be specified and applied in policies.
 - When supporting 3rd-Party clients, the following verbs are required and guided:
- View permissions : 
get,list,watch - Edit permissions : 
get,list,watch+create,update,patch,delete,deletecollection 
 - View permissions : 
 - Generally, 
createverb specification is required for container shell access session creation through pod exec commands. - Wildcards are allowed.
verbs: ["*"]
 
- Commonly called verbs are as follows:
 
Conditions Specification Method
conditions items can define resourceTags, userAttributes, ipAddresses as conditions. [OPTIONAL]
resourceTags: In tag items, you can filter by resource tag keys and values.userAttributes: Specifies user attributes as conditions and restricts the use of permissions defined in the policy only to users whose values match.ipAddresses: Defines IP access control condition lists for resources in single IP, CIDR format.
KAC Policy Example
apiVersion: kubernetes.rbac.querypie.com/v1 
kind: KacPolicy
spec:
  allow: 
    resources: 
      - "cluster:*"
    subjects: 
      kubernetesGroups: 
        - "system:masters"
      impersonation: 
        users: ["system:serviceaccount:argocd"] 
        groups: ["system:admin"]  
    actions: 
      - apiGroups: ["*"] 
        resources: 
          - "pods"
        namespace: "*" 
        name: "*" 
        verbs: ["get", "list", "watch"]
    conditions: 
      resourceTags: 
        "Owner": ["Kenny", "Brant"]
        "Team": "DevSecOps" 
      userAttributes: 
        "countryCode": "KR"
        "department": "Infra"
      ipAddresses: ["10.10.0.0/24", "10.11.10.1"] 
  deny: 
    resources: 
      - "cluster:kubepie-*"
    actions: 
      - apiGroups: ["*"]
        resources: 
          - "*"
        namespace: "production"
        name: "*"
        verbs: ["*"]
    conditions: 
      resourceTags: 
        "Owner": "Brant"