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

support ExecCredential authentication #36

Merged
merged 6 commits into from
Jan 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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