fix(cluster-agent): construct kubeconfig authinfo name with agent id
Description
This change set constructs the auth info in the generated kube config
entries for the glab cluster agent update-kubeconfig command with the
agent id instead of the username.
This avoids conflicts where a glab user can switch their account but
want to reuse the same agent or simply using a different token. More
importantly though it generates the same auth info for two different
agents which can cause problems.
The changed command generates a kubeconfig along the lines of:
apiVersion: v1
clusters:
- cluster:
server: https://kas.gitlab.com/k8s-proxy
name: gitlab_com
contexts:
- context:
cluster: gitlab_com
user: gitlab_com-1096606
name: gitlab_com-timofurrer_playground-dev
- context:
cluster: gitlab_com
user: gitlab_com-1100000
name: gitlab_com-timofurrer_playground-foobar
current-context: gitlab_com-timofurrer_playground-foobar
kind: Config
preferences: {}
users:
- name: gitlab_com-1096606
user:
exec:
apiVersion: client.authentication.k8s.io/v1
args:
- cluster
- agent
- get-token
- --agent
- "1096606"
command: bin/glab
env: null
installHint: "To authenticate to the current cluster, glab is required. \n\nFollow
the installation instructions at https://gitlab.com/gitlab-org/cli#installation.\n"
interactiveMode: Never
provideClusterInfo: false
- name: gitlab_com-1100000
user:
exec:
apiVersion: client.authentication.k8s.io/v1
args:
- cluster
- agent
- get-token
- --agent
- "1100000"
command: bin/glab
env: null
installHint: "To authenticate to the current cluster, glab is required. \n\nFollow
the installation instructions at https://gitlab.com/gitlab-org/cli#installation.\n"
interactiveMode: Never
provideClusterInfo: false
Related Issues
Resolves #7448 (closed)
How has this been tested?
- Exploratory: see example kube config output above
- Unit tests as part of this change set
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to change) -
Documentation -
Chore (Related to CI or Packaging to platforms) -
Test gap