-
Notifications
You must be signed in to change notification settings - Fork 4
/
account-organizational-metadata.yaml
404 lines (396 loc) · 24.4 KB
/
account-organizational-metadata.yaml
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
APIVersion: 1
label: "recipe:account-organizational-metadata"
data:
automations:
- name: add-namespace-organizational-metadata
description: "Triggered after a namespace is created to install a recipe"
signature: "MEQCICc2CsBT4xfpXt0Gu2XLksWJdWIHOxY16LIBqgfuXy7oAiAWA5WbmI+2QshAPshELMmt18ZZfzUbXjWRsQ+IpwvqSQ=="
trigger: Event
protected: true
mode: Post
events:
namespace:
- create
entitlements:
import:
- create
recipe:
- create
- retrieve-many
rendertemplate:
- create
importreference:
- create
hookpolicy:
- create
- retrieve-many
automation:
- create
- retrieve-many
networkaccesspolicy:
- create
- retrieve-many
externalnetwork:
- create
- retrieve-many
condition: |-
/* When a namespace is created at the root level */
function when(api, params) {
return { continue: params.eventPayload.entity.namespace === "/", payload: { namespace: params.eventPayload.entity } };
}
actions:
- |
/* Create 2 recipes and auto deploy namespace organization metadata */
function then(api, params, payload) {
var namespace = payload.namespace.name;
var recipeNamespaceOrganizationlMetadata = {
"name": "Namespace organization metadata",
"description": "Controls organizational metadata of your namespaces",
"label": "recipe:namespace-organizational-metadata",
"propagate": false,
"deploymentMode": "Unique",
"metadata": [
"@aporeto:author=aporeto"
],
"associatedTags": null,
"targetIdentities": [
"automation",
"hookpolicy"
],
"longDescription": "\nA metadata is a \"key=value\" pair, where value is the name of your namespace.\n\nThis workflow allows to define the keys of your organizational metadata that are used to represent\nyour namespace hiearchy.\n\nBy default, we suggest to consider the following keys:\n\n1. workspace\n2. platform\n3. app\n\nThese metadata will be propagated to your processing units, enforcers, external networks and can then be used\nin your policies rules.",
"template": "{{`\nAPIVersion: 1\nlabel: \"recipe:namespace-organizational-metadata\"\ndata:\n hookpolicies:\n - name: \"namespace-organizational-metadata-hook\"\n description: \"Triggers automation called namespace-organizational-metadata\"\n endpointType: Automation\n protected: true\n propagate: true\n subject:\n - - \"$identity=namespace\"\n selectors:\n - - \"$identity=automation\"\n - \"$name=namespace-organizational-metadata\"\n automations:\n - name: namespace-organizational-metadata\n description: \"Triggered by the hook called namespace-organizational-metadata-hook\"\n signature: \"MEUCIQCC+VY2MlOopMOACN0oErTH7/3bsZ/WBStPaxbu2ANSpgIgQWDqVsh17dsMssc87o1tP2WBAlLLVqfdhD53CqLh2/g=\"\n trigger: Webhook\n propagate: true\n protected: true\n parameters:\n keys:\n {{- range $index, $key := .Values.keys }}\n - {{ $key | quote }}\n {{- end }}\n app_level: {{ .Values.app_level | quote }}\n actions:\n - |\n function organizationalMetadataForNamespace(namespace, keys) {\n\n parents = namespace.namespace.split(\"/\");\n parents.shift()\n\n if (!parents || parents.length == 0) {\n return [];\n }\n\n // Root namespace case not handled in this workflow.\n if (parents[0] === \"\") {\n return [];\n }\n\n idx = parents.length - 1;\n if (idx >= keys.length) {\n return [];\n }\n\n k = keys[idx];\n if (k === \"\") {\n return [];\n }\n\n return [\"@org:\" + k + \"=\" + namespace.name];\n }\n /**\n * This function will be executed when the automation condition is met:\n * @param {object} api - api manipulator that allows CRUD operations.\n * @param {object} params - the parameters configured in the automation.\n * @param {object} payload - Payload returned by the condition.\n */\n function then(api, params) {\n\n var triggerPayload = JSON.parse(params.triggerPayload);\n var namespace = triggerPayload.input;\n\n if (triggerPayload.operation !== \"create\" || !namespace.name) {\n triggerPayload.output = triggerPayload.input;\n return {\n \"statusCode\": 200,\n \"body\": JSON.stringify(triggerPayload),\n }\n }\n\n namespace.organizationalMetadata = organizationalMetadataForNamespace(namespace, params.keys);\n\n // populates the output field of the remote processor model with our modifications\n triggerPayload.output = namespace;\n\n return {\n \"statusCode\": 200,\n \"body\": JSON.stringify(triggerPayload),\n }\n\n }\n - name: auto-deploy-discovery-mode\n description: \"Automatic deployment of discovery mode in app namespaces\"\n signature: \"MEUCIHS4SDy7tszF6cF5cxq1db3Se7p4v7/BGiLr+3uDvpviAiEAk7N9O37JliL8QKe0SY4+6tNok+sPkExmITSXgC0RDo4=\"\n trigger: Event\n events:\n namespace:\n - create\n entitlements:\n recipe:\n - retrieve-many\n rendertemplate:\n - create\n importreference:\n - create\n networkaccesspolicy:\n - create\n - retrieve-many\n externalnetwork:\n - create\n - retrieve-many\n propagate: true\n protected: true\n parameters:\n keys:\n {{- range $index, $key := .Values.keys }}\n - {{ $key | quote }}\n {{- end }}\n app_level: {{ .Values.app_level | quote }}\n condition: |-\n /* When creating a namespace that contains app */\n function when(api, params, payload) {\n var namespace = params.eventPayload.entity.namespace;\n\n appIndex = _.indexOf(params.keys, params.app_level)\n\n console.error(appIndex, params.app_level);\n\n if (appIndex < 1) {\n return { continue: false };\n }\n\n parents = namespace.split(\"/\");\n // remove root and account namespaces.\n parents.shift();\n parents.shift();\n\n return { continue: parents.length === appIndex, payload: { targetNamespace: params.eventPayload.entity.name } };\n }\n actions:\n - |\n /* Deploy the discovery mode recipe */\n function then(api, params, payload) {\n return aporeto.deployRecipeWithLabelFilter(api, payload.targetNamespace, 'label == \"recipe:design-mode\"', {\"propagate\": true});\n }\nidentities:\n - hookpolicy\n - automation\n`}}",
"steps": [
{
"name": "Structure",
"description": "Provides the sorted list of key that describes best your namespace hierarchy.",
"parameters": [
{
"key": "keys",
"name": "Keys",
"description": "Sorted list of keys",
"type": "StringSlice",
"defaultValue": [
"workspace",
"platform",
"app"
]
},
{
"key": "app_level",
"name": "App level",
"description": "Indicate the namespace keyword that contains your apps.",
"type": "String",
"defaultValue": "app"
}
]
}
]
}
var recipeCreateNewWorkspace = {
"name": "1) Prepare an enforcer deployment",
"description": "Define a namespace hierarchy where the enforcer will be deployed.",
"label": "recipe:create-workspace-platform-app",
"deploymentMode": "Unrestricted",
"metadata": [
"@aporeto:author=aporeto"
],
"associatedTags": [
"aporeto:recipe:placement=getting-started"
],
"targetIdentities": [
"namespaces"
],
"longDescription": "## Create a namespace hierarchy before registering your enforcers\n\n---\n\n### This wizard allows you to establish a repeatable structure to organize your workloads into apps\n* It creates a highly recommended fixed 3-tier Microsegmentation namespace hierarchy tree in your account namespace.\n> > /{account}/**{workspace}**/**{platform}**/**{app}**\n* All processing units (PU) will receive 3 tags corresponding to the 3 levels in the hierarchy you are about to create to aid in policy creation to simplify the consumption of the Microsegmentation solution.\n\n > > 1. @org:**workspace** =\n > > 1. @org:**platform** =\n > > 1. @org:**app** =\n\n* Hosts, Docker Hosts, and Container Clusters should each be in their own Platform groups.\n* Processing Units will appear in the user defined **\"app\"** tier after enforcers are registered.\n* **The default behavior for the app tiers will be to automatically enable Discovery Mode to allow all communication**\n* For K8s/OpenShift the app tier automatically corresponds the cluster namespace and requires no user input in this wizard\n\n---\n\n_**After running the wizard:**_\n\n> > - [ ] Note the namespace and provide it to the enforcer registration\n> > - [ ] Navigate to the Microsegmentation app tier namespace to visualize your application connectivity\n> > - [ ] Start the policy creation process\n\n---\n\n_**Re-run this wizard to:**_\n> > - [ ] Add to an existing namespace hierarchy\n> > > or\n> > - [ ] Create an entirely new namespace hierarchy\n\n\n#### For more information please refer to the documentation.",
"template": "{{`\nAPIVersion: 1\nlabel: recipe:create-workspace-platform-app\ndata:\n {{- $pattern := cat \"^\" .Aporeto.Namespace \"(/[a-zA-Z0-9-_]+){0,2}$\" | nospace }}\n {{- if (regexMatch $pattern .Values.existing_namespace) }}\n {{- $existing_ns := .Values.existing_namespace | trimPrefix .Aporeto.Namespace }}\n {{- $workspace := \"\" }}\n {{- $platform := \"\" }}\n {{- $app := \"\" }}\n namespaces:\n {{- if (regexMatch \"^(/[a-zA-Z0-9-_]+){0,1}(/)?$\" .Values.existing_namespace) }}\n {{- $workspace = required \"Workspace name is required\" .Values.workspace }}\n {{- if not (regexMatch \"^[a-zA-Z0-9-_]+$\" $workspace) }}\n {{- fail \"workspace name must only contain alpha numerical characters, '-' or '_'\"}}\n {{- end }}\n - name: {{ $workspace }}\n {{- end }}\n {{- if (regexMatch \"^(/[a-zA-Z0-9-_]+){0,2}(/)?$\" .Values.existing_namespace) }}\n {{- $platform = required \"Platform name is required\" .Values.platform }}\n {{- if not (regexMatch \"^[a-zA-Z0-9-_]+$\" $platform) }}\n {{- fail \"platform name must only contain alpha numerical characters, '-' or '_'\"}}\n {{- end }}\n - name: {{ $platform }}\n namespace: {{ regexReplaceAll \"\\\\s+\" (cat $existing_ns $workspace) \"/\" | trimSuffix \"/\"}}\n {{- end }}\n {{- if and (regexMatch \"^^(/[a-zA-Z0-9-_]+){0,3}(/)?$\" .Values.existing_namespace) (ne .Values.mode \"kubernetes\") }}\n {{- $app = required \"Application name is required\" .Values.app}}\n {{- if not (regexMatch \"^[a-zA-Z0-9-_]+$\" $app) }}\n {{- fail \"application name must only contain alpha numerical characters, '-' or '_'\"}}\n {{- end }}\n - name: {{ $app }}\n namespace: {{ regexReplaceAll \"\\\\s+\" (cat $existing_ns $workspace $platform) \"/\" | trimSuffix \"/\"}}\n {{- end }}\n {{- else }}\n {{- fail \"Invalid starting namespace pattern\" }}\n {{- end }}\n`}}",
"steps": [
{
"name": "Namespaces",
"parameters": [
{
"key": "existing_namespace",
"name": "Provide your account namespace or provide an existing namespace",
"description": "Leave the default (i.e. /{account} ) to create a new hierarchy or provide an existing namespace (e.g. /{account}/{workspace} ) to continue building on an existing hierarchy",
"type": "Namespace",
"defaultValue": namespace
},
{
"key": "starting_ns_warning",
"name": "Incorrect namespace",
"type": "WarningMessage",
"defaultValue": "The namespace provided is not valid",
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "NotMatch",
"value": "^[a-zA-Z0-9-_/]+$"
}
]
]
},
{
"key": "workspace",
"name": "Workspace name",
"description": "Examples are a Cloud Region (us-central-1), An Environment (dev, prod, test, pci), a business unit, or a combination",
"type": "String",
"optional": true,
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "Match",
"value": "^(/[a-zA-Z0-9-_]+){0,1}$"
}
]
]
},
{
"key": "mode",
"name": "Platform type",
"description": "Select the option that applies to your platform",
"type": "Enum",
"defaultValue": "hosts",
"allowedChoices": {
"hosts": "Hosts(Bare Metal, VMs)",
"docker": "Non-Orchestrated containers (Standalone Docker)",
"kubernetes": "Orchestrated containers (OpenShift, Kubernetes)"
},
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "Match",
"value": "^(/[a-zA-Z0-9-_]+){0,2}$"
}
]
]
},
{
"key": "platform",
"name": "Platform name",
"description": "Provide a name for your Kubernetes/Openshift Cluster, Host or DockerHost group name",
"type": "String",
"optional": true,
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "Match",
"value": "^(/[a-zA-Z0-9-_]+){0,2}$"
}
]
]
},
{
"key": "app",
"name": "Application name",
"description": "Provide a name for your app tier",
"type": "String",
"optional": true,
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "Match",
"value": "^(/[a-zA-Z0-9-_]+){0,3}$"
},
{
"key": "mode",
"operator": "NotEqual",
"value": "kubernetes"
}
]
]
},
{
"key": "kubernetes_warning",
"name": "Warning",
"type": "WarningMessage",
"defaultValue": "Selected namespace should be an account, workspace or platform level.",
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "Match",
"value": "^(/[a-zA-Z0-9-_]+){4,}$"
}
]
]
},
{
"key": "sucess_message_nok8s1",
"name": "Details",
"type": "InfoMessage",
"defaultValue": "Copy the following namespace for your enforcer deployment: **.Values.existing_namespace/.Values.workspace/.Values.platform/.Values.app**",
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "Match",
"value": "^(/[a-zA-Z0-9-_]+){1}$"
},
{
"key": "mode",
"operator": "NotEqual",
"value": "kubernetes"
},
{
"key": "app",
"operator": "Defined"
}
]
]
},
{
"key": "sucess_message_nok8s2",
"name": "Details",
"type": "InfoMessage",
"defaultValue": "Copy the following namespace for your enforcer deployment: **.Values.existing_namespace/.Values.platform/.Values.app**",
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "Match",
"value": "^(/[a-zA-Z0-9-_]+){2}$"
},
{
"key": "mode",
"operator": "NotEqual",
"value": "kubernetes"
},
{
"key": "app",
"operator": "Defined"
}
]
]
},
{
"key": "sucess_message_nok8s3",
"name": "Details",
"type": "InfoMessage",
"defaultValue": "Copy the following namespace for your enforcer deployment: **.Values.existing_namespace/.Values.app**",
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "Match",
"value": "^(/[a-zA-Z0-9-_]+){3}$"
},
{
"key": "mode",
"operator": "NotEqual",
"value": "kubernetes"
},
{
"key": "app",
"operator": "Defined"
}
]
]
},
{
"key": "sucess_message_k8s1",
"name": "Details",
"type": "InfoMessage",
"defaultValue": "Copy the following namespace for your enforcer deployment: **.Values.existing_namespace/.Values.workspace/.Values.platform**",
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "Match",
"value": "^(/[a-zA-Z0-9-_]+){1}$"
},
{
"key": "mode",
"operator": "Equal",
"value": "kubernetes"
},
{
"key": "platform",
"operator": "Defined"
}
]
]
},
{
"key": "sucess_message_k8s2",
"name": "Details",
"type": "InfoMessage",
"defaultValue": "Copy the following namespace for your enforcer deployment: **.Values.existing_namespace/.Values.platform**",
"visibilityCondition": [
[
{
"key": "existing_namespace",
"operator": "Match",
"value": "^(/[a-zA-Z0-9-_]+){2}$"
},
{
"key": "mode",
"operator": "Equal",
"value": "kubernetes"
},
{
"key": "platform",
"operator": "Defined"
}
]
]
},
{
"key": "msgcopy",
"name": "I have copied my namespace",
"description": "I have copied my namespace.",
"type": "Checkbox",
"default": false,
"validationFunction": "function validate(value) {\n if (value !== true) {\n throw \"Please confirm you have copied your namespace\";\n };\n}",
"visibilityCondition": [
[
{
"key": "mode",
"operator": "Equal",
"value": "kubernetes"
},
{
"key": "platform",
"operator": "Defined"
}
],
[
{
"key": "mode",
"operator": "NotEqual",
"value": "kubernetes"
},
{
"key": "app",
"operator": "Defined"
}
]
]
}
]
}
]
}
var content = {
data: {
"APIVersion": 1,
"label": "recipe:namespace-organizational-metadata",
"data": {
"recipes": [recipeNamespaceOrganizationlMetadata, recipeCreateNewWorkspace]
}
}
}
// Import recipes
api.Create('import', content, namespace);
parameters = {
"keys": ["workspace", "platform", "app"],
"app_level": "app"
}
// Automatic deployment of the recipe
return aporeto.deployRecipeWithLabelFilter(api, namespace, 'label == "recipe:namespace-organizational-metadata"', parameters);
}
identities:
- hookpolicy
- automation