policy.go 1.7 KB

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