Lesson 6 Security and Authentication
Lesson 6 Security and Authentication
Lesson 6 Security and Authentication
Kubernetes: Security
Learning Objectives
kube-apiserver [flags]
Secure Kube-API Server
--audit-log-batch-buffer-size int Default: 10000 The size of the buffer to store events before batching
and writing; it is only used in a batch mode
--audit-log-batch-max-size int Default: 1 It is the maximum size of a batch that is only used in a
batch mode
Authentication
User and Password-Based Authentication
TLS certificates need to be distributed for the node components and are to be
signed with the master Certificate Authority (CA). This is to achieve private and
secure connection between node components and master components.
Securing the Kubernetes Cluster
--enable-bootstrap-token-auth
--controllers=*,tokencleaner
Kubeconfig
Kubeconfig File Requirements
For example:
• A running kubelet might authenticate using certificates
• A user might authenticate using tokens
• Administrators may have several certificate sets that
they use to provide individual users
Kubeconfig File Requirements
Kubernetes uses etcd for persistent storage of all of its REST API objects. Kubernetes objects are
stored under the /registry key in etcd.
Here are a few best practices for persistent storage key value pair in etcd:
The main aim of an API group is to extend the Kubernetes API specified in a REST path and the
apiVersion field of a serialized object.
• The core group is also called legacy group. It uses apiVersion: V1 and is at REST path
/api/v1.
Consists of the subject, i.e., a user, group, or account and the reference to which the role will be
granted
Used to grant permissions within a namespace and not cluster-wide; ClusterRoleBinding is used
for granting permissions cluster-wide
RBAC Role Creation
Problem Statement: You are given a project to demonstrate the workflow of creating an RBAC
role.
Associate the User with the Role
Problem Statement: You are given a project to demonstrate the association of a user with the
role.
Cluster Roles and Role Bindings
Cluster Role
AlikeRole and ClusterRole can also be used to grant permission. They can grant permissions
for:
• Non-resource endpoints
• Clustered scooped resources like nodes
• Namespace resources
It is also used to grant read access to secrets across all namespaces or a particular namespace (if
necessary).
ClusterRoleBinding
Used to bind a role to user, groups, and service accounts. These are also called subjects
• system:authenticated group
• system:unauthenticated group
ClusterRoleBinding
Let us see an example of ClusterRoleBinding that allows users to read secrets in any namespace:
Example:
apiVersion: rbac.authorization.k8s.io/v1
# This cluster role binding allows anyone in the group
“SampleGroup” to read secrets in any namespace.
kind: ClusterRoleBinding
metadata:
name: read-secrets-global
subjects:
- kind: Group
name: SampleGroup
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: secret-reader
apiGroup: rbac.authorization.k8s.io
Cluster Role Creation
Problem Statement: You are given a project to demonstrate the creation of a cluster role.
Associate the User with Cluster Role
Problem Statement: You are given a project to demonstrate the association of a user with
cluster role.
Image Security
Registry Requirements
Docker images are pushed to registry before referring it in a pod. Private registries require keys
to read those images.
Problem Statement: You are given a project to demonstrate the use of the secrets with private
registry information stored.
Network Policy
Ingress and Egress Traffic
Default network policy type in which the NetworkPolicy includes a list of ingress rules
Each ingress rule is used to allow traffic that matched the from and port section
In this, the NetworkPolicy includes a list of egress rules. Each egress rule is used to allow traffic
that matched the to and port section
Ingress and Egress Traffic
Here are the four selectors that can be specified in ingress from and egress to section:
podSelector namespaceSelctor
Problem Statement: You are given a project to modify the pod settings to associate with the
network policy.
Key Takeaways
a. Role
b. RoleBinding
c. Cluster Role
d. ClusterBinding
Knowledge
Check
_____________ is used to grant permissions at the cluster level.
1
a. Role
b. RoleBinding
c. Cluster Role
d. ClusterBinding
a. Ingress rule
b. Egress rule
c. podSelector
d. namespaceSelector
Knowledge
Check Which of the following rules is used to allow traffic that matches the from and
port section?
2
a. Ingress rule
b. Egress rule
c. podSelector
d. namespaceSelector
Ingress rule is used to allow traffic that matches the from and port section.
Knowledge
Check Which of the following registries uses the kubelet version v1.3.0 or latest if the nodes
3 and the registry are in different regions?
AWS EC2 Container Registry (ECR) uses the kubelet version v1.3.0 or latest if the nodes and the registry are
in different regions.
Knowledge
Check
Which of the following is a requirement of AWS EC2 Container Registry (ECR)?
4
b. Use of kubelet version v1.3.0 or latest if the nodes and the registry are in different regions
b. Use of kubelet version v1.3.0 or latest if the nodes and the registry are in different regions
Use of kubelet version v1.2.0 or latest, use of kubelet version v1.3.0 or latest if the nodes and the registry
are in different regions, and offering of ECR in your region are the requirements of AWS ECR.
Knowledge
Check Which of the following kube-apiserver flags specifies the maximum size of a batch and
can be used only in a batch mode?
5
a. --admission-control-config-file string
b. --audit-dynamic-configuration
a. --admission-control-config-file string
b. --audit-dynamic-configuration
--audit-log-batch-max-size int Default: 1 specifies the maximum size of a batch and can be sued only in a
batch mode.
Problem Statement: Corporate banks have a lot of sensitive information
pertaining to millions of people. With online banking, one can get rid of many
challenges of traditional banking. But, how can you ensure that data transfer
and visibility are only limited to authorized users?