|
1 | 1 | local common = import 'common.libsonnet'; |
| 2 | +local esp = import 'lib/espejote.libsonnet'; |
2 | 3 | local kap = import 'lib/kapitan.libjsonnet'; |
3 | 4 | local kube = import 'lib/kube.libjsonnet'; |
4 | | -local po = import 'lib/patch-operator.libsonnet'; |
5 | | -local inv = kap.inventory(); |
| 5 | + |
6 | 6 | // The hiera parameters for the component |
| 7 | +local inv = kap.inventory(); |
7 | 8 | local params = inv.parameters.appuio_cloud; |
8 | 9 |
|
9 | | -// See https://docs.openshift.com/container-platform/4.8/cicd/builds/securing-builds-by-strategy.html#builds-disabling-build-strategy-globally_securing-builds-by-strategy |
10 | | -local bindingToPatch = kube.ClusterRoleBinding('system:build-strategy-docker-binding'); |
| 10 | +local metadataPatch = { |
| 11 | + annotations+: { |
| 12 | + 'syn.tools/source': 'https://github.com/appuio/component-appuio-cloud.git', |
| 13 | + }, |
| 14 | + labels+: { |
| 15 | + 'app.kubernetes.io/managed-by': 'espejote', |
| 16 | + 'app.kubernetes.io/part-of': 'syn', |
| 17 | + 'app.kubernetes.io/component': 'appuio-cloud', |
| 18 | + }, |
| 19 | +}; |
11 | 20 |
|
12 | | -local disallowDockerBuildStrategyPatch = { |
| 21 | +// See https://docs.openshift.com/container-platform/4.8/cicd/builds/securing-builds-by-strategy.html#builds-disabling-build-strategy-globally_securing-builds-by-strategy |
| 22 | +local patch = { |
| 23 | + apiVersion: 'rbac.authorization.k8s.io/v1', |
| 24 | + kind: 'ClusterRoleBinding', |
13 | 25 | metadata: { |
14 | 26 | annotations: { |
15 | 27 | 'rbac.authorization.kubernetes.io/autoupdate': 'false', |
16 | 28 | }, |
| 29 | + name: 'system:build-strategy-docker-binding', |
17 | 30 | }, |
18 | 31 | subjects: [], |
19 | 32 | }; |
20 | 33 |
|
| 34 | +local serviceAccount = { |
| 35 | + apiVersion: 'v1', |
| 36 | + kind: 'ServiceAccount', |
| 37 | + metadata: { |
| 38 | + name: 'rbac-clusterrolebinding-system-build-strategy-docker-binding', |
| 39 | + namespace: inv.parameters.espejote.namespace, |
| 40 | + } + metadataPatch, |
| 41 | +}; |
| 42 | + |
| 43 | +local clusterRole = { |
| 44 | + apiVersion: 'rbac.authorization.k8s.io/v1', |
| 45 | + kind: 'ClusterRole', |
| 46 | + metadata: { |
| 47 | + name: 'syn-espejote:rbac-clusterrolebinding-system-build-strategy-docker-binding', |
| 48 | + } + metadataPatch, |
| 49 | + rules: [ |
| 50 | + { |
| 51 | + apiGroups: [ 'rbac.authorization.k8s.io' ], |
| 52 | + resources: [ 'clusterrolebindings' ], |
| 53 | + resourceNames: [ 'system:build-strategy-docker-binding' ], |
| 54 | + verbs: [ '*' ], |
| 55 | + }, |
| 56 | + ], |
| 57 | +}; |
| 58 | + |
| 59 | +local clusterRoleBinding = { |
| 60 | + apiVersion: 'rbac.authorization.k8s.io/v1', |
| 61 | + kind: 'ClusterRoleBinding', |
| 62 | + metadata: { |
| 63 | + name: 'syn-espejote:rbac-clusterrolebinding-system-build-strategy-docker-binding', |
| 64 | + } + metadataPatch, |
| 65 | + roleRef: { |
| 66 | + apiGroup: 'rbac.authorization.k8s.io', |
| 67 | + kind: 'ClusterRole', |
| 68 | + name: clusterRole.metadata.name, |
| 69 | + }, |
| 70 | + subjects: [ |
| 71 | + { |
| 72 | + kind: 'ServiceAccount', |
| 73 | + name: serviceAccount.metadata.name, |
| 74 | + namespace: serviceAccount.metadata.namespace, |
| 75 | + }, |
| 76 | + ], |
| 77 | +}; |
| 78 | + |
| 79 | +local managedResource = esp.managedResource('rbac-clusterrolebinding-system-build-strategy-docker-binding', inv.parameters.espejote.namespace) { |
| 80 | + metadata+: metadataPatch, |
| 81 | + spec: { |
| 82 | + applyOptions: { |
| 83 | + force: true, |
| 84 | + }, |
| 85 | + serviceAccountRef: { |
| 86 | + name: serviceAccount.metadata.name, |
| 87 | + }, |
| 88 | + template: std.manifestJson(patch), |
| 89 | + triggers: [ { |
| 90 | + name: 'clusterrolebinding', |
| 91 | + watchResource: { |
| 92 | + apiVersion: patch.apiVersion, |
| 93 | + kind: patch.kind, |
| 94 | + name: patch.metadata.name, |
| 95 | + }, |
| 96 | + } ], |
| 97 | + }, |
| 98 | +}; |
| 99 | + |
21 | 100 | { |
22 | | - [if params.disallowDockerBuildStrategy then '15_disallow_docker_build_strategy_patch']: |
23 | | - po.Patch(bindingToPatch, disallowDockerBuildStrategyPatch), |
| 101 | + [if params.disallowDockerBuildStrategy then '15_disallow_docker_build_strategy_patch']: [ |
| 102 | + serviceAccount, |
| 103 | + clusterRole, |
| 104 | + clusterRoleBinding, |
| 105 | + managedResource, |
| 106 | + ], |
24 | 107 | } |
0 commit comments