policy.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. InviteScope PermissionScope = "invite"
  9. HelmRepoScope PermissionScope = "helm_repo"
  10. InfraScope PermissionScope = "infra"
  11. OperationScope PermissionScope = "operation"
  12. GitInstallationScope PermissionScope = "git_installation"
  13. NamespaceScope PermissionScope = "namespace"
  14. SettingsScope PermissionScope = "settings"
  15. ReleaseScope PermissionScope = "release"
  16. )
  17. type NameOrUInt struct {
  18. Name string `json:"name"`
  19. UInt uint `json:"uint"`
  20. }
  21. type PolicyDocument struct {
  22. Scope PermissionScope `json:"scope"`
  23. Resources []NameOrUInt `json:"resources"`
  24. Verbs []APIVerb `json:"verbs"`
  25. Children map[PermissionScope]*PolicyDocument `json:"children"`
  26. }
  27. type ScopeTree map[PermissionScope]ScopeTree
  28. /* ScopeHeirarchy describes the tree of scopes, i.e. Cluster, Registry, and Settings
  29. are children of Project, Namespace is a child of Cluster, etc.
  30. */
  31. var ScopeHeirarchy = ScopeTree{
  32. ProjectScope: {
  33. ClusterScope: {
  34. NamespaceScope: {
  35. ReleaseScope: {},
  36. },
  37. },
  38. RegistryScope: {},
  39. HelmRepoScope: {},
  40. GitInstallationScope: {},
  41. InfraScope: {
  42. OperationScope: {},
  43. },
  44. SettingsScope: {},
  45. },
  46. }
  47. type Policy []*PolicyDocument
  48. var AdminPolicy = []*PolicyDocument{
  49. {
  50. Scope: ProjectScope,
  51. Verbs: ReadWriteVerbGroup(),
  52. },
  53. }
  54. var DeveloperPolicy = []*PolicyDocument{
  55. {
  56. Scope: ProjectScope,
  57. Verbs: ReadWriteVerbGroup(),
  58. Children: map[PermissionScope]*PolicyDocument{
  59. SettingsScope: {
  60. Scope: SettingsScope,
  61. Verbs: ReadVerbGroup(),
  62. },
  63. },
  64. },
  65. }
  66. var ViewerPolicy = []*PolicyDocument{
  67. {
  68. Scope: ProjectScope,
  69. Verbs: ReadVerbGroup(),
  70. Children: map[PermissionScope]*PolicyDocument{
  71. SettingsScope: {
  72. Scope: SettingsScope,
  73. Verbs: []APIVerb{},
  74. },
  75. },
  76. },
  77. }