policy.go 4.0 KB

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