- .github
- devel
- doc
-
examples
-
dynamic-client
-
notebooks
-
watch
-
yaml_dir
- README.md
- __init__.py
- annotate_deployment.py
- api_discovery.py
- apply_from_dict.py
- apply_from_directory.py
- apply_from_single_file.py
- cluster_scoped_custom_object.py
- cronjob_crud.py
- deployment_create.py
- deployment_crud.py
- duration-gep2257.py
- in_cluster_config.py
- ingress_create.py
- job_crud.py
- multiple_clusters.py
- namespaced_custom_object.py
- node_labels.py
- out_of_cluster_config.py
- pick_kube_config_context.py
- pod_config_list.py
- pod_exec.py
- pod_portforward.py
- remote_cluster.py
- rollout-daemonset.py
- rollout-statefulset.py
-
dynamic-client
- kubernetes
- scripts
- .gitignore
- CHANGELOG.md
- CONTRIBUTING.md
- LICENSE
- MANIFEST.in
- OWNERS
- README.md
- SECURITY_CONTACTS
- code-of-conduct.md
- codecov.yml
- requirements.txt
- setup.cfg
- setup.py
- test-requirements.txt
- tox.ini
Explanation
The ExecProvider
class implements a mechanism for authenticating Kubernetes clients using external programs. This approach allows for custom authentication methods beyond the built-in options. It is based on the design proposal documented at https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/kubectl-exec-plugins.md.
Key Features:
- Exec Plugin Integration: It allows the use of executable programs (plugins) to handle authentication.
- Configuration: The provider accepts a configuration dictionary, including the plugin command and optional arguments.
- Environment Variables: It sets up environment variables for the plugin, including
KUBERNETES_EXEC_INFO
which contains details about the authentication request. - Response Handling: It handles the plugin’s response, ensuring it’s a valid JSON document with the expected structure.
Constructor (__init__):
- Takes
exec_config
(a configuration dictionary) and an optionalcwd
(working directory for the plugin). - Verifies the presence of required configuration parameters (
command
andapiVersion
). - Stores the
apiVersion
andargs
from the config. - Copies the current environment variables into
self.env
. - Updates the environment with additional variables specified in the config’s
env
section.
Run Method:
- Sets up an environment variable
KUBERNETES_EXEC_INFO
containing a JSON structure describing the authentication request (including theapiVersion
,kind
, andspec
). If there’s a previous response, it’s added to thespec
as well. - Spawns a subprocess to execute the plugin command with the configured environment and arguments.
- Captures the stdout and stderr output.
- Checks the exit code of the plugin. If it’s not zero, an exception is raised, including the error message from the plugin.
- Parses the JSON output from the plugin’s stdout, validating the
apiVersion
,kind
, andstatus
fields. - Returns the
status
field from the plugin response.
Limitations:
- TLS Support: It currently lacks support for TLS certificates.
- Caching: It does not implement any caching mechanisms for authentication tokens or other information.
Overall:
The ExecProvider
provides a flexible way to incorporate custom authentication methods into Kubernetes clients, but it’s important to be aware of its limitations and ensure the plugin’s security and reliability.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph