Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2308: kubeconfig with external authentication command doesn't work #2381

Merged
merged 1 commit into from Aug 21, 2020

Conversation

rohanKanojia
Copy link
Member

@rohanKanojia rohanKanojia commented Jul 31, 2020

Description

Fix #2308

Iterate over PATH values in order to find correct absolute path for command being executed.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@rohanKanojia
Copy link
Member Author

retest this please

@rohanKanojia
Copy link
Member Author

Steps to test

  • Create a script which returns your auth token:
#! /bin/bash

date >> /home/rohaan/run-log
echo "{\"kind\": \"ExecCredential\", \"apiVersion\": \"client.authentication.k8s.io/v1alpha1\",\"status\":{\"token\":\"your-token\"}, \"spec\": {}}"
  • Place this script in some directory not in your $PATH, I placed it in /home/rohaan/temp-scripts/testScript
  • Add script to your $PATH
export PATH=$HOME/temp-scripts:$PATH
  • Edit users section of your .kube/config file to add exec section for this script to execute:
- name: rohanKanojia/api-rh-idev-openshift-com:443
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      command: testScript
  • Check whether kubectl is working after modifying .kube/config, also each run of script populates run-log
~ : $ kubectl get pods
NAME               READY   STATUS      RESTARTS   AGE
demo-1-t5l9n       1/1     Running     0          4h
demo-s2i-2-build   0/1     Completed   0          4h
~ : $ cat run-log 
Fri 07 Aug 2020 04:52:46 PM IST
  • Do the same thing from kubernetes-client:
try (KubernetesClient client = new DefaultKubernetesClient()) {
    PodList podList = client.pods().inNamespace("rokumar").list();
    podList.getItems().forEach(p -> System.out.println(p.getMetadata().getName()));
}

@rohanKanojia rohanKanojia force-pushed the pr/issue2308 branch 2 times, most recently from 31af911 to fa0baf9 Compare August 7, 2020 11:36
@manusa
Copy link
Member

manusa commented Aug 21, 2020

Following (testScript.bat) script can be used from a Windows OS:

@echo off
for /f "delims=" %%i in ('date /t') do (set curr_date=%%i)
echo %curr_date%_%TIME% >>00_kube_auth_log.txt
echo {"kind": "ExecCredential", "apiVersion": "client.authentication.k8s.io/v1alpha1","status":{"token":"your_SECRET_token"}, "spec": {}}

@manusa
Copy link
Member

manusa commented Aug 21, 2020

Tested on Windows, provided test scenario works well.

@sonarcloud
Copy link

sonarcloud bot commented Aug 21, 2020

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

72.0% 72.0% Coverage
0.0% 0.0% Duplication

@manusa
Copy link
Member

manusa commented Aug 21, 2020

[merge]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.kube/config with external authentication command doesn't work
4 participants