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
Changes from 3 commits
a701bd0
837a59e
5037775
095a4ad
cb19d5f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,11 @@ import ( | |
"fmt" | ||
"os" | ||
|
||
"sigs.k8s.io/aws-iam-authenticator/pkg/metrics" | ||
"sigs.k8s.io/aws-iam-authenticator/pkg/token" | ||
|
||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
@@ -70,6 +72,7 @@ var verifyCmd = &cobra.Command{ | |
|
||
func init() { | ||
rootCmd.AddCommand(verifyCmd) | ||
metrics.InitMetrics(prometheus.DefaultRegisterer) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this change unrelated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. it fixes #438 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do |
||
verifyCmd.Flags().StringP("token", "t", "", "Token to verify") | ||
verifyCmd.Flags().StringP("output", "o", "", "Output format. Only `json` is supported currently.") | ||
viper.BindPFlag("token", verifyCmd.Flags().Lookup("token")) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ import ( | |
"github.com/aws/aws-sdk-go/service/sts/stsiface" | ||
"github.com/sirupsen/logrus" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/pkg/apis/clientauthentication" | ||
clientauthv1beta1 "k8s.io/client-go/pkg/apis/clientauthentication/v1beta1" | ||
"sigs.k8s.io/aws-iam-authenticator/pkg" | ||
"sigs.k8s.io/aws-iam-authenticator/pkg/arn" | ||
|
@@ -89,7 +90,9 @@ const ( | |
clusterIDHeader = "x-k8s-aws-id" | ||
// Format of the X-Amz-Date header used for expiration | ||
// https://golang.org/pkg/time/#pkg-constants | ||
dateHeaderFormat = "20060102T150405Z" | ||
dateHeaderFormat = "20060102T150405Z" | ||
kindExecCredential = "ExecCredential" | ||
execInfoEnvKey = "KUBERNETES_EXEC_INFO" | ||
) | ||
|
||
// Token is generated and used by Kubernetes client-go to authenticate with a Kubernetes cluster. | ||
|
@@ -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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't parse this manually, instead use
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice. Thank you!! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
pair := strings.SplitN(e, "=", 2) | ||
if pair[0] == execInfoEnvKey { | ||
cred := &clientauthentication.ExecCredential{} | ||
if err := json.Unmarshal([]byte(pair[1]), cred); err == nil { | ||
apiVersion = cred.APIVersion | ||
} | ||
break | ||
} | ||
} | ||
|
||
expirationTimestamp := metav1.NewTime(token.Expiration) | ||
execInput := &clientauthv1beta1.ExecCredential{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "client.authentication.k8s.io/v1beta1", | ||
Kind: "ExecCredential", | ||
APIVersion: apiVersion, | ||
Kind: kindExecCredential, | ||
}, | ||
Status: &clientauthv1beta1.ExecCredentialStatus{ | ||
ExpirationTimestamp: &expirationTimestamp, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixes #438