v0.20 Problem with authentication on controller-manager
Describe the bug It seems that controller-manager deployment from yaml is not using environment variables correctly.
Checks
- [ ] My actions-runner-controller version (v0.x.y) does support the feature
- [ ] I'm using an unreleased version of the controller I built from HEAD of the default branch
To Reproduce Steps to reproduce the behavior:
- deploy actions-runner-controller v0.20.0 from release page
- deploy secret with github app key and ids
- Try deploying any runner
- Get error in controller-manager saying that key file has length 0
Expected behavior Github runner should be registered
Environment (please complete the following information):
- Controller Version: 0.20.0
- Deployment Method:
kubectl apply
Additional context I have created a workaround by manually providing required arguments to /manager binary, see below:
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
control-plane: controller-manager
name: controller-manager
namespace: actions-runner-system
spec:
replicas: 1
selector:
matchLabels:
control-plane: controller-manager
template:
metadata:
labels:
control-plane: controller-manager
spec:
containers:
- name: manager
command:
- "/manager"
args:
- --metrics-addr=127.0.0.1:8080
- --enable-leader-election
- --sync-period=10m
- "-github-app-private-key"
- $(GITHUB_APP_PRIVATE_KEY)
- "-github-app-id"
- $(GITHUB_APP_ID)
- "-github-app-installation-id"
- $(GITHUB_APP_INSTALLATION_ID)
env:
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
key: github_token
name: controller-manager
optional: true
- name: GITHUB_APP_ID
valueFrom:
secretKeyRef:
key: github_app_id
name: controller-manager
optional: true
- name: GITHUB_APP_INSTALLATION_ID
valueFrom:
secretKeyRef:
key: github_app_installation_id
name: controller-manager
optional: true
- name: GITHUB_APP_PRIVATE_KEY
value: /etc/actions-runner-controller/github_app_private_key
image: summerwind/actions-runner-controller:v0.20.0
ports:
- containerPort: 9443
name: webhook-server
protocol: TCP
resources:
limits:
cpu: 100m
memory: 100Mi
requests:
cpu: 100m
memory: 20Mi
volumeMounts:
- mountPath: /tmp/k8s-webhook-server/serving-certs
name: cert
readOnly: true
- mountPath: /etc/actions-runner-controller
name: controller-manager
readOnly: true
- args:
- --secure-listen-address=0.0.0.0:8443
- --upstream=http://127.0.0.1:8080/
- --logtostderr=true
- --v=10
image: quay.io/brancz/kube-rbac-proxy:v0.10.0
name: kube-rbac-proxy
ports:
- containerPort: 8443
name: https
terminationGracePeriodSeconds: 10
volumes:
- name: cert
secret:
defaultMode: 420
secretName: webhook-server-cert
- name: controller-manager
secret:
secretName: controller-manager
---
Get error in controller-manager saying that certificate file has length 0
Which certificate are you referring? I thought the GitHub App authentication only requires key, app id, and installation id, but cert.
Yes, sorry, I meant key.
Thanks! Then it should just work.
How does the content of your secret look like?
kubectl describe secret controller-manager
Name: controller-manager
Namespace: actions-runner-system
Labels: <none>
Annotations: <none>
Type: Opaque
Data
====
github_app_id: 6 bytes
github_app_installation_id: 8 bytes
github_app_private_key: 1679 bytes
I've been trying to replicate this and have been unable to do so. We haven't touch anything in the area of this code in the latest release so I think this issue must be environmental. Are you able to provide any more details? I've tried replicating with both Helm and kubectl deployment methods as well as PAT and GitHub Auth
FWIW I'm experiencing this exact same issue in 0.19.0, and I cannot for the life of me figure out why -- I'm speculating that it's an incorrect formatting of the private key file, but I'm not sure, and I don't know what the correct format ought to be (apart from passing the key downloaded from GitHub verbatim).
If you're creating the secret via kubectl then you should just be able to use the --from-file= argument to read directly from the key.
When I download a key from GitHub it's encoded with LF line ending
kubectl create secret generic controller-manager \
-n actions-runner-system \
--from-literal=github_app_id=${APP_ID} \
--from-literal=github_app_installation_id=${INSTALLATION_ID} \
--from-file=github_app_private_key=${PRIVATE_KEY_FILE_PATH}
If you're using Helm then you should be setting your values like this:
github_app_id: "1111111"
github_app_installation_id: "1111111"
github_app_private_key: |
-----BEGIN RSA PRIVATE KEY-----
......
@sykora what method are you using?
I'm using option (1): the kubectl command with --from-file directly on the private key that was downloaded from GitHub, and starts with -----BEGIN RSA PRIVATE KEY----- and ends with the corresponding END footer. Do I need to be doing some kind of post processing/stripping?
Not that I'm aware of, what are you line endings on the downloaded file? What events are output for the controller on the cluster?
- I confirmed that the file uses LF line endings (not CRLF) by running
dos2unix key | cmp - key. - There are no events on the controller pod; its logs only contain the message that was implied in the original post:
Error: Client creation failed. authentication failed: using private key of size 0 (...): could not parse private key: Invalid Key: Key must be PEM encoded PKCS1 or PKCS8 private key
I have the same issue, tried debugging by changing deployment to use debian:slim image
- inspected env vars : ok
- checked the file is on the right path and readable : ok
- checked the content of the file with ssh-keygen and openssl : it is decoded correctly.
The error in kubectl logs looks like this:
Error: Environment variable read failed.
Error: Client creation failed. authentication failed: using private key of size 0 (...): could not parse private key: Invalid Key: Key must be PEM encoded PKCS1 or PKCS8 private key
so the first log line must be coming from here: https://github.com/actions-runner-controller/actions-runner-controller/blob/master/main.go#L85
Error: Environment variable read failed. Error: Client creation failed. authentication failed: using private key of size 0 (...): could not parse private key: Invalid Key: Key must be PEM encoded PKCS1 or PKCS8 private key
I had the same issue. Adding a %v exposed the exact error: fmt.Fprintln(os.Stderr, fmt.Sprintf("Error: Environment variable read failed: %v", err)). In my case it was bad helm yaml values, the app failed to parse the github_app_installation_id property because it was not quoted. Ensure your integers are quoted, example:
authSecret:
create: true
# must be quoted
github_app_id: "000000"
# must be quoted
github_app_installation_id: "00000000"
github_app_private_key: |-
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
@saumas That's it :/ That was my next step in debugging (printing value of err) but you saved me some time. Thanks :bow:
Having the exact same error checked by decode all the secrets are correct.
I've been trying to replicate this and have been unable to do so. We haven't touch anything in the area of this code in the latest release so I think this issue must be environmental. Are you able to provide any more details? I've tried replicating with both Helm and kubectl deployment methods as well as PAT and GitHub Auth.
I am using helm through terraform and I get the same error I tried downgrading chart, using a different tag. Something to note I am using it on eks with envelop encryption. so the keys are kuberntes encrypted and aws kms encrypted on disk. The annotation I am passing to the Service account has access to decrypt if the code requests it.
resource "kubernetes_namespace" "cert_manager" {
metadata {
name = "cert-manager"
}
}
resource "helm_release" "cert_manager" {
depends_on = [kubernetes_namespace.cert_manager]
name = "cert-manager"
repository = "https://charts.jetstack.io/"
namespace = "cert-manager"
chart = "cert-manager"
wait = true
set {
name = "serviceAccount.create"
value = "true"
}
set {
name = "serviceAccount.automountServiceAccountToken"
value = "true"
}
set {
name = "serviceAccount.name"
value = "cert-manager"
}
set {
name = "installCRDs"
value = "true"
}
set {
name = "webhook.securePort"
value = "10350"
}
}
resource "kubernetes_namespace" "actions_runner_system" {
metadata {
name = "actions-runner-system"
}
}
resource "helm_release" "github_runner" {
depends_on = [kubernetes_namespace.actions_runner_system]
name = "actions-runner-controller"
repository = "https://actions-runner-controller.github.io/actions-runner-controller"
namespace = "actions-runner-system"
wait = true
chart = "actions-runner-controller"
set {
name = "serviceAccount.create"
value = "true"
}
set {
name = "authSecret.create"
value = "true"
}
set {
name = "authSecret.github_app_id"
value = "123456"
type = "string"
}
set {
name = "authSecret.github_app_installation_id"
value = "Iv3415034i14914"
type = "string"
}
set {
name = "authSecret.github_app_private_key"
value = file("${path.module}/github.pem")
}
set {
name = "env.RUNNER_FEATURE_FLAG_EPHEMERAL"
value = "true"
type = "string"
}
set {
name = "githubWebhookServer.enabled"
value = "true"
type = "string"
}
set {
name = "githubWebhookServer.ports[0].nodePort"
value = "33080"
type = "string"
}
}
I get the same error I tried downgrading chart, using a different tag
@manpreet-agoro Are you basically saying that the version of actions-runner-controller that you downgraded to has some issue regarding this? I thought about it a while but it still look like a usage error to me.
From actions-runner-controller perspective, it's only about loading a few creds from envvars and/or flags. Our helm chart is just transforming helm values into those envvars and flags. And I think we have not changed code related to this for months 🤔
Well I am getting the same error, I cleared the install for the weekend. But yes basically same error even on downgrade. That's why I gave the terraform which I used. Makes easier to replicate everything. But as i mentioned I am using "envelop encryption" using kms in aws which means if the application is not handling the decryption of the variables on disk it might fail. The error is same
Error: Client creation failed. authentication failed: using private key of size 0 (...): could not parse private key: Invalid Key: Key must be PEM encoded PKCS1 or PKCS8 private key
@manpreet-agoro Thanks. Would you mind trying another setup (helm, k8s manifests, etc without terraform) too so that you can isolate the cause?
In #907, I've enhanced it to stop on environment read error, while logging a more detailed error message as @saumas has tried.
If anyone is still struggling to isolate the cause of the problem, would you mind trying #907?
The process would look like this:
- You checkout this repository locally.
- Then you run
NAME=$DOCKER_USER/actions-runner-controller VERSION=canary make docker-build docker-pushfor a custom container image build. - Finally, you update your actions-runer-controller's controller-manager deployment to use the new image,
$DOCKER_USER/actions-runner-controller:canary.
Please also note that you need to replace $DOCKER_USER with your own DockerHub account name.
I haven't tested any of the fixes here, but I did want to comment for posterity that the stop-gap way that I made things work was to replace the use of environment variables with the use of command-line flags to the /manager entry-point. However for those flags, the app ID and installation ID need to be non-quoted integers, or will otherwise trigger a parse error there. However, the private key was accepted that way.
I will be investigating other non-duct-tape approaches to make these changes durable.