Overview
When using the TykCertificate Custom Resource Definition (CRD) with Tyk Operator to upload certificates to the Tyk Dashboard or Tyk Gateway, the controller may fail with an error such as failed to upload certificate to Tyk: Resource not found: HTTP 404. This article explains the root cause and provides steps to diagnose and resolve this issue.
Root Cause
When Tyk Operator reconciles a TykCertificate resource, it extracts the private key (tls.key) and certificate (tls.crt) from the referenced Kubernetes Secret. In both the Dashboard and Gateway clients, the operator concatenates the raw byte slices of the private key and certificate directly together into a single payload without inserting a newline delimiter.
If tls.key does not terminate with a newline character, the end of the private key block and the start of the certificate block merge onto a single line:
-----END PRIVATE KEY----------BEGIN CERTIFICATE-----Because the certificate parser cannot read this combined PEM data, the Tyk Dashboard or Tyk Gateway rejects the upload with an HTTP 404 error. This issue commonly occurs when secrets are stored in JSON payloads, configuration managers, or external secret stores like GCP Secret Manager or HashiCorp Vault where trailing newlines are omitted or stripped.
Verification
To verify whether the secret is missing a trailing newline, inspect the raw end of the decoded private key from the Kubernetes Secret:
kubectl get secret <secret-name> -n <namespace> -o jsonpath="{.data.tls\.key}" | base64 -d | tail -c 20 | od -cIf the final character in the output is a hyphen (-) rather than a newline character (\n), the private key lacks a terminating newline.
Resolution
To resolve the upload error, ensure tls.key includes a newline character immediately after the closing footer:
- Ensure the source private key file or secret manager entry contains a newline character after -----END PRIVATE KEY-----.
- Update the Kubernetes Secret with the corrected private key value.
- Trigger a reconciliation or delete and recreate the TykCertificate custom resource.
Applies To
- Tyk Operator v1.5.0 and later
- Tyk Dashboard
- Tyk Gateway
- Kubernetes Secrets of type kubernetes.io/tls
Comments
0 comments
Please sign in to leave a comment.