1
1
package policy
2
2
3
+ import "strings"
4
+
5
+ const WildcardSymbol = "*"
6
+
7
+ type actionFields uint32
8
+
3
9
// Action represents the allowed actions to be done on an object.
4
10
type Action string
5
11
@@ -8,4 +14,129 @@ const (
8
14
ActionRead Action = "read"
9
15
ActionUpdate Action = "update"
10
16
ActionDelete Action = "delete"
17
+
18
+ ActionUse Action = "use"
19
+ ActionSSH Action = "ssh"
20
+ ActionApplicationConnect = "application_connect"
11
21
)
22
+
23
+ const (
24
+ fieldOwner actionFields = 1 << iota
25
+ fieldOrg
26
+ fieldACL
27
+ )
28
+
29
+ type PermissionDefinition struct {
30
+ // name is optional. Used to override "Type" for function naming.
31
+ name string
32
+ // Type should be a unique string to identify the
33
+ Type string
34
+ // Actions are a map of actions to some description of what the action
35
+ // should represent. The key in the actions map is the verb to use
36
+ // in the rbac policy.
37
+ Actions map [Action ]ActionDefinition
38
+ }
39
+
40
+ func (p PermissionDefinition ) Name () string {
41
+ if p .name != "" {
42
+ return p .name
43
+ }
44
+ return p .Type
45
+ }
46
+
47
+ type ActionDefinition struct {
48
+ // Human friendly description to explain the action.
49
+ Description string
50
+
51
+ // These booleans enforce these fields are p
52
+ Fields actionFields
53
+ }
54
+
55
+ func actDef (fields actionFields , description string ) ActionDefinition {
56
+ return ActionDefinition {
57
+ Description : description ,
58
+ Fields : fields ,
59
+ }
60
+ }
61
+
62
+ func (a ActionDefinition ) Requires () string {
63
+ fields := make ([]string , 0 )
64
+ if a .Fields & fieldOwner != 0 {
65
+ fields = append (fields , "owner" )
66
+ }
67
+ if a .Fields & fieldOrg != 0 {
68
+ fields = append (fields , "org" )
69
+ }
70
+ if a .Fields & fieldACL != 0 {
71
+ fields = append (fields , "acl" )
72
+ }
73
+
74
+ return strings .Join (fields , "," )
75
+ }
76
+
77
+ var RBACPermissions = []PermissionDefinition {
78
+ {
79
+ name : "Wildcard" ,
80
+ Type : WildcardSymbol ,
81
+ Actions : map [Action ]ActionDefinition {
82
+ WildcardSymbol : {
83
+ Description : "Wildcard gives admin level access to all resources and all actions." ,
84
+ Fields : 0 ,
85
+ },
86
+ },
87
+ },
88
+ {
89
+ Type : "workspace" ,
90
+ Actions : map [Action ]ActionDefinition {
91
+ ActionCreate : actDef (fieldOwner | fieldOrg , "create a workspace" ),
92
+ ActionRead : actDef (fieldOwner | fieldOrg | fieldACL , "read workspace data" ),
93
+ // TODO: Make updates more granular
94
+ ActionUpdate : actDef (fieldOwner | fieldOrg | fieldACL , "update a workspace" ),
95
+ ActionDelete : actDef (fieldOwner | fieldOrg | fieldACL , "delete a workspace" ),
96
+ ActionSSH : actDef (fieldOwner | fieldOrg | fieldACL , "ssh into a given workspace" ),
97
+ ActionApplicationConnect : actDef (fieldOwner | fieldOrg | fieldACL , "connect to workspace apps via browser" ),
98
+ },
99
+ },
100
+ {
101
+ Type : "workspace_proxy" ,
102
+ Actions : map [Action ]ActionDefinition {
103
+ ActionCreate : actDef (0 , "create a workspace proxy" ),
104
+ ActionDelete : actDef (0 , "delete a workspace proxy" ),
105
+ ActionUpdate : actDef (0 , "update a workspace proxy" ),
106
+ ActionRead : actDef (0 , "read and use a workspace proxy" ),
107
+ },
108
+ },
109
+ {
110
+ Type : "license" ,
111
+ Actions : map [Action ]ActionDefinition {
112
+ ActionCreate : actDef (0 , "create a license" ),
113
+ ActionRead : actDef (0 , "read licenses" ),
114
+ ActionDelete : actDef (0 , "delete license" ),
115
+ // Licenses are immutable, so update makes no sense
116
+ },
117
+ },
118
+ {
119
+ Type : "audit_log" ,
120
+ Actions : map [Action ]ActionDefinition {
121
+ ActionRead : actDef (0 , "read audit logs" ),
122
+ },
123
+ },
124
+ {
125
+ Type : "deployment_config" ,
126
+ Actions : map [Action ]ActionDefinition {
127
+ ActionRead : actDef (0 , "read deployment config" ),
128
+ },
129
+ },
130
+ {
131
+ Type : "deployment_stats" ,
132
+ Actions : map [Action ]ActionDefinition {
133
+ ActionRead : actDef (0 , "read deployment stats" ),
134
+ },
135
+ },
136
+ {
137
+ Type : "replicas" ,
138
+ Actions : map [Action ]ActionDefinition {
139
+ ActionRead : actDef (0 , "read replicas" ),
140
+ },
141
+ },
142
+ }
0 commit comments