Skip to content

Commit

Permalink
Adding Support for kubectl ExecCredential output
Browse files Browse the repository at this point in the history
**Why:**

* Allows you to use the `heptio-authenticator-aws` binary in your
`~/.kube/config` as an external authProvider

**Usage:**

```yaml

users:
- name: user
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      command: heptio-authenticator-aws
      args:
        - "token"
        - "--cluster-id"
        - "cluster-id"
```

**This change addresses the need by:**

* closes kubernetes-sigs#64

Signed-off-by: Christopher Hein <me@christopherhein.com>
  • Loading branch information
christopherhein committed Apr 9, 2018
1 parent d282f87 commit faa0204
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/heptio-authenticator-aws/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ var tokenCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "could not get token: %v\n", err)
os.Exit(1)
}
fmt.Println(tok)

enc := gen.FormatJSON(tok)
fmt.Println(enc)
},
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/heptio/authenticator/pkg/arn"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientauthv1alpha1 "k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1"
)

// Identity is returned on successful Verify() results. It contains a parsed
Expand Down Expand Up @@ -125,6 +127,8 @@ type Generator interface {
Get(string) (string, error)
// GetWithRole creates a token by assuming the provided role, using the credentials in the default chain.
GetWithRole(clusterID, roleARN string) (string, error)
// FormatJSON returns the client auth formatted json for the execcredential auth
FormatJSON(string) string
}

type generator struct {
Expand Down Expand Up @@ -180,6 +184,21 @@ func (g generator) GetWithRole(clusterID string, roleARN string) (string, error)
return v1Prefix + base64.RawURLEncoding.EncodeToString([]byte(presignedURLString)), nil
}

// FormatJSON formats the json to support 1.10 external authProvider
func (g generator) FormatJSON(token string) string {
execInput := &clientauthv1alpha1.ExecCredential{
TypeMeta: metav1.TypeMeta{
APIVersion: "client.authentication.k8s.io/v1alpha1",
Kind: "ExecCredential",
},
Status: &clientauthv1alpha1.ExecCredentialStatus{
Token: token,
},
}
enc, _ := json.Marshal(execInput)
return string(enc)
}

// Verifier validates tokens by calling STS and returning the associated identity.
type Verifier interface {
Verify(token string) (*Identity, error)
Expand Down

0 comments on commit faa0204

Please sign in to comment.