Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
support ExecCredential authentication (#36)
Browse files Browse the repository at this point in the history
* add exec auth method

* kube config exec.env is optional

* Update pykube/http.py

Co-Authored-By: Daniel Middlecote <[email protected]>

* add a version check

* commit black changes

* avoid referencing or changing os.environ

Co-authored-by: zoidbergwill <[email protected]>
Co-authored-by: Daniel Middlecote <[email protected]>
  • Loading branch information
3 people authored and hjacobs committed Jan 15, 2020
1 parent 045e597 commit 8602da2
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pykube/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import posixpath
import shlex
import subprocess
import os

try:
import google.auth
Expand Down Expand Up @@ -98,6 +99,24 @@ def send(self, request, **kwargs):
pass
elif "token" in config.user and config.user["token"]:
request.headers["Authorization"] = "Bearer {}".format(config.user["token"])

elif "exec" in config.user:
exec_conf = config.user["exec"]

if exec_conf["apiVersion"] == "client.authentication.k8s.io/v1alpha1":
cmd_env_vars = dict(os.environ)
for env_var in exec_conf.get("env") or []:
cmd_env_vars[env_var["name"]] = env_var["value"]

output = subprocess.check_output(
[exec_conf["command"]] + exec_conf["args"], env=cmd_env_vars
)

parsed_out = json.loads(output)
token = parsed_out["status"]["token"]

request.headers["Authorization"] = "Bearer {}".format(token)

elif "auth-provider" in config.user:
auth_provider = config.user["auth-provider"]
if auth_provider.get("name") == "gcp":
Expand Down

0 comments on commit 8602da2

Please sign in to comment.