policy.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package types
  2. type PermissionScope string
  3. const (
  4. UserScope PermissionScope = "user"
  5. ProjectScope PermissionScope = "project"
  6. ClusterScope PermissionScope = "cluster"
  7. NamespaceScope PermissionScope = "namespace"
  8. SettingsScope PermissionScope = "settings"
  9. ApplicationScope PermissionScope = "application"
  10. )
  11. type NameOrUInt struct {
  12. Name string `json:"name"`
  13. UInt uint `json:"uint"`
  14. }
  15. type PolicyDocument struct {
  16. Scope PermissionScope `json:"scope"`
  17. Resources []NameOrUInt `json:"resources"`
  18. Verbs []APIVerb `json:"verbs"`
  19. Children map[PermissionScope]*PolicyDocument `json:"children"`
  20. }
  21. type ScopeTree map[PermissionScope]ScopeTree
  22. /* ScopeHeirarchy describes the scope tree:
  23. Project
  24. / \
  25. Cluster Settings
  26. /
  27. Namespace
  28. |
  29. Release
  30. */
  31. var ScopeHeirarchy = ScopeTree{
  32. ProjectScope: {
  33. ClusterScope: {
  34. NamespaceScope: {
  35. ApplicationScope: {},
  36. },
  37. },
  38. SettingsScope: {},
  39. },
  40. }
  41. type Policy []*PolicyDocument
  42. var AdminPolicy = []*PolicyDocument{
  43. {
  44. Scope: ProjectScope,
  45. Verbs: ReadWriteVerbGroup(),
  46. },
  47. }
  48. var DeveloperPolicy = []*PolicyDocument{
  49. {
  50. Scope: ProjectScope,
  51. Verbs: ReadWriteVerbGroup(),
  52. Children: map[PermissionScope]*PolicyDocument{
  53. SettingsScope: {
  54. Scope: SettingsScope,
  55. Verbs: ReadVerbGroup(),
  56. },
  57. },
  58. },
  59. }
  60. var ViewerPolicy = []*PolicyDocument{
  61. {
  62. Scope: ProjectScope,
  63. Verbs: ReadVerbGroup(),
  64. Children: map[PermissionScope]*PolicyDocument{
  65. SettingsScope: {
  66. Scope: SettingsScope,
  67. Verbs: []APIVerb{},
  68. },
  69. },
  70. },
  71. }