Skip to content

Commit

Permalink
Merge pull request #22 from appuio/disallow-docker-build-strategy
Browse files Browse the repository at this point in the history
Disallow docker build strategy
  • Loading branch information
bastjan authored Oct 4, 2021
2 parents 9dc403f + e007af3 commit e0783dc
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions class/appuio-cloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ parameters:
- appuio-cloud/component/project-template.jsonnet
- appuio-cloud/component/project-policies.jsonnet
- appuio-cloud/component/quota-limitrange.jsonnet
- appuio-cloud/component/build-strategy.jsonnet
input_type: jsonnet
output_path: appuio-cloud/
2 changes: 2 additions & 0 deletions class/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ parameters:
memory: "100Mi"
# 250Mi (requests.ephemeral-storage) / 45 (count/pods) = ~5Mi
ephemeral-storage: "5Mi"

disallowDockerBuildStrategy: true
22 changes: 22 additions & 0 deletions component/build-strategy.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
local common = import 'common.libsonnet';
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';
local resourceLocker = import 'lib/resource-locker.libjsonnet';
local inv = kap.inventory();
// The hiera parameters for the component
local params = inv.parameters.appuio_cloud;

// 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
local bindingToPatch = kube.ClusterRoleBinding('system:build-strategy-docker-binding');

local disallowDockerBuildStrategyPatch = {
annotations: {
'rbac.authorization.kubernetes.io/autoupdate': 'false',
},
subjects: [],
};

{
[if params.disallowDockerBuildStrategy then '15_disallow_docker_build_strategy_patch']:
resourceLocker.Patch(bindingToPatch, disallowDockerBuildStrategyPatch),
}
7 changes: 7 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,10 @@ It will also reject any container requesting more than `4G` of memory or less th

Consult https://kubernetes.io/docs/concepts/policy/limit-range/[the official Kubernetes documentation] on how to configure these `limits`.

== `disallowDockerBuildStrategy`

[horizontal]
type:: boolean
default:: `true`

Creating https://docs.openshift.com/container-platform/4.7/cicd/builds/build-strategies.html#builds-strategy-docker-build_build-strategies[build strategies using Docker] is disallowed.
6 changes: 6 additions & 0 deletions tests/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ parameters:
- type: https
source: https://raw.githubusercontent.com/projectsyn/component-kyverno/v1.1.0/lib/kyverno.libsonnet
output_path: vendor/lib/kyverno.libsonnet
- type: https
source: https://raw.githubusercontent.com/projectsyn/component-resource-locker/v2.0.1/lib/resource-locker.libjsonnet
output_path: vendor/lib/resource-locker.libjsonnet

appuio_cloud:
bypassNamespaceRestrictions:
Expand All @@ -14,3 +17,6 @@ parameters:
kind: ServiceAccount
name: argocd-application-controller
namespace: argocd

resource_locker:
namespace: syn-resource-locker
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
name: system-build-strategy-docker-binding-manager
name: system-build-strategy-docker-binding-manager
namespace: syn-resource-locker
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
name: syn-resource-locker-ystem-build-strategy-docker-binding-manager
name: syn-resource-locker-ystem-build-strategy-docker-binding-manager
rules:
- apiGroups:
- rbac.authorization.k8s.io
resources:
- clusterrolebindings
verbs:
- get
- list
- patch
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
name: syn-resource-locker-ystem-build-strategy-docker-binding-manager
name: syn-resource-locker-ystem-build-strategy-docker-binding-manager
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: syn-resource-locker-ystem-build-strategy-docker-binding-manager
subjects:
- kind: ServiceAccount
name: system-build-strategy-docker-binding-manager
namespace: syn-resource-locker
---
apiVersion: redhatcop.redhat.io/v1alpha1
kind: ResourceLocker
metadata:
annotations:
argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true
labels:
name: system-build-strategy-docker-binding
name: system-build-strategy-docker-binding
namespace: syn-resource-locker
spec:
patches:
- id: patch1
patchTemplate: "\"annotations\":\n \"rbac.authorization.kubernetes.io/autoupdate\"\
: \"false\"\n\"subjects\": []"
patchType: application/strategic-merge-patch+json
targetObjectRef:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
name: system:build-strategy-docker-binding
serviceAccountRef:
name: system-build-strategy-docker-binding-manager

0 comments on commit e0783dc

Please sign in to comment.