Personal-files request for glab (kube-config, write to ~/.kube)

name: glab
description: GitLab CLI. Work with GitLab issues, merge requests, pipelines and Kubernetes agents from the command line.
snapcraft: https://gitlab.com/gitlab-org/cli/-/blob/main/snap/snapcraft.yaml
upstream: https://gitlab.com/gitlab-org/cli
upstream-relation: maintainer (publisher is GitLab, Inc., which develops glab)
plugs:
  kube-config:
    interface: personal-files
    attributes:
      write: $HOME/.kube
    request-type: installation
    reasoning: `glab cluster agent update-kubeconfig` merges a context for a
      GitLab agent for Kubernetes into the user's kubeconfig so kubectl can
      reach the cluster. Under strict confinement HOME is the snap data
      directory, which kubectl never reads, so glab resolves the default
      kubeconfig against SNAP_REAL_HOME and needs access to ~/.kube.
      Write access to the directory (not only ~/.kube/config) is needed because
      client-go creates config.lock next to the kubeconfig while writing.
      Manual connection only; auto-connection is not requested.

Background

A user reported that the snap can’t do this: https://gitlab.com/gitlab-org/cli/-/work_items/8304. glab wrote the context into a kubeconfig in the snap’s data folder, which kubectl never reads, so the command reported success while the real ~/.kube/config stayed empty. The only workaround was pointing KUBECONFIG at a file outside a hidden folder, which the home interface allows. That’s a poor default for a standard Kubernetes setup.

The fix is https://gitlab.com/gitlab-org/cli/-/merge_requests/4031. If glab hits a permission error on a path under ~/.kube while running as a snap, it prints:

To allow the glab snap to access ~/.kube, run: sudo snap connect glab:kube-config

Kubeconfigs outside ~/.kube (for example, a custom KUBECONFIG path) aren’t covered, and glab doesn’t show the hint for them.

The revision waiting for review is 6944 (1.123.0-106-gd2db7b4).

Thanks!

1 Like

This request has been added to the queue for review by the @reviewers team.

1 Like

Hello @gitlab-cli :slight_smile:

Given the reasoning provided and that the request concerns installation-only with manual connection since glab doesn’t “own” $HOME/.kube, this is a +1 from my side.

Just a small note: Could you please rename the plug to dot-kube to match our naming convention for personal-files plugs?

1 Like

Thank you @yomonokio

This has been done in https://gitlab.com/gitlab-org/cli/-/merge_requests/4160/diffs which should be in https://dashboard.snapcraft.io/snaps/glab/revisions/6980/

2 Likes

Hi @gitlab-cli

Thanks for detailed request and limiting the scope to installation.

Assuming that the config.lock file is specific to glab snap, will it possible to write this file to a temporary location so that the scope of the personal-files interface can be limited to ~/.kube/config?

No problem @shishirsub10, thanks for the review!

config.lock isn’t specific to the glab snap. It’s client-go’s standard kubeconfig lock, created as <kubeconfig>.lock next to the kubeconfig while writing and removed afterwards. kubectl and other client-go tools use the same lock to avoid concurrent writes, so it has to stay next to the kubeconfig and can’t move to a temporary location.

To limit the scope, we can narrow the plug from the folder to exactly those two files:

plugs: dot-kube: interface: personal-files write: - $HOME/.kube/config - $HOME/.kube/config.lock

Would that be acceptable? If so, we’ll upload a revision with the narrowed plug and share the revision number.

Thanks!

1 Like

Hi @gitlab-cli

config.lock isn’t specific to the glab snap. It’s client-go’s standard kubeconfig lock, created as <kubeconfig>.lock next to the kubeconfig while writing and removed afterwards. kubectl and other client-go tools use the same lock to avoid concurrent writes, so it has to stay next to the kubeconfig and can’t move to a temporary location.

I was not aware, thanks for the info.

To limit the scope, we can narrow the plug from the folder to exactly those two files:

plugs: dot-kube: interface: personal-files write: - $HOME/.kube/config - $HOME/.kube/config.lock

Would that be acceptable?

Yes, that will work. +1 from me as well for granting write access to $HOME/.kube/config and $HOME/.kube/config.lock using personal-files interface with manual-connection.

1 Like

Thanks @shishirsub10 ! We’ve narrowed the plug to $HOME/.kube/config and $HOME/.kube/config.lock (https://gitlab.com/gitlab-org/cli/-/merge_requests/4214). Revisions 7030 and 7031 are the first uploads with it. Could the declaration be granted? Do i need to reject the earlier revisions?

Hi @gitlab-cli

Perfect, thanks for making the change.

One final thing, could you please change the name of the plug to dot-kube-config?

No worries @shishirsub10

Renamed the plug to dot-kube-config in https://gitlab.com/gitlab-org/cli/-/merge_requests/4238. Revision 7045 is the first upload with it, and we’ve rejected the earlier queued revisions.

1 Like

+2 votes for, 0 votes against, publisher is already vetted, granting manual-connection of dot-kube-config personal-files interface to glab. I was unable to trigger the automated reviews and things are kind of stuck for now. I have pinged the related team internally and will get that sorted, thanks!

3 Likes

Hi @gitlab-cli

The snap is now live. Apologies for the delay!

1 Like

Thank you, much appreciated

1 Like