defaults.go 2.9 KB

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