policy.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package types
  2. import "time"
  3. type PermissionScope string
  4. const (
  5. UserScope PermissionScope = "user"
  6. ProjectScope PermissionScope = "project"
  7. ClusterScope PermissionScope = "cluster"
  8. RegistryScope PermissionScope = "registry"
  9. InviteScope PermissionScope = "invite"
  10. HelmRepoScope PermissionScope = "helm_repo"
  11. InfraScope PermissionScope = "infra"
  12. OperationScope PermissionScope = "operation"
  13. GitInstallationScope PermissionScope = "git_installation"
  14. NamespaceScope PermissionScope = "namespace"
  15. SettingsScope PermissionScope = "settings"
  16. ReleaseScope PermissionScope = "release"
  17. )
  18. type NameOrUInt struct {
  19. Name string `json:"name"`
  20. UInt uint `json:"uint"`
  21. }
  22. type PolicyDocument struct {
  23. Scope PermissionScope `json:"scope"`
  24. Resources []NameOrUInt `json:"resources"`
  25. Verbs []APIVerb `json:"verbs"`
  26. Children map[PermissionScope]*PolicyDocument `json:"children"`
  27. }
  28. type ScopeTree map[PermissionScope]ScopeTree
  29. /* ScopeHeirarchy describes the tree of scopes, i.e. Cluster, Registry, and Settings
  30. are children of Project, Namespace is a child of Cluster, etc.
  31. */
  32. var ScopeHeirarchy = ScopeTree{
  33. ProjectScope: {
  34. ClusterScope: {
  35. NamespaceScope: {
  36. ReleaseScope: {},
  37. },
  38. },
  39. RegistryScope: {},
  40. HelmRepoScope: {},
  41. GitInstallationScope: {},
  42. InfraScope: {
  43. OperationScope: {},
  44. },
  45. SettingsScope: {},
  46. },
  47. }
  48. type Policy []*PolicyDocument
  49. var AdminPolicy = []*PolicyDocument{
  50. {
  51. Scope: ProjectScope,
  52. Verbs: ReadWriteVerbGroup(),
  53. Children: map[PermissionScope]*PolicyDocument{
  54. ClusterScope: {
  55. Scope: ClusterScope,
  56. Verbs: ReadWriteVerbGroup(),
  57. },
  58. RegistryScope: {
  59. Scope: RegistryScope,
  60. Verbs: ReadWriteVerbGroup(),
  61. },
  62. HelmRepoScope: {
  63. Scope: HelmRepoScope,
  64. Verbs: ReadWriteVerbGroup(),
  65. },
  66. GitInstallationScope: {
  67. Scope: GitInstallationScope,
  68. Verbs: ReadWriteVerbGroup(),
  69. },
  70. InfraScope: {
  71. Scope: InfraScope,
  72. Verbs: ReadWriteVerbGroup(),
  73. },
  74. SettingsScope: {
  75. Scope: SettingsScope,
  76. Verbs: ReadWriteVerbGroup(),
  77. },
  78. },
  79. },
  80. }
  81. var DeveloperPolicy = []*PolicyDocument{
  82. {
  83. Scope: ProjectScope,
  84. Verbs: ReadWriteVerbGroup(),
  85. Children: map[PermissionScope]*PolicyDocument{
  86. ClusterScope: {
  87. Scope: ClusterScope,
  88. Verbs: ReadWriteVerbGroup(),
  89. },
  90. RegistryScope: {
  91. Scope: RegistryScope,
  92. Verbs: ReadWriteVerbGroup(),
  93. },
  94. HelmRepoScope: {
  95. Scope: HelmRepoScope,
  96. Verbs: ReadWriteVerbGroup(),
  97. },
  98. GitInstallationScope: {
  99. Scope: GitInstallationScope,
  100. Verbs: ReadWriteVerbGroup(),
  101. },
  102. InfraScope: {
  103. Scope: InfraScope,
  104. Verbs: ReadWriteVerbGroup(),
  105. },
  106. SettingsScope: {
  107. Scope: SettingsScope,
  108. Verbs: ReadVerbGroup(),
  109. },
  110. },
  111. },
  112. }
  113. var ViewerPolicy = []*PolicyDocument{
  114. {
  115. Scope: ProjectScope,
  116. Verbs: ReadVerbGroup(),
  117. Children: map[PermissionScope]*PolicyDocument{
  118. ClusterScope: {
  119. Scope: ClusterScope,
  120. Verbs: ReadVerbGroup(),
  121. },
  122. RegistryScope: {
  123. Scope: RegistryScope,
  124. Verbs: ReadVerbGroup(),
  125. },
  126. HelmRepoScope: {
  127. Scope: HelmRepoScope,
  128. Verbs: ReadVerbGroup(),
  129. },
  130. GitInstallationScope: {
  131. Scope: GitInstallationScope,
  132. Verbs: ReadVerbGroup(),
  133. },
  134. InfraScope: {
  135. Scope: InfraScope,
  136. Verbs: ReadVerbGroup(),
  137. },
  138. SettingsScope: {
  139. Scope: SettingsScope,
  140. Verbs: []APIVerb{},
  141. },
  142. },
  143. },
  144. }
  145. type CreatePolicy struct {
  146. Name string `json:"name" form:"required"`
  147. Policy []*PolicyDocument `json:"policy" form:"required"`
  148. }
  149. const URLParamPolicyID URLParam = "policy_id"
  150. type APIPolicyMeta struct {
  151. CreatedAt time.Time `json:"created_at"`
  152. UpdatedAt time.Time `json:"updated_at"`
  153. ProjectID uint `json:"project_id"`
  154. UID string `json:"uid"`
  155. Name string `json:"name"`
  156. }
  157. type APIPolicy struct {
  158. *APIPolicyMeta
  159. Policy []*PolicyDocument `json:"policy"`
  160. }