policy.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. StackScope PermissionScope = "stack"
  18. GitlabIntegrationScope PermissionScope = "gitlab_integration"
  19. PreviewEnvironmentScope PermissionScope = "preview_environment"
  20. EnvironmentScope PermissionScope = "environment"
  21. )
  22. type NameOrUInt struct {
  23. Name string `json:"name"`
  24. UInt uint `json:"uint"`
  25. }
  26. type PolicyDocument struct {
  27. Scope PermissionScope `json:"scope"`
  28. Resources []NameOrUInt `json:"resources"`
  29. Verbs []APIVerb `json:"verbs"`
  30. Children map[PermissionScope]*PolicyDocument `json:"children"`
  31. }
  32. type ScopeTree map[PermissionScope]ScopeTree
  33. /* ScopeHeirarchy describes the tree of scopes, i.e. Cluster, Registry, and Settings
  34. are children of Project, Namespace is a child of Cluster, etc.
  35. */
  36. var ScopeHeirarchy = ScopeTree{
  37. ProjectScope: {
  38. ClusterScope: {
  39. NamespaceScope: {
  40. StackScope: {},
  41. ReleaseScope: {},
  42. },
  43. },
  44. RegistryScope: {},
  45. HelmRepoScope: {},
  46. GitInstallationScope: {},
  47. InfraScope: {
  48. OperationScope: {},
  49. },
  50. SettingsScope: {
  51. InviteScope: {},
  52. },
  53. PreviewEnvironmentScope: {
  54. EnvironmentScope: {},
  55. },
  56. GitlabIntegrationScope: {},
  57. },
  58. }
  59. type Policy []*PolicyDocument
  60. var AdminPolicy = []*PolicyDocument{
  61. {
  62. Scope: ProjectScope,
  63. Verbs: ReadWriteVerbGroup(),
  64. Children: map[PermissionScope]*PolicyDocument{
  65. ClusterScope: {
  66. Scope: ClusterScope,
  67. Verbs: ReadWriteVerbGroup(),
  68. },
  69. RegistryScope: {
  70. Scope: RegistryScope,
  71. Verbs: ReadWriteVerbGroup(),
  72. },
  73. HelmRepoScope: {
  74. Scope: HelmRepoScope,
  75. Verbs: ReadWriteVerbGroup(),
  76. },
  77. GitInstallationScope: {
  78. Scope: GitInstallationScope,
  79. Verbs: ReadWriteVerbGroup(),
  80. },
  81. InfraScope: {
  82. Scope: InfraScope,
  83. Verbs: ReadWriteVerbGroup(),
  84. },
  85. SettingsScope: {
  86. Scope: SettingsScope,
  87. Verbs: ReadWriteVerbGroup(),
  88. },
  89. },
  90. },
  91. }
  92. var DeveloperPolicy = []*PolicyDocument{
  93. {
  94. Scope: ProjectScope,
  95. Verbs: ReadWriteVerbGroup(),
  96. Children: map[PermissionScope]*PolicyDocument{
  97. ClusterScope: {
  98. Scope: ClusterScope,
  99. Verbs: ReadWriteVerbGroup(),
  100. },
  101. RegistryScope: {
  102. Scope: RegistryScope,
  103. Verbs: ReadWriteVerbGroup(),
  104. },
  105. HelmRepoScope: {
  106. Scope: HelmRepoScope,
  107. Verbs: ReadWriteVerbGroup(),
  108. },
  109. GitInstallationScope: {
  110. Scope: GitInstallationScope,
  111. Verbs: ReadWriteVerbGroup(),
  112. },
  113. InfraScope: {
  114. Scope: InfraScope,
  115. Verbs: ReadWriteVerbGroup(),
  116. },
  117. SettingsScope: {
  118. Scope: SettingsScope,
  119. Verbs: ReadVerbGroup(),
  120. },
  121. },
  122. },
  123. }
  124. var ViewerPolicy = []*PolicyDocument{
  125. {
  126. Scope: ProjectScope,
  127. Verbs: ReadVerbGroup(),
  128. Children: map[PermissionScope]*PolicyDocument{
  129. ClusterScope: {
  130. Scope: ClusterScope,
  131. Verbs: ReadVerbGroup(),
  132. },
  133. RegistryScope: {
  134. Scope: RegistryScope,
  135. Verbs: ReadVerbGroup(),
  136. },
  137. HelmRepoScope: {
  138. Scope: HelmRepoScope,
  139. Verbs: ReadVerbGroup(),
  140. },
  141. GitInstallationScope: {
  142. Scope: GitInstallationScope,
  143. Verbs: ReadVerbGroup(),
  144. },
  145. InfraScope: {
  146. Scope: InfraScope,
  147. Verbs: ReadVerbGroup(),
  148. },
  149. SettingsScope: {
  150. Scope: SettingsScope,
  151. Verbs: []APIVerb{},
  152. },
  153. },
  154. },
  155. }
  156. type CreatePolicyRequest struct {
  157. Name string `json:"name" form:"required"`
  158. Policy []*PolicyDocument `json:"policy" form:"required"`
  159. }
  160. type UpdatePolicyRequest struct {
  161. Policy []*PolicyDocument `json:"policy" form:"required"`
  162. }
  163. const URLParamPolicyID URLParam = "policy_id"
  164. type APIPolicyMeta struct {
  165. CreatedAt time.Time `json:"created_at"`
  166. UpdatedAt time.Time `json:"updated_at"`
  167. ProjectID uint `json:"project_id"`
  168. UID string `json:"uid"`
  169. Name string `json:"name"`
  170. }
  171. type APIPolicy struct {
  172. *APIPolicyMeta
  173. Policy []*PolicyDocument `json:"policy"`
  174. }