Connect to managed clusters (GKE, EKS, AKS)

This page shows how to run piceli release against a managed cluster whose kubeconfig authenticates through an exec credential plugin (gke-gcloud-auth-plugin, aws eks get-token, kubelogin, an OIDC login plugin), and what Piceli does to keep that safe.

Maturity: preview. The [target] keys allow_exec, exec_sha256, exec_pass_env and exec_timeout_seconds and the error codes listed here may still change before 1.0. Scripts should match on the error codes.

How it works

An exec plugin is a local program that kubectl (and Piceli) runs to get a short-lived credential. Running it is code execution with your cloud login, so Piceli never does it implicitly:

  1. Opt-in. A context whose user has an exec block is refused (exec-auth-not-allowed) unless [target] sets allow_exec = true. The plugin does not run before that.

  2. Pinned. The command is resolved once to an absolute real path: a bare name such as gke-gcloud-auth-plugin is looked up in PATH, a relative path is resolved from the kubeconfig’s directory, and symlinks are followed. Piceli records the file’s sha256 and, when exec_sha256 is set, refuses a different file (exec-pin-mismatch). The file is hashed again before every run, so a binary replaced during a run is refused too. Files writable by their group or other users are refused (exec-command-unsafe).

  3. Minimal environment. The plugin receives only:

    • PATH and HOME from Piceli’s environment (plugins find their tools and their login cache through them);

    • the variables you name in exec_pass_env (for example AWS_PROFILE), copied from Piceli’s environment;

    • the env entries of the kubeconfig’s exec block;

    • LANG=C and KUBERNETES_EXEC_INFO (the Kubernetes exec protocol input, with interactive: false, plus the server and CA when the kubeconfig sets provideClusterInfo: true).

    Nothing else is inherited: no cloud credentials in variables you did not name, no KUBECONFIG.

  4. Non-interactive and bounded. stdin is closed, the run is stopped after exec_timeout_seconds (default 60), and output is limited to 1 MB. Plugins that require a terminal (interactiveMode: Always) are refused. The plugin’s own messages (stderr) are shown on Piceli’s stderr, as kubectl does; its stdout, which carries the credential, is never printed or logged.

  5. In memory only. Tokens live in the client’s memory. Client certificates returned by a plugin are passed to OpenSSL through pipes, not files. The cluster CA is read from the kubeconfig in memory as well.

  6. Refresh owned by Piceli. Before each API request Piceli checks the credential’s expirationTimestamp and re-runs the same pinned plugin when less than min(30 s, lifetime / 2) remains. A credential without an expiry is reused for the whole command. KubernetesProvider accepts a credential-refresh hook only when Piceli’s exec source installed it on that exact client; any other refresh hook is still refused.

Still refused, with or without allow_exec:

  • legacy auth-provider users (gcp, oidc, azure): auth-provider-refused. They are deprecated upstream; every provider has an exec replacement (below);

  • proxies (proxy-url), insecure-skip-tls-verify, non-https servers, basic auth, and users that mix exec with static credentials;

  • exec apiVersion client.authentication.k8s.io/v1alpha1 (only v1 and v1beta1 are accepted).

Prerequisites

  • A kubeconfig file generated by your provider’s CLI, saved as its own file (Piceli never reads KUBECONFIG or ~/.kube/config):

    Provider

    Generate the kubeconfig

    Plugin

    GKE

    KUBECONFIG=gke.kubeconfig gcloud container clusters get-credentials my-cluster --region europe-west1

    gke-gcloud-auth-plugin

    EKS

    aws eks update-kubeconfig --name my-cluster --region eu-west-1 --kubeconfig eks.kubeconfig

    aws (eks get-token)

    AKS

    az aks get-credentials -n my-cluster -g my-group -f aks.kubeconfig, then kubelogin convert-kubeconfig -l azurecli --kubeconfig aks.kubeconfig

    kubelogin

    OIDC

    Your identity provider’s instructions for an exec plugin such as kubelogin (oidc-login)

    e.g. kubectl-oidc_login

  • A current login for the plugin (gcloud auth login, aws sso login, az login, or one interactive OIDC login), since Piceli runs it without a terminal.

Steps

  1. Check that the context works and look at the exec block Piceli will run:

    $ kubectl --kubeconfig gke.kubeconfig --context my-context get ns kube-system
    $ grep -A8 'exec:' gke.kubeconfig
    
  2. Pin the plugin. Resolve the command the same way Piceli does and hash it:

    $ realpath "$(command -v gke-gcloud-auth-plugin)"
    /opt/google-cloud-sdk/bin/gke-gcloud-auth-plugin
    $ shasum -a 256 /opt/google-cloud-sdk/bin/gke-gcloud-auth-plugin
    9f2c…  /opt/google-cloud-sdk/bin/gke-gcloud-auth-plugin
    
  3. Allow it in release.toml:

    [target]
    kubeconfig = "gke.kubeconfig"
    context = "my-context"
    namespace = "shop"
    allow_exec = true                          # run this context's exec plugin
    exec_sha256 = "sha256:9f2c…"               # optional, recommended
    # exec_pass_env = ["CLOUDSDK_CONFIG"]      # extra variables the plugin needs
    # exec_timeout_seconds = 60
    

    For EKS with named profiles, pass the profile explicitly: exec_pass_env = ["AWS_PROFILE"] (or add it to the kubeconfig’s env).

  4. Plan, then apply the approved hash as usual:

    $ piceli release plan --spec release.toml
    $ piceli release apply --spec release.toml --approve <plan_hash>
    

    For a pipeline (piceli deploy), set the same options on its Target instead; they apply to piceli deploy, piceli status, piceli access and piceli release … --spec module.py:pipeline:

    target = Target.kubeconfig(
        "gke.kubeconfig",
        context="my-context",
        namespace="shop",
        allow_exec=True,
        exec_sha256="sha256:9f2c…",
        # exec_pass_env=["CLOUDSDK_CONFIG"], exec_timeout_seconds=60,
    )
    

Expected output: the same as with a static kubeconfig. When a plugin upgrade changes its file, the next command refuses with exec-pin-mismatch and names the new digest; update exec_sha256 after checking the upgrade was expected.

Reference

[target] keys (all optional; the exec_* keys require allow_exec = true):

Key

Type

Default

Meaning

allow_exec

bool

false

Run the context’s exec plugin.

exec_sha256

sha256:<64 hex>

none

Expected digest of the resolved command file.

exec_pass_env

list of names

[]

Extra variables copied from Piceli’s environment.

exec_timeout_seconds

number in (0, 300]

60

Limit for one plugin run.

piceli.pipeline.Target.kubeconfig(...) takes the same four options as keyword arguments (allow_exec=True, exec_sha256=…, exec_pass_env=[…], exec_timeout_seconds=…), validated the same way (pipeline-invalid otherwise).

piceli status and piceli access use the target’s policy too (from [target] or the pipeline’s Target). status runs the plugin through Piceli’s own client; access resolves and pins it, then kubectl port-forward runs it itself with your environment (as for piceli observe). Without the opt-in both refuse the exec user (exec-auth-not-allowed).

Python API: KubeconfigTarget(..., allow_exec=True, exec_sha256=...) with build_provider, or api_client_from_kubeconfig(path, context, exec_policy=ExecPolicy(True)) from piceli.k8s.ops.provider_factory. The built ProviderBinding.credential_plugin holds the resolved path, digest and exec apiVersion (never arguments, environment or credentials).

What the pin covers: only the file the command resolves to. A plugin that starts other programs (gke-gcloud-auth-plugin → gcloud, kubelogin -l azurecli → az, kubectl oidc-login → kubectl-oidc_login) runs them from PATH unpinned; point command at the final binary where you can (kubectl-oidc_login instead of kubectl). A user who can replace the file between the hash and the run can still swap it; keep plugins in directories only you (or root) can write.

If it fails

Code

Meaning

Fix

exec-auth-not-allowed

The context uses an exec plugin and allow_exec is not set.

Review the exec block, then set allow_exec = true.

auth-provider-refused

The user has a legacy auth-provider.

Regenerate the kubeconfig for the exec plugin (table above).

exec-command-not-found

The command is not in PATH or does not exist.

Install the plugin or fix PATH.

exec-command-unsafe

Not an executable regular file, or writable by group/others.

chmod go-w the file or reinstall it.

exec-pin-mismatch

The file’s digest differs from exec_sha256, or changed during the run.

Check the upgrade, then update exec_sha256.

exec-interactive-required

interactiveMode: Always.

Log in with the plugin first; use IfAvailable.

exec-plugin-failed

The plugin exited non-zero; its message is on stderr.

Usually log in again (gcloud auth login, aws sso login, az login).

exec-plugin-timed-out

The plugin did not finish in time. Safe to retry.

Retry; check network access or raise exec_timeout_seconds.

exec-credential-invalid

The output is not a valid ExecCredential (format, apiVersion, PEM, expiry).

Run the plugin by hand; upgrade it.

exec-config-invalid

The exec block or cluster CA data is malformed, or exec_sha256 is set for a static user.

Regenerate the kubeconfig or fix [target].

piceli explain <code> prints the same entries; see Error codes.