当前位置: 首页 > news >正文

k8s Understanding Kubernetes Security Components

Understanding Kubernetes Security Components

In Kubernetes, security is implemented through several components that work together to control access and permissions. Let's explore ServiceAccounts, Roles, RoleBindings, and SecurityContexts.

ServiceAccount

A ServiceAccount provides an identity for processes running in a Pod. It's used for authentication when Pods interact with the Kubernetes API.

Key points:

  • Every namespace has a default ServiceAccount
  • Pods automatically mount the default ServiceAccount unless specified otherwise
  • ServiceAccounts can be associated with secrets for API authentication

Role

A Role defines a set of permissions within a specific namespace. It specifies what actions (verbs) can be performed on which resources.

Key points:

  • Namespace-scoped
  • Defines permissions using rules (resources and verbs)
  • For cluster-wide permissions, use ClusterRole instead

RoleBinding

A RoleBinding grants the permissions defined in a Role to a user, group, or ServiceAccount.

Key points:

  • Links subjects (users, groups, ServiceAccounts) to a Role
  • Namespace-scoped
  • For cluster-wide bindings, use ClusterRoleBinding

SecurityContext

A SecurityContext defines privilege and access control settings for Pods or containers.

Key points:

  • Can be set at Pod or container level
  • Controls running as specific user/group IDs
  • Manages Linux capabilities
  • Enforces security policies like preventing privilege escalation

Example: Creating a Pod with Limited Permissions

Let's create a scenario where we want to run a monitoring Pod that can only read ConfigMaps in its namespace:

1. Create a ServiceAccount

apiVersion: v1
kind: ServiceAccount
metadata:name: monitoring-accountnamespace: monitoring

2. Create a Role with limited permissions

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:name: configmap-readernamespace: monitoring
rules:
- apiGroups: [""]resources: ["configmaps"]verbs: ["get", "list", "watch"]

3. Bind the Role to the ServiceAccount

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:name: monitoring-configmap-readernamespace: monitoring
subjects:
- kind: ServiceAccountname: monitoring-accountnamespace: monitoring
roleRef:kind: Rolename: configmap-readerapiGroup: rbac.authorization.k8s.io

4. Create a Pod using the ServiceAccount and SecurityContext

apiVersion: v1
kind: Pod
metadata:name: secure-monitoring-podnamespace: monitoring
spec:serviceAccountName: monitoring-accountsecurityContext:runAsUser: 1000runAsGroup: 3000fsGroup: 2000containers:- name: monitoring-containerimage: monitoring-image:latestsecurityContext:allowPrivilegeEscalation: falsereadOnlyRootFilesystem: truecapabilities:drop:- ALLresources:limits:memory: "128Mi"cpu: "500m"
http://www.jsqmd.com/news/1430/

相关文章:

  • 如何用 Dify 无代码工作流实现 AI 自动化抓取与分析 LinkedIn 招聘数据
  • 2025/9/22
  • WSL+共享文件夹搭建zephyr工作环境
  • 如果 Spring Cloud Feign 配置了 OkHttp3 非阻塞 IO(NIO),那么还需要reactor 模型来提高性能吗
  • 数据结构-单链表基础2
  • LLM的MCP协议通讯方式详解:Stdio、SSE与流式HTTP的选择与实践 - 详解
  • G1垃圾回收过程
  • Trellix自动化大规模修复开源漏洞,已修补超6万个项目
  • AI 编程工具选型速览(2025-09 版) - 详解
  • 爆款游戏背后:尚娱如何借助阿里云 Kafka Serverless 轻松驾驭“潮汐流量”?
  • Vben Admin5.0 keepAlive缓存和onActivated未生效
  • yakit + proxifier 解决`all tls strategy failed报错
  • 版本速递 | 华为云Versatile智能体平台 新增特性介绍(2025年9月发布)
  • 详细介绍:传输层TCP 与 安全层SSL/TLS
  • PE程序常见脱壳方案
  • spring ai基于内存RAG尝鲜
  • 基于 IOCP 的协程调度器——零基础深入浅出 C++20 协程
  • Gitee PPM风险矩阵:数字化转型中的项目管理预警雷达
  • 同一个灰色,POI取出来却是白色:一次Excel颜色解析的踩坑记录
  • 坤驰科技携国产化MTCA解决方案,亮相大科学装置控制系统研讨会
  • 找出所有项目引用了哪些 NuGet 包、版本号、对应项目路径,并筛选出“同一个包名但版本不同”的情况。
  • 人形机器人 —— 电机控制的三种模式 —— 力矩、速度、位置
  • 解决Windows更新后WPF代码报TypeLoadException异常的困难
  • PC与基恩士PLC通信的C#实现
  • Excel 表格技能
  • labelme标注后的json文件和原图同步按角度旋转
  • rk3588的ai功能和deepseek
  • EPSON L1300打印机清零教程
  • 「线性代数」矩阵运算与初等变换
  • 移动号码线上复机