policy.go 4.6 KB

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