defaults.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 policy
  15. import (
  16. "yunion.io/x/pkg/util/rbacscope"
  17. api "yunion.io/x/onecloud/pkg/apis/identity"
  18. "yunion.io/x/onecloud/pkg/cloudcommon/consts"
  19. common_policy "yunion.io/x/onecloud/pkg/cloudcommon/policy"
  20. "yunion.io/x/onecloud/pkg/util/rbacutils"
  21. )
  22. const (
  23. PolicyActionGet = common_policy.PolicyActionGet
  24. PolicyActionList = common_policy.PolicyActionList
  25. PolicyActionCreate = common_policy.PolicyActionCreate
  26. PolicyActionUpdate = common_policy.PolicyActionUpdate
  27. PolicyActionDelete = common_policy.PolicyActionDelete
  28. PolicyActionPerform = common_policy.PolicyActionPerform
  29. )
  30. var (
  31. predefinedDefaultPolicies = []rbacutils.SRbacPolicy{
  32. {
  33. Auth: true,
  34. Scope: rbacscope.ScopeUser,
  35. Rules: []rbacutils.SRbacRule{
  36. {
  37. Service: api.SERVICE_TYPE,
  38. Resource: "credentials",
  39. Action: PolicyActionGet,
  40. Result: rbacutils.Allow,
  41. },
  42. {
  43. Service: api.SERVICE_TYPE,
  44. Resource: "credentials",
  45. Action: PolicyActionList,
  46. Result: rbacutils.Allow,
  47. },
  48. {
  49. Service: api.SERVICE_TYPE,
  50. Resource: "credentials",
  51. Action: PolicyActionCreate,
  52. Result: rbacutils.Allow,
  53. },
  54. {
  55. Service: api.SERVICE_TYPE,
  56. Resource: "credentials",
  57. Action: PolicyActionUpdate,
  58. Result: rbacutils.Allow,
  59. },
  60. {
  61. Service: api.SERVICE_TYPE,
  62. Resource: "credentials",
  63. Action: PolicyActionDelete,
  64. Result: rbacutils.Allow,
  65. },
  66. },
  67. },
  68. {
  69. Auth: true,
  70. Scope: rbacscope.ScopeProject,
  71. Rules: []rbacutils.SRbacRule{
  72. {
  73. Service: api.SERVICE_TYPE,
  74. Resource: "users",
  75. Action: PolicyActionList,
  76. Result: rbacutils.Allow,
  77. },
  78. {
  79. Service: api.SERVICE_TYPE,
  80. Resource: "groups",
  81. Action: PolicyActionList,
  82. Result: rbacutils.Allow,
  83. },
  84. },
  85. },
  86. {
  87. // for domain
  88. Auth: true,
  89. Scope: rbacscope.ScopeDomain,
  90. Rules: []rbacutils.SRbacRule{
  91. {
  92. Service: api.SERVICE_TYPE,
  93. Resource: "domains",
  94. Action: PolicyActionGet,
  95. Result: rbacutils.Allow,
  96. },
  97. },
  98. },
  99. {
  100. // for policies administration
  101. Auth: true,
  102. Scope: rbacscope.ScopeSystem,
  103. DomainId: api.DEFAULT_DOMAIN_ID,
  104. Projects: []string{api.SystemAdminProject},
  105. Roles: []string{api.SystemAdminRole},
  106. Rules: []rbacutils.SRbacRule{
  107. {
  108. Service: api.SERVICE_TYPE,
  109. Resource: "policies",
  110. Action: PolicyActionCreate,
  111. Result: rbacutils.Allow,
  112. },
  113. {
  114. Service: api.SERVICE_TYPE,
  115. Resource: "policies",
  116. Action: PolicyActionUpdate,
  117. Result: rbacutils.Allow,
  118. },
  119. {
  120. Service: api.SERVICE_TYPE,
  121. Resource: "policies",
  122. Action: PolicyActionList,
  123. Result: rbacutils.Allow,
  124. },
  125. {
  126. Service: api.SERVICE_TYPE,
  127. Resource: "policies",
  128. Action: PolicyActionGet,
  129. Result: rbacutils.Allow,
  130. },
  131. {
  132. Service: api.SERVICE_TYPE,
  133. Resource: "policies",
  134. Action: PolicyActionPerform,
  135. Result: rbacutils.Allow,
  136. },
  137. {
  138. Service: api.SERVICE_TYPE,
  139. Resource: "roles",
  140. Action: PolicyActionCreate,
  141. Result: rbacutils.Allow,
  142. },
  143. {
  144. Service: api.SERVICE_TYPE,
  145. Resource: "roles",
  146. Action: PolicyActionUpdate,
  147. Result: rbacutils.Allow,
  148. },
  149. {
  150. Service: api.SERVICE_TYPE,
  151. Resource: "roles",
  152. Action: PolicyActionGet,
  153. Result: rbacutils.Allow,
  154. },
  155. {
  156. Service: api.SERVICE_TYPE,
  157. Resource: "roles",
  158. Action: PolicyActionList,
  159. Result: rbacutils.Allow,
  160. },
  161. {
  162. Service: api.SERVICE_TYPE,
  163. Resource: "roles",
  164. Action: PolicyActionPerform,
  165. Result: rbacutils.Allow,
  166. },
  167. },
  168. },
  169. }
  170. )
  171. func Init() {
  172. if consts.IsEnableDefaultPolicy() {
  173. common_policy.AppendDefaultPolicies(predefinedDefaultPolicies)
  174. }
  175. }