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

Use the apiversion from KUBERNETES_EXEC_INFO #439

Merged
merged 5 commits into from Mar 30, 2022

Conversation

jyotimahapatra
Copy link
Contributor

@jyotimahapatra jyotimahapatra commented Mar 9, 2022

When using the latest builds of aws-iam-authenticator(v0.5.3-v0.5.5), the default value of apiVersion in the ExecCredential object is client.authentication.k8s.io/v1beta1. This change was done here. However, when using the newer builds, clients have to update the apiVersion in kubeConfig to match the apiVersion being sent as part of the stdout here.
A difference in the values causes errors

Unable to connect to the server: getting credentials: exec plugin is configured to use API version 
client.authentication.k8s.io/v1alpha1, plugin returned version client.authentication.k8s.io/v1beta1

The current PR adds a migration path such that the aws-iam-authenticator will return the apiVersion being used in the KUBERNETES_EXEC_INFO env var being set from the client-go code. This code will be removed in the future after a period of deprecation and with a minor version change in aws-iam-authenticator.

Similar change in aws-cli https://github.com/aws/aws-cli/pull/6476/files

Signed-off-by: Jyoti Mahapatra <jyotima@amazon.com>
Signed-off-by: Jyoti Mahapatra <jyotima@amazon.com>
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 9, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jyotimahapatra

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 9, 2022
Signed-off-by: Jyoti Mahapatra <jyotima@amazon.com>
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 9, 2022
Copy link

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple small questions, @jyotimahapatra but overall looks solid.

@@ -70,6 +72,7 @@ var verifyCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(verifyCmd)
metrics.InitMetrics(prometheus.DefaultRegisterer)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this change unrelated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. it fixes #438
i can get rid of it if causing confusion. it was in my workspace, so i let it be part of the PR

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably would be best to isolate this to a different PR, thanks Jyoti. Then you can link to #438 from that other PR summary :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

pkg/token/token_test.go Outdated Show resolved Hide resolved
@@ -338,11 +341,23 @@ func (g generator) GetWithSTS(clusterID string, stsAPI stsiface.STSAPI) (Token,

// FormatJSON formats the json to support ExecCredential authentication
func (g generator) FormatJSON(token Token) string {
apiVersion := clientauthv1beta1.SchemeGroupVersion.String()
for _, e := range os.Environ() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't parse this manually, instead use LoadExecCredentialFromEnv(). Example usage:

package main

import (
	"fmt"
	"k8s.io/client-go/tools/auth/exec"
)

func main() {
	obj, config, err := exec.LoadExecCredentialFromEnv()
	fmt.Printf("%#v, %#v, %#v\n", obj, config, err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice. Thank you!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like https://github.com/kubernetes/client-go/blob/master/pkg/apis/clientauthentication/types.go#L54-L59 is sending an error ExecCredential does not contain cluster information .. We have to keep this implementation and work on fixing the error in client-go. wdyt?

@@ -70,6 +72,7 @@ var verifyCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(verifyCmd)
metrics.InitMetrics(prometheus.DefaultRegisterer)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes #438

@@ -70,6 +72,7 @@ var verifyCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(verifyCmd)
metrics.InitMetrics(prometheus.DefaultRegisterer)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. it fixes #438
i can get rid of it if causing confusion. it was in my workspace, so i let it be part of the PR

@wongma7
Copy link
Contributor

wongma7 commented Mar 24, 2022

lgtm, works for me . plz squash commits.

in 1.24 alpha api will be removed from client-go and probably kubectl as well, not sure what their migration plan exactly (will there be some way for me to find/replace all the v1alpha1 entries in my kubeconfig??) but we will see

  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      args:
      - token
      - -i
      - cluster-0
      command: aws-iam-authenticator

~/g/s/s/aws-iam-authenticator (try|✚1) $ kubectl version 
ERRO[2022-03-24T12:13:40-07:00] apiVersion client.authentication.k8s.io/v1beta1 
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.3", GitCommit:"ca643a4d1f7bfe34773c74f79527be4afd95bf39", GitTreeState:"clean", BuildDate:"2021-07-15T21:04:39Z", GoVersion:"go1.16.6", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22+", GitVersion:"v1.22.6-eks-7d68063", GitCommit:"f24e667e49fb137336f7b064dba897beed639bad", GitTreeState:"clean", BuildDate:"2022-02-23T19:29:12Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"linux/amd64"}

  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - token
      - -i
      - cluster-0
      command: aws-iam-authenticator

~/g/s/s/aws-iam-authenticator (try|✚1) $ kubectl version
ERRO[2022-03-24T12:13:47-07:00] apiVersion client.authentication.k8s.io/v1alpha1 
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.3", GitCommit:"ca643a4d1f7bfe34773c74f79527be4afd95bf39", GitTreeState:"clean", BuildDate:"2021-07-15T21:04:39Z", GoVersion:"go1.16.6", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22+", GitVersion:"v1.22.6-eks-7d68063", GitCommit:"f24e667e49fb137336f7b064dba897beed639bad", GitTreeState:"clean", BuildDate:"2022-02-23T19:29:12Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"linux/amd64"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants