policy.go 2.0 KB

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