Kubernetes Policy YAML Code Syntax Instructions
This document is based on QueryPie Enterprise version 10.0.0.
QueryPie Access Control Policy Overview
Access control policies defined in QueryPie operate based on Enhanced Attribute Based Access Control (EABAC). EABAC governs access to resources registered in QueryPie based on the roles and attributes of QueryPie users, enabling comprehensive management of permissions. It combines the functionalities of Role-Based Access Control (RBAC) and Attribute-Based Access Control (ABAC) to provide flexible and sophisticated access control. All policies operate under the principle of All Deny.
EABAC functions through two components: Roles are configured via GUI, while Policies are defined and managed using YAML code.
For Kubernetes policies, a comprehensive model has been developed to accommodate both Role-based restrictions confined to namespaces existing in Kubernetes and ClusterRole supporting resources beyond namespace scopes.
Kubernetes Policy YAML Basic Structure
The overall policy code structure supports wildcard ("*") and regular expression (RE2 format: ^$
must be specified) patterns in most policy items, with some exceptions.
Category | Property | Required | Description | Valid Values |
---|---|---|---|---|
| - | O | Version of the written YAML code. This value is managed by the system and does not need modification. |
|
| - | O | Type of the written YAML code. This value is managed by the system and does not need modification. |
|
| - | O | Specifies whether to allow or deny specific rules in the policy.
|
|
|
| O | Specifies the resources to allow/deny access to. ALLOW WILDCARD & REGEX |
|
|
| O | Specifies the Kubernetes user/group to impersonate Kubernetes commands.
|
|
|
| O | Specifies the Resource API to allow/deny within the Kubernetes cluster API server. ALLOW WILDCARD & REGEX
|
|
|
| Applies detailed controls based on conditions such as the application of resource access policies.
|
|
Resources Specification
The resources
field defines Kubernetes clusters registered in QueryPie, not Kubernetes resources themselves.
Defining
resources
field is mandatory. REQUIREDIt should be based on the Kubernetes cluster name.
Format:
"cluster:{Kubernetes Cluster Name in QueryPie}"
Kubernetes cluster names are structured as follows:
Maximum 100 characters in length
Alphanumeric characters (case-sensitive), numbers, and the following special characters are allowed:
underscore (_)
hyphen (-)
Names must start and end with alphanumeric characters or numbers
Cluster names must be unique
Multiple Kubernetes clusters can be specified within a single policy.
- "cluster:kubepie-dev-1"
- "cluster:kubepie-dev-2"
["cluster:kubepie-dev-1", "cluster:kubepie-dev-2"]
It allows writing in wildcard.
"cluster:kubepie-dev-*"
It allows writing in regular expression.
"cluster:^kubepie-dev-.*$"
Subjects Specification
subjects
defines Kubernetes users/groups for impersonation within Kubernetes commands. It is applicable only to spec:allow
and is not syntactically allowed in spec:deny
.
kubernetesGroups
: REQUIREDDefines Kubernetes group accounts that QueryPie Proxy will impersonate to perform API actions on resources.
These subjects must be defined at the Policy-wide level, with at least one assignment required.
Impersonation using these subjects can be nested within a single Role across different Policies.
Specify Kubernetes groups (single or multiple) authorized to perform actions on resources specified under
Resources
.CODEkubernetesGroups: - system:masters - default-group-account
impersonation
: OPTIONALSpecifies the allowed users or groups for impersonation in Kubernetes commands like
kubectl
with--as
and--as-group
parameters at the client-side.users
: Lists Kubernetes users or service accounts existing within the cluster for whom impersonation via "--as" parameter is permitted.groups
: Lists Kubernetes groups existing within the cluster for whom impersonation via "--as-group" parameter is permitted.CODEimpersonation: users: - "system:serviceaccount:argocd" groups: - "system:admin"
Wildcard is permitted (
"*"
)
Actions Specification
Specifies the Resource API list to allow or deny within the Kubernetes cluster API server. Each action requires entries for apiGroups
, resources
, namespace
, name
, verbs
. REQUIRED
apiGroups
: Defines the list of Kubernetes API groups.By defining API groups, finer-grained access control is possible per API group.
If control over custom resources is needed, specify them under
apiGroups
.References:
You can use a wildcard "*" to comprehensively specify entire API groups.
apiGroups: ["*"]
resources
: Defines the list of Kubernetes resources.Commonly used resources include:
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 can also be accommodated in policies.
When granting permissions only to namespace-specific resources, read-only access to the namespace is automatically included. Therefore, you do not need to specify the namespace every time you make resource API calls. If you wish to prevent granting permissions to specific namespaces, you can configure access denial for namespace resources in
spec:deny
.You can specify multiple resources within a single policy action:
CODEresources: - "pods" - "deployments" - "configmaps"
Wildcard is permitted. (
"*"
)
namespace
: Defines the target namespace.Specify namespaces in actions to control access to specified namespaces within the cluster.
Both wildcards and regular expressions are supported.
namespace: "*"
For resources that do not belong to specific namespaces, it is recommended to specify "*" to ensure that the namespace value does not affect them. This approach allows you to manage resources that are not tied to any particular namespace effectively.
e.g.,
persistentvolumes
,persistentvolumeclaims
,serviceaccounts
,customresourcedefinitions
,endpoints
,nodes
,clusterroles
,clusterrolebindings
등
name
: Defines the target resource name enabling control based on resource naming conventions within the cluster.Supports both wildcards and regular expressions.
name: "pods-*"
verbs
: Specifies Kubernetes API permissions to allow or deny operations.Commonly used verbs include:
get
: Retrieve resource informationlist
: List resourceswatch
: Monitor resource changescreate
: Create new resourcesupdate
: Update existing resourcespatch
: Modify resources partiallydelete
: Delete resourcesdeletecollection
: Delete multiple resources in a single operation
Specialized verbs not listed can also be specified and applied in policies.
When supporting 3rd-party clients, the following verbs are essential and should be provided:
View Permissions :
get
,list
,watch
Edit Permissions :
get
,list
,watch
+create
,update
,patch
,delete
,deletecollection
For creating sessions to access container shells via the
pod exec
command, specifying theget
,create
verb is typically necessary.Wildcard is permitted.
verbs: ["*"]
Conditions Specification
In the conditions
section, you can define conditions using resourceTags
, userAttributes
, and ipAddresses
. OPTIONAL
resourceTags
: Use resource tags to filter resources based on key-value pairs.CODEresourceTags: "region": "ap-northeast-1" "Owner": "Brant"
userAttributes
: Define user attributes to restrict policy permissions to users whose attributes match specified criteria.CODEuserAttributes: "countryCode": "KR" "department": "Infra"
ipAddresses
: Specify IP addresses or CIDR blocks to control access to resources based on source IP.CODEipAddresses: ["10.10.0.0/24", "10.11.10.1"]
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"