github-app-operator
A Kubernetes operator to get and renew a Github App access token using a custom GithubApp resource.
3.8K
This is a Kubernetes operator that will generate an access token for a GithubApp and store it in a secret to use for authenticated requests to Github as the GithubApp.
It will reconcile a new access token before expiry (1hr).
See how to deploy the operator with Helm, Kustomize or from source - GitHub Source
GithubApp in your destination namespace.appId, installId, and either privateKeySecret, googlePrivateKeySecret or vaultPrivateKey defined in a GithubApp resource to request an access token from GitHub.accessTokenSecret.privateKeySecret - refers to an existing secret in the namespace holding the base64 encoded PEM of the GitHub App's private key.data.privateKey.googlePrivateKeySecret - the full secret path in Secret Manager for your GitHub App secret, e.g. projects/xxxxxxxxxx/secrets/my-gh-app/versions/latest.roles/secretmanager.secretAccessor.vaultPrivateKey block:
spec.vaultPrivateKey.mountPath - Secret mount path, e.g., secretspec.vaultPrivateKey.secretPath - Secret path, e.g., githubapps/{App ID}spec.vaultPrivateKey.secretKey - Secret key, e.g., privateKeyVAULT_ROLE - The role bound for Kubernetes auth for the operator.VAULT_ROLE_AUDIENCE - The audience bound in Vault.VAULT_ADDR - FQDN of your Vault server, e.g., http://vault.default:8200.VAULT_NAMESPACE for enterprise Vault (see Vault API).GithubApp object if deleted.GithubApp when:
GithubApp.GithubApp object.status.expiresAt value.status.expiresAt field of the GithubApp object.status.error field of the GithubApp object during reconciliation.CHECK_INTERVAL - e.g., to check every 5 minutes, set the value to 5m (default: 5m).EXPIRY_THRESHOLD - e.g., to reconcile a new access token if there is less than 10 minutes left from expiry, set the value to 10m (default: 15m).GITHUB_PROXY - e.g., http://myproxy.com:8080.VAULT_PROXY_ADDR - e.g., http://myproxy.com:8080.GithubApp that match any of the labels defined in spec.rolloutDeployment.labels.
DEBUG_LOG to true in the manager deployment environment variable for debug level logs.kubectl get:
GithubApp.GithubApp ResourceHere is an example of how to define the GithubApp resource:
apiVersion: githubapp.samir.io/v1
kind: GithubApp
metadata:
name: example-githubapp
spec:
appId: <your-github-app-id>
installId: <your-github-app-installation-id>
privateKeySecret: <your-private-key-secret-name> # If using Kubernetes secret
googlePrivateKeySecret: <your-google-secret-path> # If using GCP Secret Manager
vaultPrivateKey: # If using Hashicorp Vault
mountPath: <your-vault-mount-path>
secretPath: <your-vault-secret-path>
secretKey: <your-vault-secret-key>
accessTokenSecret: <your-access-token-secret-name>
base64 -w 0 private-key.pem
apiVersion: v1
kind: Secret
metadata:
name: github-app-secret
namespace: YOUR_NAMESPACE
type: Opaque
data:
privateKey: BASE64_ENCODED_PRIVATE_KEY
team-1 namespace, the access token will be available to use in the secret github-app-access-token-123123kubectl apply -f - <<EOF
apiVersion: githubapp.samir.io/v1
kind: GithubApp
metadata:
name: GithubApp-sample
namespace: team-1
spec:
appId: 123123
installId: 12312312
privateKeySecret: github-app-secret
accessTokenSecret: github-app-access-token-123123
EOF
team-1 namespace when the github token is modified, matching any of labels:
kubectl apply -f - <<EOF
apiVersion: githubapp.samir.io/v1
kind: GithubApp
metadata:
name: GithubApp-sample
namespace: team-1
spec:
appId: 123123
installId: 12312312
privateKeySecret: github-app-secret
accessTokenSecret: github-app-access-token-123123
rolloutDeployment:
labels:
foo: bar
foo2: bar2
EOF
kubectl apply -f - <<EOF
apiVersion: githubapp.samir.io/v1
kind: GithubApp
metadata:
name: GithubApp-sample
namespace: team-1
spec:
appId: 123123
installId: 12312312
accessTokenSecret: github-app-access-token-123123
vaultPrivateKey:
mountPath: secret
secretPath: githubapp/123123
secretKey: privateKey
EOF
kubectl apply -f - <<EOF
apiVersion: githubapp.samir.io/v1
kind: GithubApp
metadata:
name: GithubApp-sample
namespace: team-1
spec:
appId: 123123
installId: 12312312
accessTokenSecret: github-app-access-token-123123
googlePrivateKeySecret: "projects/123123123123/secrets/gh-app-123123/versions/latest"
EOF
A helm chart is generated using make helm when a new tag is pushed, i.e a release.
You can pull the helm chart from this repos packages
helm pull oci://ghcr.io/samirtahir91/github-app-operator/helm-charts/github-app-operator --version <TAG>
values.yaml as required.samirtahir91076/github-app-operator:latest
Content type
Image
Digest
sha256:8053ee4cf…
Size
34.7 MB
Last updated
about 2 months ago
docker pull samirtahir91076/github-app-operator