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

Commit 8602da2

Browse files
dash1291zoidyzoidzoiddlmiddlecote
authored andcommitted
support ExecCredential authentication (#36)
* 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]>
1 parent 045e597 commit 8602da2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pykube/http.py

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import posixpath
88
import shlex
99
import subprocess
10+
import os
1011

1112
try:
1213
import google.auth
@@ -98,6 +99,24 @@ def send(self, request, **kwargs):
9899
pass
99100
elif "token" in config.user and config.user["token"]:
100101
request.headers["Authorization"] = "Bearer {}".format(config.user["token"])
102+
103+
elif "exec" in config.user:
104+
exec_conf = config.user["exec"]
105+
106+
if exec_conf["apiVersion"] == "client.authentication.k8s.io/v1alpha1":
107+
cmd_env_vars = dict(os.environ)
108+
for env_var in exec_conf.get("env") or []:
109+
cmd_env_vars[env_var["name"]] = env_var["value"]
110+
111+
output = subprocess.check_output(
112+
[exec_conf["command"]] + exec_conf["args"], env=cmd_env_vars
113+
)
114+
115+
parsed_out = json.loads(output)
116+
token = parsed_out["status"]["token"]
117+
118+
request.headers["Authorization"] = "Bearer {}".format(token)
119+
101120
elif "auth-provider" in config.user:
102121
auth_provider = config.user["auth-provider"]
103122
if auth_provider.get("name") == "gcp":

0 commit comments

Comments
 (0)