policy.go 4.1 KB

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