forked from tkestack/tke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
412 lines (331 loc) · 14.3 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/*
* Tencent is pleased to support the open source community by making TKEStack
* available.
*
* Copyright (C) 2012-2019 Tencent. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://opensource.org/licenses/Apache-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// LocalIdentity is an object that contains the metadata about identify used to
// login to TKE.
type LocalIdentity struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Spec defines the desired identities of identity in this set.
// +optional
Spec LocalIdentitySpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
// +optional
Status LocalIdentityStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// LocalIdentityList is the whole list of all identities.
type LocalIdentityList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// List of identities.
Items []LocalIdentity `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// LocalIdentitySpec is a description of an identity.
type LocalIdentitySpec struct {
Username string `json:"username" protobuf:"bytes,7,opt,name=name"`
DisplayName string `json:"displayName" protobuf:"bytes,8,opt,name=displayName"`
Email string `json:"email" protobuf:"bytes,9,opt,name=email"`
PhoneNumber string `json:"phoneNumber" protobuf:"bytes,10,opt,name=phone"`
HashedPassword string `json:"hashedPassword,omitempty" protobuf:"bytes,4,opt,name=hashedPassword"`
OriginalPassword string `json:"originalPassword,omitempty" protobuf:"bytes,5,opt,name=originalPassword"`
// +optional
TenantID string `json:"tenantID,omitempty" protobuf:"bytes,2,opt,name=tenantID"`
Groups []string `json:"groups,omitempty" protobuf:"bytes,6,rep,name=groups"`
// +optional
Extra map[string]string `json:"extra,omitempty" protobuf:"bytes,3,rep,name=extra"`
}
// LocalIdentityStatus is a description of an identity status.
type LocalIdentityStatus struct {
// +optional
Locked bool `json:"locked,omitempty" protobuf:"varint,1,opt,name=locked"`
// The last time the local identity was updated.
// +optional
LastUpdateTime metav1.Time `protobuf:"bytes,2,opt,name=lastUpdateTime"`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// APIKey contains expiration time used to apply the api key.
type APIKey struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=objectMeta"`
// Spec defines the desired identities of APIkey in this set.
Spec APIKeySpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
Status APIKeyStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// LocalIdentityList is the whole list of all identities.
type APIKeyList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=listMeta"`
// List of api keys.
Items []APIKey `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// APIKeySpec is a description of an apiKey.
type APIKeySpec struct {
// APIkey is the jwt token used to authenticate user, and contains user info and sign.
APIkey string `json:"apiKey,omitempty" protobuf:"bytes,1,opt,name=apiKey"`
TenantID string `json:"tenantID,omitempty" protobuf:"bytes,5,opt,name=tenantID"`
// Username is creator
// +optional
Username string `json:"username,omitempty" protobuf:"bytes,6,opt,name=username"`
// Description describes api keys usage.
// +optional
Description string `json:"description" protobuf:"bytes,2,opt,name=description"`
// IssueAt is the created time for api key
IssueAt metav1.Time `json:"issue_at,omitempty" protobuf:"bytes,3,opt,name=issue_at,json=issueAt"`
// ExpireAt is the expire time for api key
ExpireAt metav1.Time `json:"expire_at,omitempty" protobuf:"bytes,4,opt,name=expire_at,json=expireAt"`
}
// APIKeyStatus is a description of an api key status.
type APIKeyStatus struct {
// Disabled represents whether the apikey has been disabled.
// +optional
Disabled bool `json:"disabled" protobuf:"varint,1,opt,name=disabled"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// APIKeyReq contains expiration time used to apply the api key.
type APIKeyReq struct {
metav1.TypeMeta `json:",inline"`
//Exipre is required, holds the duration of the api key become invalid. By default, 168h(= seven days)
// +optional
Expire metav1.Duration `json:"expire,omitempty" protobuf:"bytes,2,opt,name=expire"`
// Description describes api keys usage.
Description string `json:"description" protobuf:"bytes,3,opt,name=description"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// APIKeyReqPassword contains userinfo and expiration time used to apply the api key.
type APIKeyReqPassword struct {
metav1.TypeMeta `json:",inline"`
// TenantID for user
TenantID string `json:"tenantID,omitempty" protobuf:"bytes,2,opt,name=tenantID"`
// Username
Username string `json:"username,omitempty" protobuf:"bytes,3,opt,name=username"`
// Password (encoded by base64)
Password string `json:"password,omitempty" protobuf:"bytes,4,opt,name=password"`
// Description describes api keys usage.
// +optional
Description string `json:"description" protobuf:"bytes,5,opt,name=description"`
// Expire holds the duration of the api key become invalid. By default, 168h(= seven days)
// +optional
Expire metav1.Duration `json:"expire,omitempty" protobuf:"bytes,6,opt,name=expire"`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// APISigningKey hold encryption and signing key.
type APISigningKey struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// +optional
SigningKey []byte `json:"signingKey,omitempty" protobuf:"bytes,2,opt,name=signingKey"`
// +optional
SigningKeyPub []byte `json:"signingKeyPub,omitempty" protobuf:"bytes,3,opt,name=signingKeyPub"`
}
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// APISigningKeyList is the whole list of all signing key.
type APISigningKeyList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// List of keys.
Items []APISigningKey `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// ProjectPhase defines the phase of project constructor.
type PolicyPhase string
const (
// PolicyActive indicates the policy is active.
PolicyActive PolicyPhase = "Active"
// ProjectTerminating means the project is undergoing graceful termination.
PolicyTerminating PolicyPhase = "Terminating"
)
// FinalizerName is the name identifying a finalizer during project lifecycle.
type FinalizerName string
const (
// ProjectFinalize is an internal finalizer values to Project.
PolicyFinalize FinalizerName = "policy"
)
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Policy represents a policy document for access control.
type Policy struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Spec defines the desired identities of policy document in this set.
// +optional
Spec PolicySpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
// +optional
Status PolicyStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// PolicyList is the whole list of all policies.
type PolicyList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// List of policies.
Items []Policy `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// Effect defines the policy effect.
type Effect string
const (
// Allow is the allow type.
Allow Effect = "allow"
// Deny is the deny type.
Deny Effect = "deny"
)
// PolicySpec is a description of a policy.
type PolicySpec struct {
Finalizers []FinalizerName `json:"finalizers,omitempty" protobuf:"bytes,8,rep,name=finalizers,casttype=FinalizerName"`
TenantID string `json:"tenantID" protobuf:"bytes,1,opt,name=tenantID"`
DisplayName string `json:"displayName" protobuf:"bytes,7,opt,name=displayName"`
Username string `json:"username" protobuf:"bytes,2,opt,name=username"`
// +optional
Description string `json:"description" protobuf:"bytes,3,opt,name=description"`
// Subjects is the policy subjects.
// +optional
Subjects []string `json:"subjects,omitempty" protobuf:"bytes,4,rep,name=subjects"`
Statement Statement `json:"statement" protobuf:"bytes,5,rep,name=statement"`
// +optional
Conditions []byte `json:"conditions,omitempty" protobuf:"bytes,6,rep,name=conditions"`
}
// Statement defines a series of action on resource can be done or not.
type Statement struct {
Actions []string `json:"actions" protobuf:"bytes,1,rep,name=actions"`
Resources []string `json:"resources" protobuf:"bytes,2,rep,name=resources"`
// Effect indicates action on the resource is allowed or not, can be "allow" or "deny"
Effect Effect `json:"effect" protobuf:"bytes,3,opt,name=effect,casttype=Effect"`
}
// PolicyStatus represents information about the status of a policy.
type PolicyStatus struct {
// +optional
Phase PolicyPhase `json:"phase" protobuf:"bytes,1,opt,name=phase,casttype=PolicyPhase"`
// +optional
// Subjects represents the objects the policy applies to.
Subjects []Subject `json:"subjects" protobuf:"bytes,2,rep,name=subjects"`
}
const (
DefaultRuleModel = `
[request_definition]
r = sub, obj, act
[policy_definition]
p = sub, obj, act, eft
[role_definition]
g = _, _
[policy_effect]
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))
[matchers]
m = g(r.sub, p.sub) && keyMatchCustom(r.obj, p.obj) && keyMatchCustom(r.act, p.act)
`
)
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Rule represents a rule document for access control.
type Rule struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Spec defines the desired identities of policy document in this set.
Spec RuleSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
}
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// RuleList is the whole list of all policies.
type RuleList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// List of rules.
Items []Rule `json:"items" protobuf:"bytes,2,rep,name=items"`
}
// RuleSpec is a description of a policy.
type RuleSpec struct {
PType string `json:"ptype" protobuf:"bytes,1,opt,name=ptype"`
V0 string `json:"v0" protobuf:"bytes,2,opt,name=v0"`
V1 string `json:"v1" protobuf:"bytes,3,opt,name=v1"`
V2 string `json:"v2" protobuf:"bytes,4,opt,name=v2"`
V3 string `json:"v3" protobuf:"bytes,5,opt,name=v3"`
V4 string `json:"v4" protobuf:"bytes,6,opt,name=v4"`
V5 string `json:"v5" protobuf:"bytes,7,opt,name=v5"`
V6 string `json:"v6" protobuf:"bytes,8,opt,name=v6"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Binding references the objects a policy applies to, but does not contain it.
type Binding struct {
metav1.TypeMeta `json:",inline"`
// Subjects holds references to the objects the policy applies to.
// +optional
Subjects []Subject `json:"subject" protobuf:"bytes,1,rep,name=subject"`
}
// Subject references a user can specify by id or name.
type Subject struct {
ID string `json:"id" protobuf:"bytes,1,opt,name=id"`
Name string `json:"name" protobuf:"bytes,2,opt,name=name"`
}
// +genclient
// +genclient:nonNamespaced
// +genclient:skipVerbs=deleteCollection
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ConfigMap holds configuration data for tke to consume.
type ConfigMap struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Data contains the configuration data.
// Each key must consist of alphanumeric characters, '-', '_' or '.'.
// Values with non-UTF-8 byte sequences must use the BinaryData field.
// The keys stored in Data must not overlap with the keys in
// the BinaryData field, this is enforced during validation process.
// +optional
Data map[string]string `json:"data,omitempty" protobuf:"bytes,2,rep,name=data"`
// BinaryData contains the binary data.
// Each key must consist of alphanumeric characters, '-', '_' or '.'.
// BinaryData can contain byte sequences that are not in the UTF-8 range.
// The keys stored in BinaryData must not overlap with the ones in
// the Data field, this is enforced during validation process.
// +optional
BinaryData map[string][]byte `json:"binaryData,omitempty" protobuf:"bytes,3,rep,name=binaryData"`
}
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ConfigMapList is a resource containing a list of ConfigMap objects.
type ConfigMapList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
// Items is the list of ConfigMaps.
Items []ConfigMap `json:"items" protobuf:"bytes,2,rep,name=items"`
}