Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create github k8s service account #77

Merged
merged 12 commits into from
Mar 6, 2023
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ integration-test: ## Run integration tests

validate: ## Run static checks
@ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=$(CURDIR)/.tool-versions pre-commit run --color=always --show-diff-on-failure --all-files

create-ci-service-account: ## Create a k8s service account that would be used by CI systems
@./scripts/create-ci-service-account.sh
11 changes: 11 additions & 0 deletions manifests/ci-service-account/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Service account for CI Bot
This cluster will deploy a `ServiceAccount` with the
sole purpose of being utilized by the CI System to interact with the cluster.

The `ServiceAccount` is associated with a `kubernetes.io/service-account-token`.
Once this token is generated, the cluster administrator must export this token to the
CI System as a secret.

In the case of GitHub, follow the [official guide](https://docs.github.com/en/actions/security-guides/encrypted-secrets#about-encrypted-secrets)
for creating a secret. Depending on your specific needs the secret could be applicable to a single repo,
an environment, or the entire GitHub organization.
12 changes: 12 additions & 0 deletions manifests/ci-service-account/ci-cluster-role-binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: continuous-deployment
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: continuous-deployment
subjects:
- kind: ServiceAccount
name: ci-bot
namespace: default
25 changes: 25 additions & 0 deletions manifests/ci-service-account/ci-cluster-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: continuous-deployment
rules:
- apiGroups:
- ''
- apps
- networking.k8s.io
resources:
- namespaces
- deployments
- replicasets
- ingresses
- services
- secrets
verbs:
- create
- delete
- deletecollection
- get
- list
- patch
- update
- watch
4 changes: 4 additions & 0 deletions manifests/ci-service-account/ci-service-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: ci-bot
7 changes: 7 additions & 0 deletions manifests/ci-service-account/ci-token.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: github-actions-token
annotations:
kubernetes.io/service-account.name: "ci-bot"
type: kubernetes.io/ci-bot-token
3 changes: 3 additions & 0 deletions scripts/create-ci-service-account.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

kubectl apply -f manifests/gha-service-account