forked from microsoft/regorus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframework.rego
1831 lines (1483 loc) · 53.1 KB
/
framework.rego
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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
package framework
import future.keywords.every
import future.keywords.in
version := "0.3.0"
device_mounted(target) {
data.metadata.devices[target]
}
default deviceHash_ok := false
# test if a device hash exists as a layer in a policy container
deviceHash_ok {
layer := data.policy.containers[_].layers[_]
input.deviceHash == layer
}
# test if a device hash exists as a layer in a fragment container
deviceHash_ok {
feed := data.metadata.issuers[_].feeds[_]
some fragment in feed
layer := fragment.containers[_].layers[_]
input.deviceHash == layer
}
default mount_device := {"allowed": false}
mount_device := {"metadata": [addDevice], "allowed": true} {
not device_mounted(input.target)
deviceHash_ok
addDevice := {
"name": "devices",
"action": "add",
"key": input.target,
"value": input.deviceHash,
}
}
default unmount_device := {"allowed": false}
unmount_device := {"metadata": [removeDevice], "allowed": true} {
device_mounted(input.unmountTarget)
removeDevice := {
"name": "devices",
"action": "remove",
"key": input.unmountTarget,
}
}
layerPaths_ok(layers) {
length := count(layers)
count(input.layerPaths) == length
every i, path in input.layerPaths {
layers[(length - i) - 1] == data.metadata.devices[path]
}
}
default overlay_exists := false
overlay_exists {
data.metadata.matches[input.containerID]
}
overlay_mounted(target) {
data.metadata.overlayTargets[target]
}
default candidate_containers := []
candidate_containers := containers {
semver.compare(policy_framework_version, version) == 0
policy_containers := [c | c := data.policy.containers[_]]
fragment_containers := [c |
feed := data.metadata.issuers[_].feeds[_]
fragment := feed[_]
c := fragment.containers[_]
]
containers := array.concat(policy_containers, fragment_containers)
}
candidate_containers := containers {
semver.compare(policy_framework_version, version) < 0
policy_containers := apply_defaults("container", data.policy.containers, policy_framework_version)
fragment_containers := [c |
feed := data.metadata.issuers[_].feeds[_]
fragment := feed[_]
c := fragment.containers[_]
]
containers := array.concat(policy_containers, fragment_containers)
}
default mount_overlay := {"allowed": false}
mount_overlay := {"metadata": [addMatches, addOverlayTarget], "allowed": true} {
not overlay_exists
containers := [container |
container := candidate_containers[_]
layerPaths_ok(container.layers)
]
count(containers) > 0
addMatches := {
"name": "matches",
"action": "add",
"key": input.containerID,
"value": containers,
}
addOverlayTarget := {
"name": "overlayTargets",
"action": "add",
"key": input.target,
"value": true,
}
}
default unmount_overlay := {"allowed": false}
unmount_overlay := {"metadata": [removeOverlayTarget], "allowed": true} {
overlay_mounted(input.unmountTarget)
removeOverlayTarget := {
"name": "overlayTargets",
"action": "remove",
"key": input.unmountTarget,
}
}
command_ok(command) {
count(input.argList) == count(command)
every i, arg in input.argList {
command[i] == arg
}
}
env_ok(pattern, "string", value) {
pattern == value
}
env_ok(pattern, "re2", value) {
regex.match(pattern, value)
}
rule_ok(rule, env) {
not rule.required
}
rule_ok(rule, env) {
rule.required
env_ok(rule.pattern, rule.strategy, env)
}
envList_ok(env_rules, envList) {
every rule in env_rules {
some env in envList
rule_ok(rule, env)
}
every env in envList {
some rule in env_rules
env_ok(rule.pattern, rule.strategy, env)
}
}
valid_envs_subset(env_rules) := envs {
envs := {env |
some env in input.envList
some rule in env_rules
env_ok(rule.pattern, rule.strategy, env)
}
}
valid_envs_for_all(items) := envs {
allow_environment_variable_dropping
# for each item, find a subset of the environment rules
# that are valid
valid := [envs |
some item in items
envs := valid_envs_subset(item.env_rules)
]
# we want to select the most specific matches, which in this
# case consists of those matches which require dropping the
# fewest environment variables (i.e. the longest lists)
counts := [num_envs |
envs := valid[_]
num_envs := count(envs)
]
max_count := max(counts)
largest_env_sets := {envs |
some i
counts[i] == max_count
envs := valid[i]
}
# if there is more than one set with the same size, we
# can only proceed if they are all the same, so we verify
# that the intersection is equal to the union. For a single
# set this is trivially true.
envs_i := intersection(largest_env_sets)
envs_u := union(largest_env_sets)
envs_i == envs_u
envs := envs_i
}
valid_envs_for_all(items) := envs {
not allow_environment_variable_dropping
# no dropping allowed, so we just return the input
envs := input.envList
}
workingDirectory_ok(working_dir) {
input.workingDir == working_dir
}
privileged_ok(elevation_allowed) {
not input.privileged
}
privileged_ok(elevation_allowed) {
input.privileged
input.privileged == elevation_allowed
}
noNewPrivileges_ok(no_new_privileges) {
no_new_privileges
input.noNewPrivileges
}
noNewPrivileges_ok(no_new_privileges) {
no_new_privileges == false
}
idName_ok(pattern, "any", value) {
true
}
idName_ok(pattern, "id", value) {
pattern == value.id
}
idName_ok(pattern, "name", value) {
pattern == value.name
}
idName_ok(pattern, "re2", value) {
regex.match(pattern, value.name)
}
user_ok(user) {
user.umask == input.umask
idName_ok(user.user_idname.pattern, user.user_idname.strategy, input.user)
every group in input.groups {
some group_idname in user.group_idnames
idName_ok(group_idname.pattern, group_idname.strategy, group)
}
}
seccomp_ok(seccomp_profile_sha256) {
input.seccompProfileSHA256 == seccomp_profile_sha256
}
default container_started := false
container_started {
data.metadata.started[input.containerID]
}
default container_privileged := false
container_privileged {
data.metadata.started[input.containerID].privileged
}
capsList_ok(allowed_caps_list, requested_caps_list) {
count(allowed_caps_list) == count(requested_caps_list)
every cap in requested_caps_list {
some allowed in allowed_caps_list
cap == allowed
}
every allowed in allowed_caps_list {
some cap in requested_caps_list
allowed == cap
}
}
filter_capsList_by_allowed(allowed_caps_list, requested_caps_list) := caps {
# find a subset of the capabilities that are valid
caps := {cap |
some cap in requested_caps_list
some allowed in allowed_caps_list
cap == allowed
}
}
filter_capsList_for_single_container(allowed_caps) := caps {
bounding := filter_capsList_by_allowed(allowed_caps.bounding, input.capabilities.bounding)
effective := filter_capsList_by_allowed(allowed_caps.effective, input.capabilities.effective)
inheritable := filter_capsList_by_allowed(allowed_caps.inheritable, input.capabilities.inheritable)
permitted := filter_capsList_by_allowed(allowed_caps.permitted, input.capabilities.permitted)
ambient := filter_capsList_by_allowed(allowed_caps.ambient, input.capabilities.ambient)
caps := {
"bounding": bounding,
"effective": effective,
"inheritable": inheritable,
"permitted": permitted,
"ambient": ambient
}
}
largest_caps_sets_for_all(containers, privileged) := largest_caps_sets {
filtered := [caps |
container := containers[_]
capabilities := get_capabilities(container, privileged)
caps := filter_capsList_for_single_container(capabilities)
]
# we want to select the most specific matches, which in this
# case consists of those matches which require dropping the
# fewest capabilities (i.e. the longest lists)
counts := [num_caps |
caps := filtered[_]
num_caps := count(caps.bounding) + count(caps.effective) +
count(caps.inheritable) + count(caps.permitted) +
count(caps.ambient)
]
max_count := max(counts)
largest_caps_sets := [caps |
some i
counts[i] == max_count
caps := filtered[i]
]
}
all_caps_sets_are_equal(sets) := caps {
# if there is more than one set with the same size, we
# can only proceed if they are all the same, so we verify
# that the intersection is equal to the union. For a single
# set this is trivially true.
bounding_i := intersection({caps.bounding | caps := sets[_]})
effective_i := intersection({caps.effective | caps := sets[_]})
inheritable_i := intersection({caps.inheritable | caps := sets[_]})
permitted_i := intersection({caps.permitted | caps := sets[_]})
ambient_i := intersection({caps.ambient | caps := sets[_]})
bounding_u := union({caps.bounding | caps := sets[_]})
effective_u := union({caps.effective | caps := sets[_]})
inheritable_u := union({caps.inheritable | caps := sets[_]})
permitted_u := union({caps.permitted | caps := sets[_]})
ambient_u := union({caps.ambient | caps := sets[_]})
bounding_i == bounding_u
effective_i == effective_u
inheritable_i == inheritable_u
permitted_i == permitted_u
ambient_i == ambient_u
caps := {
"bounding": bounding_i,
"effective": effective_i,
"inheritable": inheritable_i,
"permitted": permitted_i,
"ambient": ambient_i,
}
}
valid_caps_for_all(containers, privileged) := caps {
allow_capability_dropping
# find largest matching capabilities sets aka "the most specific"
largest_caps_sets := largest_caps_sets_for_all(containers, privileged)
# if there is more than one set with the same size, we
# can only proceed if they are all the same
caps := all_caps_sets_are_equal(largest_caps_sets)
}
valid_caps_for_all(containers, privileged) := caps {
not allow_capability_dropping
# no dropping allowed, so we just return the input
caps := input.capabilities
}
caps_ok(allowed_caps, requested_caps) {
capsList_ok(allowed_caps.bounding, requested_caps.bounding)
capsList_ok(allowed_caps.effective, requested_caps.effective)
capsList_ok(allowed_caps.inheritable, requested_caps.inheritable)
capsList_ok(allowed_caps.permitted, requested_caps.permitted)
capsList_ok(allowed_caps.ambient, requested_caps.ambient)
}
get_capabilities(container, privileged) := capabilities {
container.capabilities != null
capabilities := container.capabilities
}
default_privileged_capabilities := capabilities {
caps := {cap | cap := data.defaultPrivilegedCapabilities[_]}
capabilities := {
"bounding": caps,
"effective": caps,
"inheritable": caps,
"permitted": caps,
"ambient": set(),
}
}
get_capabilities(container, true) := capabilities {
container.capabilities == null
container.allow_elevated
capabilities := default_privileged_capabilities
}
default_unprivileged_capabilities := capabilities {
caps := {cap | cap := data.defaultUnprivilegedCapabilities[_]}
capabilities := {
"bounding": caps,
"effective": caps,
"inheritable": set(),
"permitted": caps,
"ambient": set(),
}
}
get_capabilities(container, false) := capabilities {
container.capabilities == null
container.allow_elevated
capabilities := default_unprivileged_capabilities
}
get_capabilities(container, privileged) := capabilities {
container.capabilities == null
not container.allow_elevated
capabilities := default_unprivileged_capabilities
}
default create_container := {"allowed": false}
create_container := {"metadata": [updateMatches, addStarted],
"env_list": env_list,
"caps_list": caps_list,
"allow_stdio_access": allow_stdio_access,
"allowed": true} {
not container_started
# narrow the matches based upon command, working directory, and
# mount list
possible_after_initial_containers := [container |
container := data.metadata.matches[input.containerID][_]
# NB any change to these narrowing conditions should be reflected in
# the error handling, such that error messaging correctly reflects
# the narrowing process.
noNewPrivileges_ok(container.no_new_privileges)
user_ok(container.user)
privileged_ok(container.allow_elevated)
workingDirectory_ok(container.working_dir)
command_ok(container.command)
mountList_ok(container.mounts, container.allow_elevated)
seccomp_ok(container.seccomp_profile_sha256)
]
count(possible_after_initial_containers) > 0
# check to see if the environment variables match, dropping
# them if allowed (and necessary)
env_list := valid_envs_for_all(possible_after_initial_containers)
possible_after_env_containers := [container |
container := possible_after_initial_containers[_]
envList_ok(container.env_rules, env_list)
]
count(possible_after_env_containers) > 0
# check to see if the capabilities variables match, dropping
# them if allowed (and necessary)
caps_list := valid_caps_for_all(possible_after_env_containers, input.privileged)
possible_after_caps_containers := [container |
container := possible_after_env_containers[_]
caps_ok(get_capabilities(container, input.privileged), caps_list)
]
count(possible_after_caps_containers) > 0
# set final container list
containers := possible_after_caps_containers
# we can't do narrowing based on allowing stdio access so at this point
# every container from the policy that might match this create request
# must have the same allow stdio value otherwise, we are in an undecidable
# state
allow_stdio_access := containers[0].allow_stdio_access
every c in containers {
c.allow_stdio_access == allow_stdio_access
}
updateMatches := {
"name": "matches",
"action": "update",
"key": input.containerID,
"value": containers,
}
addStarted := {
"name": "started",
"action": "add",
"key": input.containerID,
"value": {
"privileged": input.privileged,
},
}
}
mountSource_ok(constraint, source) {
startswith(constraint, data.sandboxPrefix)
newConstraint := replace(constraint, data.sandboxPrefix, input.sandboxDir)
regex.match(newConstraint, source)
}
mountSource_ok(constraint, source) {
startswith(constraint, data.hugePagesPrefix)
newConstraint := replace(constraint, data.hugePagesPrefix, input.hugePagesDir)
regex.match(newConstraint, source)
}
mountSource_ok(constraint, source) {
startswith(constraint, data.plan9Prefix)
some target, containerID in data.metadata.p9mounts
source == target
input.containerID == containerID
}
mountSource_ok(constraint, source) {
constraint == source
}
mountConstraint_ok(constraint, mount) {
mount.type == constraint.type
mountSource_ok(constraint.source, mount.source)
mount.destination != ""
mount.destination == constraint.destination
# the following check is not required (as the following tests will prove this
# condition as well), however it will check whether those more expensive
# tests need to be performed.
count(mount.options) == count(constraint.options)
every option in mount.options {
some constraintOption in constraint.options
option == constraintOption
}
every option in constraint.options {
some mountOption in mount.options
option == mountOption
}
}
mount_ok(mounts, allow_elevated, mount) {
some constraint in mounts
mountConstraint_ok(constraint, mount)
}
mount_ok(mounts, allow_elevated, mount) {
some constraint in data.defaultMounts
mountConstraint_ok(constraint, mount)
}
mount_ok(mounts, allow_elevated, mount) {
allow_elevated
some constraint in data.privilegedMounts
mountConstraint_ok(constraint, mount)
}
mountList_ok(mounts, allow_elevated) {
every mount in input.mounts {
mount_ok(mounts, allow_elevated, mount)
}
}
default exec_in_container := {"allowed": false}
exec_in_container := {"metadata": [updateMatches],
"env_list": env_list,
"caps_list": caps_list,
"allowed": true} {
container_started
# narrow our matches based upon the process requested
possible_after_initial_containers := [container |
container := data.metadata.matches[input.containerID][_]
# NB any change to these narrowing conditions should be reflected in
# the error handling, such that error messaging correctly reflects
# the narrowing process.
workingDirectory_ok(container.working_dir)
noNewPrivileges_ok(container.no_new_privileges)
user_ok(container.user)
some process in container.exec_processes
command_ok(process.command)
]
count(possible_after_initial_containers) > 0
# check to see if the environment variables match, dropping
# them if allowed (and necessary)
env_list := valid_envs_for_all(possible_after_initial_containers)
possible_after_env_containers := [container |
container := possible_after_initial_containers[_]
envList_ok(container.env_rules, env_list)
]
count(possible_after_env_containers) > 0
# check to see if the capabilities variables match, dropping
# them if allowed (and necessary)
caps_list := valid_caps_for_all(possible_after_env_containers, container_privileged)
possible_after_caps_containers := [container |
container := possible_after_env_containers[_]
caps_ok(get_capabilities(container, container_privileged), caps_list)
]
count(possible_after_caps_containers) > 0
# set final container list
containers := possible_after_caps_containers
updateMatches := {
"name": "matches",
"action": "update",
"key": input.containerID,
"value": containers,
}
}
default shutdown_container := {"allowed": false}
shutdown_container := {"metadata": [remove], "allowed": true} {
container_started
remove := {
"name": "matches",
"action": "remove",
"key": input.containerID,
}
}
default signal_container_process := {"allowed": false}
signal_container_process := {"metadata": [updateMatches], "allowed": true} {
container_started
input.isInitProcess
containers := [container |
container := data.metadata.matches[input.containerID][_]
signal_ok(container.signals)
]
count(containers) > 0
updateMatches := {
"name": "matches",
"action": "update",
"key": input.containerID,
"value": containers,
}
}
signal_container_process := {"metadata": [updateMatches], "allowed": true} {
container_started
not input.isInitProcess
containers := [container |
container := data.metadata.matches[input.containerID][_]
some process in container.exec_processes
command_ok(process.command)
signal_ok(process.signals)
]
count(containers) > 0
updateMatches := {
"name": "matches",
"action": "update",
"key": input.containerID,
"value": containers,
}
}
signal_ok(signals) {
some signal in signals
input.signal == signal
}
plan9_mounted(target) {
data.metadata.p9mounts[target]
}
default plan9_mount := {"allowed": false}
plan9_mount := {"metadata": [addPlan9Target], "allowed": true} {
not plan9_mounted(input.target)
some containerID, _ in data.metadata.matches
pattern := concat("", [input.rootPrefix, "/", containerID, input.mountPathPrefix])
regex.match(pattern, input.target)
addPlan9Target := {
"name": "p9mounts",
"action": "add",
"key": input.target,
"value": containerID,
}
}
default plan9_unmount := {"allowed": false}
plan9_unmount := {"metadata": [removePlan9Target], "allowed": true} {
plan9_mounted(input.unmountTarget)
removePlan9Target := {
"name": "p9mounts",
"action": "remove",
"key": input.unmountTarget,
}
}
default enforcement_point_info := {"available": false, "default_results": {"allow": false}, "unknown": true, "invalid": false, "version_missing": false}
enforcement_point_info := {"available": false, "default_results": {"allow": false}, "unknown": false, "invalid": false, "version_missing": true} {
policy_api_version == null
}
enforcement_point_info := {"available": available, "default_results": default_results, "unknown": false, "invalid": false, "version_missing": false} {
enforcement_point := data.api.enforcement_points[input.name]
semver.compare(data.api.version, enforcement_point.introducedVersion) >= 0
available := semver.compare(policy_api_version, enforcement_point.introducedVersion) >= 0
default_results := enforcement_point.default_results
}
enforcement_point_info := {"available": false, "default_results": {"allow": false}, "unknown": false, "invalid": true, "version_missing": false} {
enforcement_point := data.api.enforcement_points[input.name]
semver.compare(data.api.version, enforcement_point.introducedVersion) < 0
}
default candidate_external_processes := []
candidate_external_processes := external_processes {
semver.compare(policy_framework_version, version) == 0
policy_external_processes := [e | e := data.policy.external_processes[_]]
fragment_external_processes := [e |
feed := data.metadata.issuers[_].feeds[_]
fragment := feed[_]
e := fragment.external_processes[_]
]
external_processes := array.concat(policy_external_processes, fragment_external_processes)
}
candidate_external_processes := external_processes {
semver.compare(policy_framework_version, version) < 0
policy_external_processes := apply_defaults("external_process", data.policy.external_processes, policy_framework_version)
fragment_external_processes := [e |
feed := data.metadata.issuers[_].feeds[_]
fragment := feed[_]
e := fragment.external_processes[_]
]
external_processes := array.concat(policy_external_processes, fragment_external_processes)
}
external_process_ok(process) {
command_ok(process.command)
envList_ok(process.env_rules, input.envList)
workingDirectory_ok(process.working_dir)
}
default exec_external := {"allowed": false}
exec_external := {"allowed": true,
"allow_stdio_access": allow_stdio_access,
"env_list": env_list} {
possible_processes := [process |
process := candidate_external_processes[_]
# NB any change to these narrowing conditions should be reflected in
# the error handling, such that error messaging correctly reflects
# the narrowing process.
workingDirectory_ok(process.working_dir)
command_ok(process.command)
]
count(possible_processes) > 0
# check to see if the environment variables match, dropping
# them if allowed (and necessary)
env_list := valid_envs_for_all(possible_processes)
processes := [process |
process := possible_processes[_]
envList_ok(process.env_rules, env_list)
]
count(processes) > 0
allow_stdio_access := processes[0].allow_stdio_access
every p in processes {
p.allow_stdio_access == allow_stdio_access
}
}
default get_properties := {"allowed": false}
get_properties := {"allowed": true} {
allow_properties_access
}
default dump_stacks := {"allowed": false}
dump_stacks := {"allowed": true} {
allow_dump_stacks
}
default runtime_logging := {"allowed": false}
runtime_logging := {"allowed": true} {
allow_runtime_logging
}
default fragment_containers := []
fragment_containers := data[input.namespace].containers
default fragment_fragments := []
fragment_fragments := data[input.namespace].fragments
default fragment_external_processes := []
fragment_external_processes := data[input.namespace].external_processes
apply_defaults(name, raw_values, framework_version) := values {
semver.compare(framework_version, version) == 0
values := raw_values
}
apply_defaults("container", raw_values, framework_version) := values {
semver.compare(framework_version, version) < 0
values := [checked |
raw := raw_values[_]
checked := check_container(raw, framework_version)
]
}
apply_defaults("external_process", raw_values, framework_version) := values {
semver.compare(framework_version, version) < 0
values := [checked |
raw := raw_values[_]
checked := check_external_process(raw, framework_version)
]
}
apply_defaults("fragment", raw_values, framework_version) := values {
semver.compare(framework_version, version) < 0
values := [checked |
raw := raw_values[_]
checked := check_fragment(raw, framework_version)
]
}
default fragment_framework_version := null
fragment_framework_version := data[input.namespace].framework_version
extract_fragment_includes(includes) := fragment {
framework_version := fragment_framework_version
objects := {
"containers": apply_defaults("container", fragment_containers, framework_version),
"fragments": apply_defaults("fragment", fragment_fragments, framework_version),
"external_processes": apply_defaults("external_process", fragment_external_processes, framework_version)
}
fragment := {
include: objects[include] | include := includes[_]
}
}
issuer_exists(iss) {
data.metadata.issuers[iss]
}
feed_exists(iss, feed) {
data.metadata.issuers[iss].feeds[feed]
}
update_issuer(includes) := issuer {
feed_exists(input.issuer, input.feed)
old_issuer := data.metadata.issuers[input.issuer]
old_fragments := old_issuer.feeds[input.feed]
new_issuer := {"feeds": {input.feed: array.concat([extract_fragment_includes(includes)], old_fragments)}}
issuer := object.union(old_issuer, new_issuer)
}
update_issuer(includes) := issuer {
not feed_exists(input.issuer, input.feed)
old_issuer := data.metadata.issuers[input.issuer]
new_issuer := {"feeds": {input.feed: [extract_fragment_includes(includes)]}}
issuer := object.union(old_issuer, new_issuer)
}
update_issuer(includes) := issuer {
not issuer_exists(input.issuer)
issuer := {"feeds": {input.feed: [extract_fragment_includes(includes)]}}
}
default candidate_fragments := []
candidate_fragments := fragments {
semver.compare(policy_framework_version, version) == 0
policy_fragments := [f | f := data.policy.fragments[_]]
fragment_fragments := [f |
feed := data.metadata.issuers[_].feeds[_]
fragment := feed[_]
f := fragment.fragments[_]
]
fragments := array.concat(policy_fragments, fragment_fragments)
}
candidate_fragments := fragments {
semver.compare(policy_framework_version, version) < 0
policy_fragments := apply_defaults("fragment", data.policy.fragments, policy_framework_version)
fragment_fragments := [f |
feed := data.metadata.issuers[_].feeds[_]
fragment := feed[_]
f := fragment.fragments[_]
]
fragments := array.concat(policy_fragments, fragment_fragments)
}
default load_fragment := {"allowed": false}
svn_ok(svn, minimum_svn) {
# deprecated
semver.is_valid(svn)
semver.is_valid(minimum_svn)
semver.compare(svn, minimum_svn) >= 0
}
svn_ok(svn, minimum_svn) {
to_number(svn) >= to_number(minimum_svn)
}
fragment_ok(fragment) {
input.issuer == fragment.issuer
input.feed == fragment.feed
svn_ok(data[input.namespace].svn, fragment.minimum_svn)
}
load_fragment := {"metadata": [updateIssuer], "add_module": add_module, "allowed": true} {
some fragment in candidate_fragments
fragment_ok(fragment)
issuer := update_issuer(fragment.includes)
updateIssuer := {
"name": "issuers",
"action": "update",
"key": input.issuer,
"value": issuer,
}
add_module := "namespace" in fragment.includes
}
default scratch_mount := {"allowed": false}
scratch_mounted(target) {
data.metadata.scratch_mounts[target]
}
scratch_mount := {"metadata": [add_scratch_mount], "allowed": true} {
not scratch_mounted(input.target)
allow_unencrypted_scratch
add_scratch_mount := {
"name": "scratch_mounts",
"action": "add",
"key": input.target,
"value": {"encrypted": input.encrypted},
}