defaults.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/image"
  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. )
  27. var (
  28. predefinedDefaultPolicies = []rbacutils.SRbacPolicy{
  29. {
  30. Auth: true,
  31. Scope: rbacscope.ScopeProject,
  32. Rules: []rbacutils.SRbacRule{
  33. {
  34. Service: api.SERVICE_TYPE,
  35. Resource: "image_quotas",
  36. Action: PolicyActionGet,
  37. Result: rbacutils.Allow,
  38. },
  39. {
  40. Service: api.SERVICE_TYPE,
  41. Resource: "image_quotas",
  42. Action: PolicyActionList,
  43. Result: rbacutils.Allow,
  44. },
  45. },
  46. },
  47. {
  48. // for anonymous update torrent status
  49. Auth: false,
  50. Scope: rbacscope.ScopeSystem,
  51. Rules: []rbacutils.SRbacRule{
  52. {
  53. Service: api.SERVICE_TYPE,
  54. Resource: "images",
  55. Action: PolicyActionPerform,
  56. Extra: []string{"update-torrent-status"},
  57. Result: rbacutils.Allow,
  58. },
  59. },
  60. },
  61. }
  62. )
  63. func Init() {
  64. if consts.IsEnableDefaultPolicy() {
  65. common_policy.AppendDefaultPolicies(predefinedDefaultPolicies)
  66. }
  67. }