policy.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package types
  2. type PermissionScope string
  3. const (
  4. UserScope PermissionScope = "user"
  5. ProjectScope PermissionScope = "project"
  6. ClusterScope PermissionScope = "cluster"
  7. RegistryScope PermissionScope = "registry"
  8. NamespaceScope PermissionScope = "namespace"
  9. SettingsScope PermissionScope = "settings"
  10. ReleaseScope PermissionScope = "release"
  11. )
  12. type NameOrUInt struct {
  13. Name string `json:"name"`
  14. UInt uint `json:"uint"`
  15. }
  16. type PolicyDocument struct {
  17. Scope PermissionScope `json:"scope"`
  18. Resources []NameOrUInt `json:"resources"`
  19. Verbs []APIVerb `json:"verbs"`
  20. Children map[PermissionScope]*PolicyDocument `json:"children"`
  21. }
  22. type ScopeTree map[PermissionScope]ScopeTree
  23. /* ScopeHeirarchy describes the tree of scopes, i.e. Cluster, Registry, and Settings
  24. are children of Project, Namespace is a child of Cluster, etc.
  25. */
  26. var ScopeHeirarchy = ScopeTree{
  27. ProjectScope: {
  28. ClusterScope: {
  29. NamespaceScope: {
  30. ReleaseScope: {},
  31. },
  32. },
  33. RegistryScope: {},
  34. SettingsScope: {},
  35. },
  36. }
  37. type Policy []*PolicyDocument
  38. var AdminPolicy = []*PolicyDocument{
  39. {
  40. Scope: ProjectScope,
  41. Verbs: ReadWriteVerbGroup(),
  42. },
  43. }
  44. var DeveloperPolicy = []*PolicyDocument{
  45. {
  46. Scope: ProjectScope,
  47. Verbs: ReadWriteVerbGroup(),
  48. Children: map[PermissionScope]*PolicyDocument{
  49. SettingsScope: {
  50. Scope: SettingsScope,
  51. Verbs: ReadVerbGroup(),
  52. },
  53. },
  54. },
  55. }
  56. var ViewerPolicy = []*PolicyDocument{
  57. {
  58. Scope: ProjectScope,
  59. Verbs: ReadVerbGroup(),
  60. Children: map[PermissionScope]*PolicyDocument{
  61. SettingsScope: {
  62. Scope: SettingsScope,
  63. Verbs: []APIVerb{},
  64. },
  65. },
  66. },
  67. }