defaults.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/jsonutils"
  17. "yunion.io/x/log"
  18. "yunion.io/x/pkg/util/rbacscope"
  19. "yunion.io/x/onecloud/pkg/util/rbacutils"
  20. )
  21. var (
  22. predefinedDefaultPolicies = []rbacutils.SRbacPolicy{
  23. {
  24. Auth: true,
  25. Scope: rbacscope.ScopeSystem,
  26. Rules: []rbacutils.SRbacRule{
  27. {
  28. Resource: "tasks",
  29. Action: PolicyActionPerform,
  30. Result: rbacutils.Allow,
  31. },
  32. {
  33. Resource: "metadatas",
  34. Action: PolicyActionList,
  35. Result: rbacutils.Allow,
  36. },
  37. },
  38. },
  39. {
  40. Auth: true,
  41. Scope: rbacscope.ScopeProject,
  42. Rules: []rbacutils.SRbacRule{
  43. {
  44. Resource: "tasks",
  45. Action: PolicyActionPerform,
  46. Result: rbacutils.Allow,
  47. },
  48. {
  49. // usages for any services
  50. Resource: "usages",
  51. Action: PolicyActionGet,
  52. Result: rbacutils.Allow,
  53. },
  54. },
  55. },
  56. {
  57. // for domain
  58. Auth: true,
  59. Scope: rbacscope.ScopeDomain,
  60. Rules: []rbacutils.SRbacRule{
  61. {
  62. // usages for any services
  63. Resource: "usages",
  64. Action: PolicyActionGet,
  65. Result: rbacutils.Allow,
  66. },
  67. },
  68. },
  69. }
  70. )
  71. func AppendDefaultPolicies(policies []rbacutils.SRbacPolicy) {
  72. log.Infof("Appending default policies: %s", jsonutils.Marshal(policies))
  73. predefinedDefaultPolicies = append(predefinedDefaultPolicies, policies...)
  74. }