首页 文章 精选 留言 我的

精选列表

搜索[多租户SaaS],共10006篇文章
优秀的个人博客,低调大师

k8s RBAC 租户权限控制实现

访问到权限分两部分 1.Authenticating认证授权配置由kube-apiserver管理 这里使用的是 Static Password File方式。apiserver启动yaml里配置basic-auth-file即可,容器 启动apiserver的话要注意这个文件需要是在容器内能访问到的。(可以通过挂载文件,或者在已经挂载的路径里增加配置文件)basic-auth-file文件格式见官方文档https://kubernetes.io/docs/admin/authentication/#static-password-file注意password在第一个,之前没注意被卡了很久。修改了文件以后需要重启apiserver才能生效。这里kubectldelete删除pod有问题,使用docker命令查看apiserver容器其实没有重启。解决方案是使用dockerkill杀掉容器。自动重启。 [root@tensorflow1 ~]# curl -u admin:admin "https://localhost:6443/api/v1/pods" -k { "kind": "Status", "apiVersion": "v1", "metadata": { }, "status": "Failure", "message": "pods is forbidden: User \"system:anonymous\" cannot list pods at the cluster scope", "reason": "Forbidden", "details": { "kind": "pods" }, "code": 403 } 这个就是没有通过认证的报错 2.Authorization授权 k8sRBAC授权规则https://kubernetes.io/docs/admin/authorization/rbac/ 简单来说就是 权限--角色--用户绑定需要配置两个文件一个是role/clusterRole,定义角色以及其权限一个是roleBinding/clusterRoleBinding,定义用户和角色的关系 { "kind": "Status", "apiVersion": "v1", "metadata": { }, "status": "Failure", "message": "pods is forbidden: User \"admin\" cannot list pods at the cluster scope", "reason": "Forbidden", "details": { "kind": "pods" }, "code": 403 } 这个就是没有权限访问,需要配置RBAC 文件如下:方案1:role + roleBinding kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: namespace: user1 name: pod-reader rules: - apiGroups: [""] # "" indicates the core API group resources: ["pods"] verbs: ["*"] - apiGroups: [""] # "" indicates the core API group resources: ["namespaces"] verbs: ["*"] kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: user1-rolebinding namespace: user1 subjects: - kind: User name: user1 # Name is case sensitive apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: myauth-user apiGroup: rbac.authorization.k8s.io 方案2:clusterRole + roleBinding (推荐) clusterRole定义全局权限,roleBinding将权限限制到namespace。clusterRole仅需要定义一次。 kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: myauth-user rules: - apiGroups: [""] # "" indicates the core API group resources: ["pods"] verbs: ["*"] - apiGroups: [""] # "" indicates the core API group resources: ["namespaces"] verbs: ["*"] - apiGroups: [""] # "" indicates the core API group resources: ["resourcequotas"] verbs: ["*"] kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: user2-rolebinding namespace: user2 subjects: - kind: User name: user2 # Name is case sensitive apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: myauth-user apiGroup: rbac.authorization.k8s.io kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: user1-rolebinding namespace: user1 subjects: - kind: User name: user1 # Name is case sensitive apiGroup: rbac.authorization.k8s.io roleRef: kind: ClusterRole name: myauth-user apiGroup: rbac.authorization.k8s.io 3.配置 新建静态密码文件 # vi /etc/kubernetes/pki/basic_auth_file admin,admin,1004 jane2,jane,1005 user1,user1,1006 user2,user2,1007 修改apiserver配置修改/etc/kubernetes/manifests/kube-apiserver.yaml在一堆参数配置下面增加 --basic-auth-file=/etc/kubernetes/pki/basic_auth_file eg: - --etcd-servers=https://127.0.0.1:2379 - --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt - --etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt - --etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key - --basic-auth-file=/etc/kubernetes/pki/basic_auth_file 这里将静态文件放在/etc/kubernetes/pki/目录下的原因是,apiserver通过容器启动,这个路径已经挂载容器中了,可以被访问到。放在其他路径需要额外配置挂载路径。apiserver只会启动在master节点上,故仅需要在master节点上配置即可。 启动好以后在master机器上执行kubectlgetall,多半是执行不成功的,因为修改apiserver配置文件后,apiserver自动重启,然后启动失败,所以就无法访问集群了。使用dockerps查看发现k8s_kube-scheduler和k8s_kube-controller-manager重启了,但是apiserver没起来。执行systemctlrestartkubelet,再dockerps就能看到apiserver启动成功了。如果还没启动起来,那再看看上面哪里配置有问题。 应用 使用--username={username}--password={password}参数访问kubectl 参考https://kubernetes-v1-4.github.io/docs/user-guide/kubectl/kubectl_create/ kubectl get all -n user1 --username=user1 --password=user1 kubectl create -f tf1-rc.yaml --username=user1 --password=user1 使用 curl -u {username}:{password} `js"https://{masterIP}:6443/api/v1/" -k访问httprestfulapicurl -u jane:jane2 "https://localhost:6443/api/v1/namespaces/user1/pods" -kcurl -u jane:jane2 "https://localhost:6443/api/v1/namespaces/user1" -k curl -u user1:user1 "https://localhost:6443/api/v1/namespaces/user1" -kcurl -u user1:user1 "https://localhost:6443/api/v1/namespaces/user1/pods" -kcurl -u user1:user1 "https://localhost:6443/api/v1/namespaces/user1/resourcequotas/" -k curl -u user2:user2 "https://localhost:6443/api/v1/namespaces/user2" -kcurl -u user2:user2 "https://localhost:6443/api/v1/namespaces/user2/pods" -kcurl -u user2:user2 "https://localhost:6443/api/v1/namespaces/user2/resourcequotas/" -k

优秀的个人博客,低调大师

【转载】使用Docker企业版确保租户安全

本文作者: Jenny Fong,转载自Docker公司微信公众号。 通过最新版本的 Docker 企业版 (EE),企业可以在整个应用组合中进一步扩大容器所带来的好处。Docker EE 可以将传统 Windows 和 Linux 应用程序以及在 IBM Z 大型机上运行的 Linux 应用程序快速进行现代化。 对于所有这些类型的应用程序,Docker EE 提供了一种通用的标准化封装格式,大大提高了应用的可移植性、灵活性,以及增强的安全性,从而使更多团队将其工作负载引入到 Docker EE 中。 保持这种多样化环境良好运转的关键在于要有一种方法来保护和隔离应用以及构建、交付和部署这些应用的多个团队。此版本的 Docker 企业版使各组织能够将各种不同的传统应用程序现代化,并遵循复杂组织的要求来确保其安全性。 为 Windows 应用

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册