Skip to content

Handle newline character on agentk token

The Problem

When setting up a wrong unexpected configuration, gitlab-agent will fail to load the config with the following message:

level=warning msg="GetConfiguration.Recv failed" error="rpc error: code = Internal desc = stream terminated by RST_STREAM with error code: PROTOCOL_ERROR

This makes me think that there is a protocol communication error, which is misleading.

Reproducing

I recently committed 2 mistakes when creating the k8s secret used to share the agent token with gitlab-agent.

Not encoding base64

Created a secret without base64 encoding. For instance, instead of creating the secret using the --from-literal strategy, kubectl apply this file:

apiVersion: v1
kind: Secret
metadata:
  name: gitlab-agent-token
  namespace: gitlab-agent
data:
  token: YmFyCg==

Copy an extra line when specifying the secret.

after printing the secret from the console, I mistakenly copied the secret plus an extra line. So the secret extra line when creating the secret made the check not match. One can reproduce this locally easily by adding an extra line to the token.txt used to start the local development agent with Bazel.

Proposal

Remove the trailing newline which is causing the error.

Edited by João Alexandre Cunha