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

feat: add gke auth command to argocd-k8s-auth (#5958) #9190

Merged
merged 1 commit into from
May 2, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cmd/argocd-k8s-auth/commands/argocd_k8s_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func NewCommand() *cobra.Command {
}

command.AddCommand(newAWSCommand())
command.AddCommand(newGCPCommand())

return command
}
40 changes: 40 additions & 0 deletions cmd/argocd-k8s-auth/commands/gcp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package commands

import (
"context"
"fmt"
"os"

"github.com/spf13/cobra"
"golang.org/x/oauth2/google"

"github.com/argoproj/argo-cd/v2/util/errors"
)

var (
// defaultGCPScopes:
// - cloud-platform is the base scope to authenticate to GCP.
// - userinfo.email is used to authenticate to GKE APIs with gserviceaccount
// email instead of numeric uniqueID.
// https://github.com/kubernetes/client-go/blob/be758edd136e61a1bffadf1c0235fceb8aee8e9e/plugin/pkg/client/auth/gcp/gcp.go#L59
defaultGCPScopes = []string{
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/userinfo.email",
}
)

func newGCPCommand() *cobra.Command {
var command = &cobra.Command{
Use: "gcp",
Run: func(c *cobra.Command, args []string) {
// Preferred way to retrieve GCP credentials
// https://github.com/golang/oauth2/blob/9780585627b5122c8cc9c6a378ac9861507e7551/google/doc.go#L54-L68
cred, err := google.FindDefaultCredentials(context.Background(), defaultGCPScopes...)
errors.CheckError(err)
token, err := cred.TokenSource.Token()
errors.CheckError(err)
_, _ = fmt.Fprint(os.Stdout, formatJSON(token.AccessToken, token.Expiry))
},
}
return command
}
29 changes: 29 additions & 0 deletions docs/operator-manual/declarative-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,35 @@ stringData:
}
```

GKE cluster secret example using argocd-k8s-auth and [Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity):

```yaml
apiVersion: v1
kind: Secret
metadata:
name: mycluster-secret
labels:
argocd.argoproj.io/secret-type: cluster
type: Opaque
stringData:
name: mycluster.com
server: https://mycluster.com
config: |
{
"execProviderConfig": {
"command": "argocd-k8s-auth",
"args": ["gcp"],
"apiVersion": "client.authentication.k8s.io/v1beta1"
},
"tlsClientConfig": {
"insecure": false,
"caData": "<base64 encoded certificate>"
}
}
```

Note that you must enable Workload Identity on your GKE cluster, create GCP service account with appropriate IAM role and bind it to Kubernetes service account for argocd-application-controller and argocd-server (showing Pod logs on UI). See [Use Workload Identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity) and [Authenticating to the Kubernetes API server](https://cloud.google.com/kubernetes-engine/docs/how-to/api-server-authentication).

## Helm Chart Repositories

Non standard Helm Chart repositories have to be registered explicitly.
Expand Down