predefined_policies.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package locale
  15. import (
  16. "yunion.io/x/pkg/util/rbacscope"
  17. )
  18. const (
  19. RoleAdmin = "admin"
  20. RoleFA = "fa"
  21. RoleDomainFA = "domainfa"
  22. RoleProjectFA = "projectfa"
  23. RoleSA = "sa"
  24. RoleProjectOwner = "project_owner"
  25. RoleDomainAdmin = "domainadmin"
  26. RoleDomainEditor = "domain_editor"
  27. RoleDomainViewer = "domain_viewer"
  28. RoleProjectEditor = "project_editor"
  29. RoleProjectViewer = "project_viewer"
  30. RoleMember = "member"
  31. )
  32. type sPolicyDefinition struct {
  33. Name string
  34. DescCN string
  35. Desc string
  36. Scope rbacscope.TRbacScope
  37. Services map[string][]string
  38. Extra map[string]map[string][]string
  39. AvailableRoles []string
  40. }
  41. type SRoleDefiniton struct {
  42. Name string
  43. Description string
  44. Policies []string
  45. Project string
  46. IsPublic bool
  47. DescriptionCN string
  48. }
  49. var (
  50. policyDefinitons = []sPolicyDefinition{
  51. {
  52. Name: "",
  53. DescCN: "任意资源",
  54. Desc: "any resources",
  55. Scope: rbacscope.ScopeProject,
  56. Services: map[string][]string{
  57. "*": nil,
  58. },
  59. },
  60. {
  61. Name: "dashboard",
  62. DescCN: "控制面板查看相关资源",
  63. Desc: "resources for viewing dashboard",
  64. Scope: rbacscope.ScopeProject,
  65. Extra: map[string]map[string][]string{
  66. "compute": {
  67. "dashboard": {
  68. "get",
  69. },
  70. "capabilities": {
  71. "list",
  72. },
  73. "usages": {
  74. "list",
  75. "get",
  76. },
  77. "quotas": {
  78. "list",
  79. "get",
  80. },
  81. "zone_quotas": {
  82. "list",
  83. "get",
  84. },
  85. "region_quotas": {
  86. "list",
  87. "get",
  88. },
  89. "project_quotas": {
  90. "list",
  91. "get",
  92. },
  93. "domain_quotas": {
  94. "list",
  95. "get",
  96. },
  97. "infras_quotas": {
  98. "list",
  99. "get",
  100. },
  101. },
  102. "image": {
  103. "usages": {
  104. "list",
  105. "get",
  106. },
  107. "image_quotas": {
  108. "list",
  109. "get",
  110. },
  111. },
  112. "identity": {
  113. "usages": {
  114. "list",
  115. "get",
  116. },
  117. "identity_quotas": {
  118. "list",
  119. "get",
  120. },
  121. "projects": {
  122. "list",
  123. },
  124. },
  125. "meter": {
  126. "bill_conditions": {
  127. "list",
  128. },
  129. },
  130. "monitor": {
  131. "alertrecords": {
  132. "list",
  133. },
  134. "alertresources": {
  135. "list",
  136. },
  137. "unifiedmonitors": {
  138. "perform",
  139. },
  140. "monitorresourcealerts": {
  141. "list",
  142. "get",
  143. },
  144. "nodealerts": {
  145. "list",
  146. },
  147. },
  148. "notify": {
  149. "notifications": {
  150. "list",
  151. "get",
  152. },
  153. "robots": {
  154. "list",
  155. "get",
  156. },
  157. "receivers": {
  158. "list",
  159. "get",
  160. },
  161. },
  162. "devtool": {
  163. "scriptapplyrecords": {
  164. "list",
  165. "get",
  166. },
  167. },
  168. "yunionconf": {
  169. "scopedpolicybindings": {
  170. "list",
  171. "get",
  172. },
  173. },
  174. "suggestion": {
  175. "suggestsysalerts": {
  176. "list",
  177. "get",
  178. },
  179. },
  180. },
  181. },
  182. {
  183. Name: "compute",
  184. DescCN: "计算服务(云主机与容器)相关资源",
  185. Desc: "resources of computing (cloud servers and containers)",
  186. Scope: rbacscope.ScopeProject,
  187. Services: map[string][]string{
  188. "compute": nil,
  189. "image": nil,
  190. "k8s": nil,
  191. },
  192. },
  193. {
  194. Name: "server",
  195. DescCN: "云主机相关资源",
  196. Desc: "resources of cloud servers",
  197. Scope: rbacscope.ScopeProject,
  198. Services: map[string][]string{
  199. "compute": {
  200. "servers",
  201. "servertemplates",
  202. "instancegroups",
  203. "scalinggroups",
  204. "scalingactivities",
  205. "scalingpolicies",
  206. "disks",
  207. "networks",
  208. "eips",
  209. "snapshotpolicies",
  210. "snapshotpolicycaches",
  211. "snapshotpolicydisks",
  212. "snapshots",
  213. "instance_snapshots",
  214. "snapshotpolicies",
  215. "secgroupcaches",
  216. "secgrouprules",
  217. "secgroups",
  218. },
  219. "image": nil,
  220. },
  221. Extra: map[string]map[string][]string{
  222. "compute": {
  223. "isolated_devices": {
  224. "get",
  225. "list",
  226. },
  227. },
  228. },
  229. },
  230. {
  231. Name: "host",
  232. DescCN: "宿主机和物理机相关资源",
  233. Desc: "resources of hosts and baremetals",
  234. Scope: rbacscope.ScopeDomain,
  235. Services: map[string][]string{
  236. "compute": {
  237. "hosts",
  238. "isolated_devices",
  239. "hostwires",
  240. "hoststorages",
  241. "baremetalagents",
  242. "baremetalnetworks",
  243. "baremetalevents",
  244. },
  245. },
  246. },
  247. {
  248. Name: "storage",
  249. DescCN: "云硬盘存储相关资源",
  250. Desc: "resources of cloud disk storages",
  251. Scope: rbacscope.ScopeDomain,
  252. Services: map[string][]string{
  253. "compute": {
  254. "storages",
  255. },
  256. },
  257. },
  258. {
  259. Name: "loadbalancer",
  260. DescCN: "负载均衡相关资源",
  261. Desc: "resources of load balancers",
  262. Scope: rbacscope.ScopeProject,
  263. Services: map[string][]string{
  264. "compute": {
  265. "loadbalanceracls",
  266. "loadbalanceragents",
  267. "loadbalancerbackendgroups",
  268. "loadbalancerbackends",
  269. "loadbalancercertificates",
  270. "loadbalancerclusters",
  271. "loadbalancerlistenerrules",
  272. "loadbalancerlisteners",
  273. "loadbalancernetworks",
  274. "loadbalancers",
  275. },
  276. },
  277. Extra: map[string]map[string][]string{
  278. "compute": {
  279. "networks": {
  280. "get",
  281. "list",
  282. },
  283. },
  284. },
  285. },
  286. {
  287. Name: "oss",
  288. DescCN: "对象存储相关资源",
  289. Desc: "resources of object storages",
  290. Scope: rbacscope.ScopeProject,
  291. Services: map[string][]string{
  292. "compute": {
  293. "buckets",
  294. },
  295. },
  296. },
  297. {
  298. Name: "dbinstance",
  299. DescCN: "关系型数据库(MySQL等)相关资源",
  300. Desc: "resources of RDS",
  301. Scope: rbacscope.ScopeProject,
  302. Services: map[string][]string{
  303. "compute": {
  304. "dbinstance_skus",
  305. "dbinstanceaccounts",
  306. "dbinstancebackups",
  307. "dbinstancedatabases",
  308. "dbinstancenetworks",
  309. "dbinstanceparameters",
  310. "dbinstanceprivileges",
  311. "dbinstances",
  312. },
  313. },
  314. },
  315. {
  316. Name: "elasticcache",
  317. DescCN: "弹性缓存(Redis等)相关资源",
  318. Desc: "resources of elastic caches",
  319. Scope: rbacscope.ScopeProject,
  320. Services: map[string][]string{
  321. "compute": {
  322. "elasticcacheaccounts",
  323. "elasticcacheacls",
  324. "elasticcachebackups",
  325. "elasticcacheparameters",
  326. "elasticcaches",
  327. "elasticcacheskus",
  328. },
  329. },
  330. },
  331. {
  332. Name: "network",
  333. DescCN: "网络相关资源",
  334. Desc: "resources of networking",
  335. Scope: rbacscope.ScopeDomain,
  336. Services: map[string][]string{
  337. "compute": {
  338. "vpcs",
  339. "wires",
  340. "natdentries",
  341. "natgateways",
  342. "natsentries",
  343. "networkinterfacenetworks",
  344. "networkinterfaces",
  345. "networks",
  346. "reservedips",
  347. "route_tables",
  348. "globalvpcs",
  349. "vpc_peering_connections",
  350. "eips",
  351. "dns_recordsets",
  352. "dns_trafficpolicies",
  353. "dns_zonecaches",
  354. "dns_zones",
  355. "dnsrecords",
  356. },
  357. },
  358. },
  359. {
  360. Name: "snapshotpolicy",
  361. DescCN: "快照策略",
  362. Desc: "snapshot policy",
  363. Scope: rbacscope.ScopeDomain,
  364. Services: map[string][]string{
  365. "compute": {
  366. "snapshotpolicies",
  367. "snapshotpolicydisks",
  368. },
  369. },
  370. },
  371. {
  372. Name: "secgroup",
  373. DescCN: "安全组",
  374. Desc: "security group",
  375. Scope: rbacscope.ScopeDomain,
  376. Services: map[string][]string{
  377. "compute": {
  378. "secgroups",
  379. "secgrouprules",
  380. },
  381. },
  382. },
  383. {
  384. Name: "meter",
  385. DescCN: "计费计量分析服务相关资源",
  386. Desc: "resources of metering and billing service",
  387. Scope: rbacscope.ScopeProject,
  388. Services: map[string][]string{
  389. "meter": nil,
  390. "suggestion": nil,
  391. "notify": {
  392. "receivers",
  393. },
  394. },
  395. },
  396. {
  397. Name: "identity",
  398. DescCN: "身份认证(IAM)服务相关资源",
  399. Desc: "resources of identity service",
  400. Scope: rbacscope.ScopeDomain,
  401. Services: map[string][]string{
  402. "identity": nil,
  403. },
  404. },
  405. {
  406. Name: "image",
  407. DescCN: "镜像服务相关资源",
  408. Desc: "resources of image service",
  409. Scope: rbacscope.ScopeProject,
  410. Services: map[string][]string{
  411. "image": nil,
  412. },
  413. },
  414. {
  415. Name: "monitor",
  416. DescCN: "监控服务相关资源",
  417. Desc: "resources of monitor service",
  418. Scope: rbacscope.ScopeProject,
  419. Services: map[string][]string{
  420. "monitor": nil,
  421. },
  422. },
  423. {
  424. Name: "container",
  425. DescCN: "容器服务相关资源",
  426. Desc: "resources of container service",
  427. Scope: rbacscope.ScopeProject,
  428. Services: map[string][]string{
  429. "k8s": nil,
  430. },
  431. },
  432. {
  433. Name: "cloudid",
  434. DescCN: "云用户及权限管理相关资源",
  435. Desc: "resources of service CloudId and IAM",
  436. Scope: rbacscope.ScopeDomain,
  437. Services: map[string][]string{
  438. "compute": {
  439. "cloudaccounts",
  440. "cloudproviders",
  441. },
  442. "identity": {
  443. "users",
  444. "projects",
  445. "roles",
  446. },
  447. "cloudid": nil,
  448. },
  449. },
  450. {
  451. Name: "cloudaccount",
  452. DescCN: "云账号管理相关资源",
  453. Desc: "resources for cloud account administration",
  454. Scope: rbacscope.ScopeDomain,
  455. Services: map[string][]string{
  456. "compute": {
  457. "cloudaccounts",
  458. "cloudproviderquotas",
  459. "cloudproviderregions",
  460. "cloudproviders",
  461. },
  462. },
  463. },
  464. {
  465. Name: "projectresource",
  466. DescCN: "项目管理相关资源",
  467. Desc: "resources for project administration",
  468. Scope: rbacscope.ScopeDomain,
  469. Services: map[string][]string{
  470. "compute": {
  471. "project_quotas",
  472. "quotas",
  473. "region_quotas",
  474. "zone_quotas",
  475. },
  476. "image": {
  477. "image_quotas",
  478. },
  479. "identity": {
  480. "projects",
  481. "roles",
  482. "policies",
  483. },
  484. },
  485. },
  486. {
  487. Name: "domainresource",
  488. DescCN: "域管理相关资源",
  489. Desc: "resources for domain administration",
  490. Scope: rbacscope.ScopeSystem,
  491. Services: map[string][]string{
  492. "compute": {
  493. "domain_quotas",
  494. "infras_quotas",
  495. },
  496. "identity": {
  497. "domains",
  498. "identity_quotas",
  499. "projects",
  500. "roles",
  501. "policies",
  502. "users",
  503. "groups",
  504. },
  505. },
  506. },
  507. {
  508. Name: "notify",
  509. DescCN: "通知服务相关资源",
  510. Desc: "resources of notify service",
  511. Scope: rbacscope.ScopeSystem,
  512. Services: map[string][]string{
  513. "notify": nil,
  514. },
  515. },
  516. {
  517. Name: "log",
  518. DescCN: "日志服务相关资源",
  519. Desc: "resources of logger service",
  520. Scope: rbacscope.ScopeSystem,
  521. Services: map[string][]string{
  522. "log": nil,
  523. },
  524. AvailableRoles: []string{
  525. "viewer",
  526. },
  527. },
  528. }
  529. adminPerformActions = map[string]map[string][]string{
  530. "compute": map[string][]string{
  531. "servers": []string{
  532. "snapshot-and-clone",
  533. "createdisk",
  534. "create-eip",
  535. "create-backup",
  536. "save-image",
  537. "delete-disk",
  538. "delete-eip",
  539. "delete-backup",
  540. },
  541. "buckets": []string{
  542. "upload",
  543. "delete",
  544. },
  545. },
  546. "k8s": map[string][]string{
  547. "kubeclusters": []string{
  548. "add-machines",
  549. "delete-machines",
  550. },
  551. },
  552. }
  553. RoleDefinitions = []SRoleDefiniton{
  554. {
  555. Name: RoleAdmin,
  556. DescriptionCN: "系统管理员",
  557. Description: "System administrator",
  558. Policies: []string{
  559. "sysadmin",
  560. },
  561. Project: "system",
  562. IsPublic: false,
  563. },
  564. {
  565. Name: RoleDomainAdmin,
  566. DescriptionCN: "域管理员",
  567. Description: "Domain administrator",
  568. Policies: []string{
  569. "domain-admin",
  570. },
  571. IsPublic: true,
  572. },
  573. {
  574. Name: RoleProjectOwner,
  575. DescriptionCN: "项目主管",
  576. Description: "Project owner",
  577. Policies: []string{
  578. "project-admin",
  579. },
  580. IsPublic: true,
  581. },
  582. {
  583. Name: RoleFA,
  584. DescriptionCN: "系统财务管理员",
  585. Description: "System finance administrator",
  586. Policies: []string{
  587. "sys-meter-admin",
  588. "sys-dashboard",
  589. },
  590. IsPublic: false,
  591. },
  592. {
  593. Name: RoleDomainFA,
  594. DescriptionCN: "域财务管理员",
  595. Description: "Domain finance administrator",
  596. Policies: []string{
  597. "domain-meter-admin",
  598. "domain-dashboard",
  599. },
  600. IsPublic: true,
  601. },
  602. {
  603. Name: RoleProjectFA,
  604. DescriptionCN: "项目财务管理员",
  605. Description: "Project finance administrator",
  606. Policies: []string{
  607. "project-meter-admin",
  608. "project-dashboard",
  609. },
  610. IsPublic: true,
  611. },
  612. {
  613. Name: RoleDomainEditor,
  614. DescriptionCN: "域操作员",
  615. Description: "Domain operation administrator",
  616. Policies: []string{
  617. "domain-editor",
  618. "domain-dashboard",
  619. },
  620. IsPublic: true,
  621. },
  622. {
  623. Name: RoleProjectEditor,
  624. DescriptionCN: "项目操作员",
  625. Description: "Project operator",
  626. Policies: []string{
  627. "project-editor",
  628. "project-dashboard",
  629. },
  630. IsPublic: true,
  631. },
  632. {
  633. Name: RoleDomainViewer,
  634. DescriptionCN: "域只读管理员",
  635. Description: "Domain read-only administrator",
  636. Policies: []string{
  637. "domain-viewer",
  638. "domain-dashboard",
  639. },
  640. IsPublic: true,
  641. },
  642. {
  643. Name: RoleProjectViewer,
  644. DescriptionCN: "项目只读成员",
  645. Description: "Project read-only member",
  646. Policies: []string{
  647. "project-viewer",
  648. "project-dashboard",
  649. },
  650. IsPublic: true,
  651. },
  652. {
  653. Name: "sys_opsadmin",
  654. DescriptionCN: "全局系统管理员",
  655. Description: "System-wide operation manager",
  656. Policies: []string{
  657. "sys-opsadmin",
  658. },
  659. IsPublic: true,
  660. },
  661. {
  662. Name: "sys_secadmin",
  663. DescriptionCN: "全局安全管理员",
  664. Description: "System-wide security manager",
  665. Policies: []string{
  666. "sys-secadmin",
  667. },
  668. IsPublic: true,
  669. },
  670. {
  671. Name: "sys_adtadmin",
  672. DescriptionCN: "全局审计管理员",
  673. Description: "System-wide audit manager",
  674. Policies: []string{
  675. "sys-adtadmin",
  676. },
  677. IsPublic: true,
  678. },
  679. {
  680. Name: "domain_opsadmin",
  681. DescriptionCN: "组织系统管理员",
  682. Description: "Domain-wide operation manager",
  683. Policies: []string{
  684. "domain-opsadmin",
  685. },
  686. IsPublic: true,
  687. },
  688. {
  689. Name: "domain_secadmin",
  690. DescriptionCN: "组织安全管理员",
  691. Description: "Domain-wide security manager",
  692. Policies: []string{
  693. "domain-secadmin",
  694. },
  695. IsPublic: true,
  696. },
  697. {
  698. Name: "domain_adtadmin",
  699. DescriptionCN: "组织审计管理员",
  700. Description: "Domain-wide audit manager",
  701. Policies: []string{
  702. "domain-adtadmin",
  703. },
  704. IsPublic: true,
  705. },
  706. {
  707. Name: "normal_user",
  708. DescriptionCN: "缺省普通用户角色",
  709. Description: "Default normal user role",
  710. Policies: []string{
  711. "normal-user",
  712. },
  713. IsPublic: true,
  714. },
  715. }
  716. )