diff --git a/README.md b/README.md index e4541115..3cf93ddb 100644 --- a/README.md +++ b/README.md @@ -668,7 +668,7 @@ The primary benefit of autoscaling on Webhook compared to the pull driven scalin > You can learn the implementation details in [#282](https://github.com/actions-runner-controller/actions-runner-controller/pull/282) -To enable this feature, you firstly need to install the webhook server, currently, only our Helm chart has the ability install it: +To enable this feature, you first need to install the GitHub webhook server. To install via our Helm chart, _[see the values documentation for all configuration options](https://github.com/actions-runner-controller/actions-runner-controller/blob/master/charts/actions-runner-controller/README.md)_ ```console diff --git a/config/default/gh-webhook-server-auth-proxy-patch.yaml b/config/default/gh-webhook-server-auth-proxy-patch.yaml new file mode 100644 index 00000000..6d01f5da --- /dev/null +++ b/config/default/gh-webhook-server-auth-proxy-patch.yaml @@ -0,0 +1,23 @@ +# This patch injects an HTTP proxy sidecar container that performs RBAC +# authorization against the Kubernetes API using SubjectAccessReviews. +apiVersion: apps/v1 +kind: Deployment +metadata: + name: github-webhook-server +spec: + template: + spec: + containers: + - name: kube-rbac-proxy + image: quay.io/brancz/kube-rbac-proxy:v0.10.0 + args: + - '--secure-listen-address=0.0.0.0:8443' + - '--upstream=http://127.0.0.1:8080/' + - '--logtostderr=true' + - '--v=10' + ports: + - containerPort: 8443 + name: https + - name: github-webhook-server + args: + - '--metrics-addr=127.0.0.1:8080' diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index d44cfad5..4539475e 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -20,19 +20,22 @@ bases: - ../webhook # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required. - ../certmanager -# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. +# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. #- ../prometheus +# [GH_WEBHOOK_SERVER] To enable the GitHub webhook server, uncomment all sections with 'GH_WEBHOOK_SERVER'. +#- ../github-webhook-server patchesStrategicMerge: - # Protect the /metrics endpoint by putting it behind auth. - # Only one of manager_auth_proxy_patch.yaml and - # manager_prometheus_metrics_patch.yaml should be enabled. +# Protect the /metrics endpoint by putting it behind auth. +# Only one of manager_auth_proxy_patch.yaml and +# manager_prometheus_metrics_patch.yaml should be enabled. - manager_auth_proxy_patch.yaml - # If you want your controller-manager to expose the /metrics - # endpoint w/o any authn/z, uncomment the following line and - # comment manager_auth_proxy_patch.yaml. - # Only one of manager_auth_proxy_patch.yaml and - # manager_prometheus_metrics_patch.yaml should be enabled. + +# If you want your controller-manager to expose the /metrics +# endpoint w/o any authn/z, uncomment the following line and +# comment manager_auth_proxy_patch.yaml. +# Only one of manager_auth_proxy_patch.yaml and +# manager_prometheus_metrics_patch.yaml should be enabled. #- manager_prometheus_metrics_patch.yaml # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in crd/kustomization.yaml @@ -43,6 +46,10 @@ patchesStrategicMerge: # 'CERTMANAGER' needs to be enabled to use ca injection - webhookcainjection_patch.yaml +# [GH_WEBHOOK_SERVER] To enable the GitHub webhook server, uncomment all sections with 'GH_WEBHOOK_SERVER'. +# Protect the GitHub webhook server metrics endpoint by putting it behind auth. +# - gh-webhook-server-auth-proxy-patch.yaml + # the following config is for teaching kustomize how to do var substitution vars: # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix. diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml index 558812ec..2703a9af 100644 --- a/config/default/manager_auth_proxy_patch.yaml +++ b/config/default/manager_auth_proxy_patch.yaml @@ -23,4 +23,3 @@ spec: args: - "--metrics-addr=127.0.0.1:8080" - "--enable-leader-election" - - "--sync-period=10m" diff --git a/config/github-webhook-server/deployment.yaml b/config/github-webhook-server/deployment.yaml new file mode 100644 index 00000000..b1fe967d --- /dev/null +++ b/config/github-webhook-server/deployment.yaml @@ -0,0 +1,37 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/component: github-webhook-server + app.kubernetes.io/part-of: actions-runner-controller + name: github-webhook-server +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/component: github-webhook-server + app.kubernetes.io/part-of: actions-runner-controller + template: + metadata: + labels: + app.kubernetes.io/component: github-webhook-server + app.kubernetes.io/part-of: actions-runner-controller + spec: + containers: + - name: github-webhook-server + image: controller:latest + command: + - '/github-webhook-server' + env: + - name: GITHUB_WEBHOOK_SECRET_TOKEN + valueFrom: + secretKeyRef: + key: github_webhook_secret_token + name: github-webhook-server + optional: true + ports: + - containerPort: 8000 + name: http + protocol: TCP + serviceAccountName: github-webhook-server + terminationGracePeriodSeconds: 10 diff --git a/config/github-webhook-server/kustomization.yaml b/config/github-webhook-server/kustomization.yaml new file mode 100644 index 00000000..b7c92d42 --- /dev/null +++ b/config/github-webhook-server/kustomization.yaml @@ -0,0 +1,12 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +images: + - name: controller + newName: summerwind/actions-runner-controller + newTag: latest + +resources: + - deployment.yaml + - rbac.yaml + - service.yaml diff --git a/config/github-webhook-server/rbac.yaml b/config/github-webhook-server/rbac.yaml new file mode 100644 index 00000000..685e8c71 --- /dev/null +++ b/config/github-webhook-server/rbac.yaml @@ -0,0 +1,113 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/component: github-webhook-server + app.kubernetes.io/part-of: actions-runner-controller + name: github-webhook-server +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + labels: + app.kubernetes.io/component: github-webhook-server + app.kubernetes.io/part-of: actions-runner-controller + name: github-webhook-server +rules: + - apiGroups: + - actions.summerwind.dev + resources: + - horizontalrunnerautoscalers + verbs: + - get + - list + - patch + - update + - watch + - apiGroups: + - actions.summerwind.dev + resources: + - horizontalrunnerautoscalers/finalizers + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - actions.summerwind.dev + resources: + - horizontalrunnerautoscalers/status + verbs: + - get + - patch + - update + - apiGroups: + - actions.summerwind.dev + resources: + - runnersets + verbs: + - get + - list + - watch + - apiGroups: + - actions.summerwind.dev + resources: + - runnerdeployments + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - actions.summerwind.dev + resources: + - runnerdeployments/finalizers + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - actions.summerwind.dev + resources: + - runnerdeployments/status + verbs: + - get + - patch + - update + - apiGroups: + - authentication.k8s.io + resources: + - tokenreviews + verbs: + - create + - apiGroups: + - authorization.k8s.io + resources: + - subjectaccessreviews + verbs: + - create +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + labels: + app.kubernetes.io/component: github-webhook-server + app.kubernetes.io/part-of: actions-runner-controller + name: github-webhook-server +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: github-webhook-server +subjects: + - kind: ServiceAccount + name: github-webhook-server diff --git a/config/github-webhook-server/service.yaml b/config/github-webhook-server/service.yaml new file mode 100644 index 00000000..00f28a06 --- /dev/null +++ b/config/github-webhook-server/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/component: github-webhook-server + app.kubernetes.io/part-of: actions-runner-controller + name: github-webhook-server +spec: + ports: + - port: 80 + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/component: github-webhook-server + app.kubernetes.io/part-of: actions-runner-controller