defaults.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/cloudid"
  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. PolicyActionList = common_policy.PolicyActionList
  25. PolicyActionGet = common_policy.PolicyActionGet
  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.ScopeSystem,
  35. Rules: []rbacutils.SRbacRule{
  36. {
  37. Service: api.SERVICE_TYPE,
  38. Resource: "cloudpolicies",
  39. Action: PolicyActionList,
  40. Result: rbacutils.Allow,
  41. },
  42. {
  43. Service: api.SERVICE_TYPE,
  44. Resource: "cloudpolicies",
  45. Action: PolicyActionGet,
  46. Result: rbacutils.Allow,
  47. },
  48. },
  49. },
  50. {
  51. Auth: true,
  52. Scope: rbacscope.ScopeDomain,
  53. Rules: []rbacutils.SRbacRule{
  54. {
  55. Service: api.SERVICE_TYPE,
  56. Resource: "cloudgroups",
  57. Action: PolicyActionList,
  58. Result: rbacutils.Allow,
  59. },
  60. {
  61. Service: api.SERVICE_TYPE,
  62. Resource: "cloudgroups",
  63. Action: PolicyActionGet,
  64. Result: rbacutils.Allow,
  65. },
  66. },
  67. },
  68. {
  69. Auth: true,
  70. Scope: rbacscope.ScopeUser,
  71. Rules: []rbacutils.SRbacRule{
  72. {
  73. Service: api.SERVICE_TYPE,
  74. Resource: "cloudusers",
  75. Action: PolicyActionList,
  76. Result: rbacutils.Allow,
  77. },
  78. {
  79. Service: api.SERVICE_TYPE,
  80. Resource: "cloudusers",
  81. Action: PolicyActionGet,
  82. Result: rbacutils.Allow,
  83. },
  84. },
  85. },
  86. {
  87. Auth: true,
  88. Scope: rbacscope.ScopeUser,
  89. Rules: []rbacutils.SRbacRule{
  90. {
  91. Service: api.SERVICE_TYPE,
  92. Resource: "samlusers",
  93. Action: PolicyActionList,
  94. Result: rbacutils.Allow,
  95. },
  96. {
  97. Service: api.SERVICE_TYPE,
  98. Resource: "samlusers",
  99. Action: PolicyActionGet,
  100. Result: rbacutils.Allow,
  101. },
  102. },
  103. },
  104. }
  105. )
  106. func Init() {
  107. if consts.IsEnableDefaultPolicy() {
  108. common_policy.AppendDefaultPolicies(predefinedDefaultPolicies)
  109. }
  110. }