defaults.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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/notify"
  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. PolicyActionPerform = common_policy.PolicyActionPerform
  24. PolicyActionGet = common_policy.PolicyActionGet
  25. PolicyActionList = common_policy.PolicyActionList
  26. PolicyActionCreate = common_policy.PolicyActionCreate
  27. PolicyActionUpdate = common_policy.PolicyActionUpdate
  28. PolicyActionDelete = common_policy.PolicyActionDelete
  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: "receivers",
  39. Action: PolicyActionGet,
  40. Result: rbacutils.Allow,
  41. },
  42. {
  43. Service: api.SERVICE_TYPE,
  44. Resource: "receivers",
  45. Action: PolicyActionList,
  46. Result: rbacutils.Allow,
  47. },
  48. {
  49. Service: api.SERVICE_TYPE,
  50. Resource: "receivers",
  51. Action: PolicyActionCreate,
  52. Result: rbacutils.Allow,
  53. },
  54. {
  55. Service: api.SERVICE_TYPE,
  56. Resource: "receivers",
  57. Action: PolicyActionUpdate,
  58. Result: rbacutils.Allow,
  59. },
  60. {
  61. Service: api.SERVICE_TYPE,
  62. Resource: "receivers",
  63. Action: PolicyActionDelete,
  64. Result: rbacutils.Allow,
  65. },
  66. {
  67. Service: api.SERVICE_TYPE,
  68. Resource: "receivers",
  69. Action: PolicyActionPerform,
  70. Result: rbacutils.Allow,
  71. },
  72. },
  73. },
  74. {
  75. Auth: true,
  76. Scope: rbacscope.ScopeSystem,
  77. Rules: []rbacutils.SRbacRule{
  78. {
  79. Service: api.SERVICE_TYPE,
  80. Resource: "topics",
  81. Action: PolicyActionGet,
  82. Result: rbacutils.Allow,
  83. },
  84. {
  85. Service: api.SERVICE_TYPE,
  86. Resource: "topics",
  87. Action: PolicyActionList,
  88. Result: rbacutils.Allow,
  89. },
  90. },
  91. },
  92. {
  93. Auth: true,
  94. Scope: rbacscope.ScopeSystem,
  95. Rules: []rbacutils.SRbacRule{
  96. {
  97. Service: api.SERVICE_TYPE,
  98. Resource: "subscribers",
  99. Action: PolicyActionGet,
  100. Result: rbacutils.Allow,
  101. },
  102. {
  103. Service: api.SERVICE_TYPE,
  104. Resource: "subscribers",
  105. Action: PolicyActionList,
  106. Result: rbacutils.Allow,
  107. },
  108. {
  109. Service: api.SERVICE_TYPE,
  110. Resource: "subscribers",
  111. Action: PolicyActionCreate,
  112. Result: rbacutils.Allow,
  113. },
  114. {
  115. Service: api.SERVICE_TYPE,
  116. Resource: "subscribers",
  117. Action: PolicyActionUpdate,
  118. Result: rbacutils.Allow,
  119. },
  120. {
  121. Service: api.SERVICE_TYPE,
  122. Resource: "subscribers",
  123. Action: PolicyActionDelete,
  124. Result: rbacutils.Allow,
  125. },
  126. {
  127. Service: api.SERVICE_TYPE,
  128. Resource: "subscribers",
  129. Action: PolicyActionPerform,
  130. Result: rbacutils.Allow,
  131. },
  132. },
  133. },
  134. {
  135. Auth: true,
  136. Scope: rbacscope.ScopeDomain,
  137. Rules: []rbacutils.SRbacRule{
  138. {
  139. Service: api.SERVICE_TYPE,
  140. Resource: "subscribers",
  141. Action: PolicyActionGet,
  142. Result: rbacutils.Allow,
  143. },
  144. {
  145. Service: api.SERVICE_TYPE,
  146. Resource: "subscribers",
  147. Action: PolicyActionList,
  148. Result: rbacutils.Allow,
  149. },
  150. {
  151. Service: api.SERVICE_TYPE,
  152. Resource: "subscribers",
  153. Action: PolicyActionCreate,
  154. Result: rbacutils.Allow,
  155. },
  156. {
  157. Service: api.SERVICE_TYPE,
  158. Resource: "subscribers",
  159. Action: PolicyActionUpdate,
  160. Result: rbacutils.Allow,
  161. },
  162. {
  163. Service: api.SERVICE_TYPE,
  164. Resource: "subscribers",
  165. Action: PolicyActionDelete,
  166. Result: rbacutils.Allow,
  167. },
  168. {
  169. Service: api.SERVICE_TYPE,
  170. Resource: "subscribers",
  171. Action: PolicyActionPerform,
  172. Result: rbacutils.Allow,
  173. },
  174. },
  175. },
  176. }
  177. )
  178. func Init() {
  179. if consts.IsEnableDefaultPolicy() {
  180. common_policy.AppendDefaultPolicies(predefinedDefaultPolicies)
  181. }
  182. }