Kubernetes Auth Method

    The auth method type allows for a Kubernetes service account token to be used to authenticate to Consul. This method of authentication makes it easy to introduce a Consul token into a Kubernetes pod.

    This page assumes general knowledge of Kubernetes and the concepts described in the main .

    The following auth method Config parameters are required to properly configure an auth method of type kubernetes:

    • (string: <required>) - Must be a host string, a host:port pair, or a URL to the base of the Kubernetes API server.

    • CACert (string: <required>) - PEM encoded CA cert for use by the TLS client used to talk with the Kubernetes API. NOTE: Every line must end with a newline (\n). If not set, system certificates are used.

    • (bool: <false>)

      - Deprecated in Consul 1.8.0 in favor of namespace rules. Indicates whether the auth method should attempt to map the Kubernetes namespace to a Consul namespace instead of creating tokens in the auth methods own namespace. Note that mapping namespaces requires the auth method to reside within the default namespace. Deprecated in Consul 1.8.0 in favor of .

    • ConsulNamespacePrefix

      Enterprise

      - Deprecated in Consul 1.8.0 in favor of . When MapNamespaces is enabled, this value will be prefixed to the Kubernetes namespace to determine the Consul namespace to create the new token within. Deprecated in Consul 1.8.0 in favor of namespace rules.

    • (map: <string:string>)

      Enterprise

      - Deprecated in Consul 1.8.0 in favor of namespace rules. This field is a mapping of Kubernetes namespace names to Consul namespace names. If a Kubernetes namespace is present within this map, the value will be used without adding the ConsulNamespacePrefix. If the value in the map is "" then the auth methods namespace will be used instead of attempting to determine an alternate namespace. Deprecated in Consul 1.8.0 in favor of .

    The following is an example configuration snippet to grant the necessary permissions to a service account named consul-auth-method-example:

    Initially the ServiceAccountJWT given to the Consul leader uses the TokenReview API to validate the provided JWT. The trusted attributes of , serviceaccount.name, and serviceaccount.uid are populated directly from the Service Account metadata.

    The Consul leader makes an additional query, this time to the ServiceAccount API to check for the existence of an annotation of consul.hashicorp.com/service-name on the ServiceAccount object. If one is found its value will override the trusted attribute of serviceaccount.name for the purposes of evaluating any binding rules.

    The authentication step returns the following trusted identity attributes for use in binding rule selectors and bind name interpolation.