policy.go 4.2 KB

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