| title | Serving Plugins Privately |
|---|---|
| slug | private-plugins |
| weight | 850 |
Plugin archives are the binary artifacts that contain the compiled plugin executable.
These archives are typically hosted in a public registry (such as the official krew-index).
For plugins stored in private registries that require authentication, Krew supports
reading credentials from the user's .netrc file (_netrc on Windows).
To enable this behavior, use the --enable-netrc flag.
This is commonly required when using [custom indexes]({{<ref "using-custom-indexes.md">}}), where plugin artifacts are served from a private registry that requires authentication.
For example, to install a plugin named bar from custom index foo:
{{<prompt>}}kubectl krew install --enable-netrc foo/barThe host portion of the plugin archive URL (as specified in the custom index)
must have a corresponding entry in your .netrc file with the appropriate credentials:
machine <private registry host>
login <username>
password <password>
By default, Krew looks for the .netrc file in your home directory:
- Linux & macOS:
~/.netrc - Windows:
%HOME%\_netrc
You can override the default location by using the --netrc-file flag.
Below is a reference on how Krew artifacts can be stored in a private GitHub repository, and
retrieved using a GitHUb PAT (personal access token) stored in a .netrc file.
Example repository structure:
internal-krew/
βββ artifacts/ β compiled plugin artifacts (stored in branches, or in main)
β βββ <plugin-name>/<version>/ β e.g. artifacts/<plugin-name>/v0.1.0/kubectl-<plugin-name>-v0.1.0.tar.gz
β βββ kubectl-<plugin-name>-v0.1.0.tar.gz
βββ plugins/ β Krew plugin manifests
β βββ <plugin-name>.yaml β manifest for kubectl-<plugin-name>
βββ src/ β source code for all plugins
β βββ <plugin-name>/ β kubectl-<plugin-name> source code
β β βββ .krew.yaml β Krew manifest template
β βββ <other-plugin>/ β additional plugins follow the same pattern
βββ .gitignore
βββ README.md
A release pipeline can be used to build the plugin artifact and store it under artifacts/, the
plugin manifest is stored under plugins/.
Plugins code live under src/<plugin-name>/
Krew template (.krew.yaml) used to populate the plugin manifest
Krew Manifests are stored plugins/<plugin-name>.yaml (generated from the .krew.yaml template)
Artifacts are published to the following locations in the repository
artifacts/<plugin-name>/<version>/in themainbranch, orartifacts/<plugin-name>/<version>/in a dedicated branch namedartifacts-<plugin-name>-<version>
This structure allows direct downloads via raw.githubusercontent.com URIs β even from private repositories β using GitHub Personal Access Token (PAT) authentication.
e.g. artifacts-foo-v0.1.0 plugin archive URI:
https://raw.githubusercontent.com/<org>/internal-krew/<branch>/artifacts/foo/v0.1.0/kubectl-foo-v0.1.0.tar.gz
Note: GitHub release artifacts on private repos do not support this auth method, that's why
raw.githubusercontent.com is used.
Users need to generate a GitHub fine-grained (repository scoped) PAT (Personal Access Token) with
read-only permissions: contents & metadata
The produced PAT token is stored in the .netrc file:
machine github.com
login token
password <fine-grained github PAT>
machine raw.githubusercontent.com
login token
password <fine-grained github PAT>