时间:2020-06-20来源:www.pcxitongcheng.com作者:电脑系统城
命令 | 描述 |
oc adm policy who-can verb resource | 设置哪些用户可以对资源执行操作 |
oc adm policy add-role-to-user role username | 将指定角色绑定到指定用户 |
oc adm policy remove-role-from-user role username | 从指定用户中移除给定角色 |
oc adm policy remove-user username | 删除指定的用户及其所有角色 |
oc adm policy add-role-to-group role groupname | 将指定的角色绑定到指定的组 |
oc adm policy remove-role-fromgroup role groupname | 从指定组中移除给定角色 |
oc adm policy remove-group groupname | 删除指定的组及其所有角色 |
命令 | 描述 |
oc adm policy add-cluster-role-to-user role username | 将集群中所有项目的指定角色绑定到指定用户 |
oc adm policy remove-cluster-role-from-user role username | 为集群中的所有项目从指定用户中删除指定角色 |
oc adm policy add-cluster-role-togroup role groupname | 为集群中的所有项目将指定的角色绑定到指定的组 |
oc adm policy remove-cluster-role-from-group role groupname | 从集群中所有项目的指定组中移除给定角色 |
1 [user@demo ~]$ oc get scc #列出可用的SCC 2 [user@demo ~]$ oc describe scc scc_name #现实特定SCC详细信息 3 [user@demo ~]$ oc adm policy add-scc-to-user scc_name user_name 4 [user@demo ~]$ oc adm policy add-scc-to-group scc_name group_name #要授予用户或组特定的SCC 5 [user@demo ~]$ oc adm policy remove-scc-from-user scc_name user_name 6 [user@demo ~]$ oc adm policy remove-scc-from-group scc_name group_name #从特定的SCC中删除用户或组
1 [kiosk@foundation0 ~]$ ssh root@master 2 [root@master ~]# htpasswd -b /etc/origin/master/htpasswd user1 redhat 3 [root@master ~]# htpasswd -b /etc/origin/master/htpasswd user2 redhat 4 #添加基于htpasswd形式的user1和user2,密码都为redhat。
1 [student@workstation ~]$ oc login -u admin -p redhat https://master.lab.example.com #使用管理员登录 2 [student@workstation ~]$ oc adm policy remove-cluster-role-from-group \ 3 self-provisioner system:authenticated:oauth 4 #删除所有赋予普通创建项目的功能,该命令可参考本环境如下目录中的命令。 5 [student@workstation ~]$ cat /home/student/DO280/labs/secure-resources/configure-policy.sh 6 #!/bin/bash 7 oc adm policy remove-cluster-role-from-group \ 8 self-provisioner system:authenticated system:authenticated:oauth
1 [student@workstation ~]$ oc login -u user1 -p redhat https://master.lab.example.com #使用普通用户user1登录 2 [student@workstation ~]$ oc new-project test #测试创建project 3 Error from server (Forbidden): You may not request a new project via this API.
1 [student@workstation ~]$ oc login -u admin -p redhat https://master.lab.example.com #使用集群管理员登录 2 [student@workstation ~]$ oc new-project project-user1 #创建两个项目 3 [student@workstation ~]$ oc new-project project-user2
1 #选择项目1 2 Now using project "project-user1" on server "https://master.lab.example.com:443". 3 [student@workstation ~]$ oc policy add-role-to-user admin user1 #将user1添加为项目1的管理员 4 role "admin" added: "user1" 5 [student@workstation ~]$ oc policy add-role-to-user edit user2 #将user2添加为项目1的开发员 6 role "edit" added: "user2" 7 8 [student@workstation ~]$ oc project project-user2 #选择项目2 9 Now using project "project-user2" on server "https://master.lab.example.com:443". 10 [student@workstation ~]$ oc policy add-role-to-user edit user2 #将user2添加为项目2的开发员 11 role "edit" added: "user2"
1 [student@workstation ~]$ oc login -u user1 -p redhat https://master.lab.example.com #使用user1登录 2 [student@workstation ~]$ oc project project-user1 #验证项目1的访问 3 Already on project "project-user1" on server "https://master.lab.example.com:443". 4 [student@workstation ~]$ oc project project-user2 #验证项目2的访问 5 error: You are not a member of project "project-user2". 6 You have one project on this server: project-user1 7 8 [student@workstation ~]$ oc login -u user2 -p redhat https://master.lab.example.com #使用user2登录 9 [student@workstation ~]$ oc project project-user1 10 Already on project "project-user1" on server "https://master.lab.example.com:443". #验证项目1的访问 11 [student@workstation ~]$ oc project project-user2 12 Now using project "project-user2" on server "https://master.lab.example.com:443". #验证项目2的访问
1 [student@workstation ~]$ oc login -u user2 -p redhat https://master.lab.example.com 2 [student@workstation ~]$ oc project project-user1 3 Now using project "project-user1" on server "https://master.lab.example.com:443". 4 [student@workstation ~]$ oc new-app --name=nginx --docker-image=registry.lab.example.com/nginx:latest 5 #使用在项目1上不具备admin权限的用户user2登录,并部署应用,会出现如下提示:
1 [student@workstation ~]$ oc get pods
1 [student@workstation ~]$ oc login -u user1 -p redhat https://master.lab.example.com #使用项目1的admin账户登录 2 [student@workstation ~]$ oc create serviceaccount useroot #创建服务账户 3 serviceaccount "useroot" created 4 [student@workstation ~]$ oc login -u admin -p redhat https://master.lab.example.com #使用集群管理员登录 5 [student@workstation ~]$ oc project project-user1 #选择项目1 6 Already on project "project-user1" on server "https://master.lab.example.com:443". 7 [student@workstation ~]$ oc adm policy add-scc-to-user anyuid -z useroot #设置SCC策略 8 scc "anyuid" added to: ["system:serviceaccount:project-user1:useroot"] #将服务帐户与anyuid安全上下文关联,此操作需要集群管理员用户。 9 [student@workstation ~]$ oc login -u user2 -p redhat https://master.lab.example.com #切换user2用户 10 [student@workstation ~]$ oc project project-user1 11 Already on project "project-user1" on server "https://master.lab.example.com:443". 12 [student@workstation ~]$ oc patch dc nginx --patch='{"spec":{"template":{"spec":{"serviceAccountName": "useroot"}}}}'
1 [student@workstation ~]$ oc get pods 2 NAME READY STATUS RESTARTS AGE 3 nginx-2-98k8f 1/1 Running 0 3m 4
1 [student@workstation ~]$ oc expose svc nginx 2 route "nginx" exposed 3 [student@workstation ~]$ oc get svc 4 NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 5 nginx ClusterIP 172.30.118.63 <none> 80/TCP 13m 6 [student@workstation ~]$ oc get route 7 NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD 8 nginx nginx-project-user1.apps.lab.example.com nginx 80-tcp None
1 [student@workstation ~]$ curl -s http://nginx-project-user1.apps.lab.example.com
1 [student@workstation ~]$ oc login -u admin -p redhat 2 [student@workstation ~]$ oc adm policy add-cluster-role-to-group self-provisioner system:authenticated system:authenticated:oauth 3 cluster role "self-provisioner" added: ["system:authenticated" "system:authenticated:oauth"] 4 [student@workstation ~]$ oc delete project project-user1 5 project "project-user1" deleted 6 [student@workstation ~]$ oc delete project project-user2 7 [root@master ~]# htpasswd -D /etc/origin/master/htpasswd user1 8 [root@master ~]# htpasswd -D /etc/origin/master/htpasswd user2
1 [user@demo ~]$ oc create secret generic secret_name \ 2 --from-literal=key1=secret1 \ 3 --from-literal=key2=secret2 #用secret data创建secret对象 4 [user@demo ~]$ oc secrets add --for=mount serviceaccount/serviceaccount-name \ 5 secret/secret_name #更新pod的服务帐户,允许引用该secrets。
1 env: 2 - name: MYSQL_ROOT_PASSWORD 3 valueFrom: 4 secretKeyRef: 5 key: username 6 name: demo-secret
1 [user@demo ~]$ oc create configmap special-config \ 2 --from-literal=serverAddress=172.20.30.40 3 [user@demo ~]$ oc get configmaps special-config -o yaml #查看configMap 4 apiVersion: v1 5 data: 6 key1: serverAddress=172.20.30.40 7 kind: ConfigMap 8 metadata: 9 creationTimestamp: 2017-07-10T17:13:31Z 10 name: special-config 11 …… 12 在配置映射的pod定义中填充环境变量APISERVER。 13 env: 14 - name: APISERVER 15 valueFrom: 16 configMapKeyRef: 17 name: special-config 18 key: serverAddress
1 [student@workstation ~]$ oc login -u developer -p redhat 2 [student@workstation ~]$ cd /home/student/DO280/labs/secure-secrets/ 3 [student@workstation secure-secrets]$ less mysql-ephemeral.yml #导入本环境MySQL模板
1 [student@workstation secure-secrets]$ oc create secret generic mysql \ 2 --from-literal='database-user'='mysql' \ 3 --from-literal='database-password'='redhat' \ 4 --from-literal='database-root-password'='do280-admin' 5 [student@workstation secure-secrets]$ oc get secret mysql -o yaml #确认secret
1 [student@workstation secure-secrets]$ oc new-app --file=mysql-ephemeral.yml 2 [student@workstation secure-secrets]$ oc get pods #确认应用 3 NAME READY STATUS RESTARTS AGE 4 mysql-1-j4fnz 1/1 Running 0 1m
1 [student@workstation secure-secrets]$ cd 2 [student@workstation ~]$ oc port-forward mysql-1-j4fnz 3306:3306
1 [student@workstation ~]$ mysql -uroot -pdo280-admin -h127.0.0.1 #新开终端测试MySQL
描述 | |
此角色中的所有用户都可以管理OpenShift集群。 | |
此角色中的所有用户都提供对集群信息的只读访问。 |
描述 | |
角色中的用户可以从项目中创建、更改和删除公共应用程序资源,比如service和dc。 但是不能对限制范围和配额等管理资源采取行动,也不能管理对项目的访问权限。 |
|
角色中的用户具有对项目的读访问权。 | |
角色中的用户可以创建新项目。这是一个集群角色,而不是项目角色。 | |
角色中的用户可以管理项目中的所有资源,包括授予对项目的其他用户的访问权 |
1 向集群用户添加角色 2 $ oc adm policy add-cluster-role-to-user cluster-role username 3 示例:将普通用户更改为集群管理员。 4 $ oc adm policy add-cluster-role-to-user cluster-role username 5 从用户中删除集群角色 6 $ oc adm policy remove-cluster-role-from-user cluster-role username 7 示例:将集群管理员更改为普通用户。 8 $ oc adm policy remove-cluster-role-from-user cluster-admin username 9 将指定的用户绑定到项目中的角色 10 $ oc adm policy add-role-to-user role-name username -n project 11 示例:在WordPress项目中dev用户绑定basic-user角色。 12 $ oc adm policy add-role-to-user basic-user dev -n wordpress
1 $ oc adm policy who-can delete user
1 [student@workstation ~]$ lab secure-review setup
1 [root@master ~]# htpasswd /etc/origin/master/htpasswd user-review 2 New password: 【redhat】 3 Re-type new password: 【redhat】
1 [student@workstation ~]$ oc login -u admin -p redhat 2 [student@workstation ~]$ oc adm policy remove-cluster-role-from-group \ 3 self-provisioner system:authenticated system:authenticated:oauth 4 禁用所有常规用户的项目创建功能
1 [student@workstation ~]$ oc login -u user-review -p redhat 2 [student@workstation ~]$ oc new-project test #普通用户无法创建项目 3 Error from server (Forbidden): You may not request a new project via this API.
1 [student@workstation ~]$ oc login -u admin -p redhat 2 [student@workstation ~]$ oc new-project secure-review #使用管理员创建项目
1 [student@workstation ~]$ oc project secure-review 2 Already on project "secure-review" on server "https://master.lab.example.com:443". 3 [student@workstation ~]$ oc policy add-role-to-user edit user-review #将edit的role和user-review进行关联
1 [student@workstation ~]$ oc login -u user-review -p redhat 2 [student@workstation ~]$ oc project secure-review #测试访问 3 Already on project "secure-review" on server "https://master.lab.example.com:443".
1 [student@workstation ~]$ cd /home/student/DO280/labs/secure-review/ 2 [student@workstation secure-review]$ less mysql-ephemeral.yml
1 [student@workstation secure-review]$ oc create secret generic mysql \ 2 --from-literal='database-user'='mysql' \ 3 --from-literal='database-password'='redhat' \ 4 --from-literal='database-root-password'='do280-admin' 5 [student@workstation secure-review]$ oc get secret mysql -o yaml #确认验证secret
1 [student@workstation secure-review]$ oc new-app --file=mysql-ephemeral.yml 2 [student@workstation secure-review]$ oc get pods 3 NAME READY STATUS RESTARTS AGE 4 mysql-1-2lr7t 1/1 Running 0 31s
1 [student@workstation ~]$ oc port-forward mysql-1-2lr7t 3306:3306
1 [student@workstation ~]$ mysql -umysql -predhat -h127.0.0.1
1 [student@workstation ~]$ oc new-app --name=phpmyadmin \ 2 --docker-image=registry.lab.example.com/phpmyadmin/phpmyadmin:4.7 \ 3 -e PMA_HOST=mysql.secure-review.svc.cluster.local
1 [student@workstation ~]$ oc get pods 2 NAME READY STATUS RESTARTS AGE 3 mysql-1-2lr7t 1/1 Running 0 8m 4 phpmyadmin-1-v7tl7 0/1 Error 2 1m 5 因为没有root权限,因此部署失败,需要提权。
1 [student@workstation ~]$ oc login -u admin -p redhat #使用管理员登录 2 [student@workstation ~]$ oc create serviceaccount phpmyadmin-account #首先创建服务账户 3 [student@workstation ~]$ oc adm policy add-scc-to-user anyuid -z phpmyadmin-account 4 scc "anyuid" added to: ["system:serviceaccount:secure-review:phpmyadmin-account"] #将服务帐户与anyuid安全上下文关联
1 [student@workstation ~]$ oc patch dc phpmyadmin --patch='{"spec":{"template":{"spec":{"serviceAccountName": "phpmyadmin-account"}}}}'
1 [student@workstation ~]$ oc login -u user-review -p redhat 2 [student@workstation ~]$ oc get pods #确认pod是否正常 3 NAME READY STATUS RESTARTS AGE 4 mysql-1-2lr7t 1/1 Running 0 13m 5 phpmyadmin-2-bdjvq 1/1 Running 0 1m
1 [student@workstation ~]$ oc expose svc phpmyadmin --hostname=phpmyadmin.apps.lab.example.com
1 [student@workstation ~]$ curl -s http://phpmyadmin.apps.lab.example.com
1 [student@workstation ~]$ lab secure-review grade #环境脚本判断 2 [student@workstation ~]$ oc login -u admin -p redhat 3 [student@workstation ~]$ oc adm policy add-cluster-role-to-group \ 4 self-provisioner system:authenticated system:authenticated:oauth 5 [student@workstation ~]$ oc delete project secure-review 6 [student@workstation ~]$ ssh root@master htpasswd -D \ 7 /etc/origin/master/htpasswd user-review #删除用户 8 [student@workstation ~]$ oc delete user user-review #删除项目
2024-07-18
Centos 7 二进制安装配置 MariaDB数据库2024-07-18
Centos7默认firewalld防火墙使用命令大全2024-07-07
四种执行python系统命令的方法常用权限linux系统内有档案有三种身份 u:拥有者 g:群组 o:其他人这些身份对于文档常用的有下面权限:r:读权限,用户可以读取文档的内容,如用cat,more查看w:写权限,用户可以编辑文档x...
2024-07-07
然而,如果我们遵循通常的 WordPress 最佳实践,这些安全问题可以避免。在本篇中,我们会向你展示如何使用 WPSeku,一个 Linux 中的 WordPress 漏洞扫描器,它可以被用来找出你安装...
2024-07-03