policy.go 4.3 KB

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