policy.go 4.0 KB

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