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(auth): Add the workflow's creator as a label. Closes #2437 #2488

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/openapi-spec/swagger.json
Expand Up @@ -2705,6 +2705,14 @@
}
}
},
"io.argoproj.workflow.v1alpha1.User": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"io.argoproj.workflow.v1alpha1.UserContainer": {
"description": "UserContainer is a container specified by a user.",
"type": "object",
Expand Down Expand Up @@ -3133,6 +3141,9 @@
},
"managedNamespace": {
"type": "string"
},
"user": {
"$ref": "#/definitions/io.argoproj.workflow.v1alpha1.User"
}
}
},
Expand Down
12 changes: 11 additions & 1 deletion cmd/argo/commands/client/conn.go
Expand Up @@ -2,13 +2,17 @@ package client

import (
"context"
"fmt"
"os"
"os/user"

"github.com/argoproj/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"

"github.com/argoproj/argo/pkg/apiclient"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/util/kubeconfig"
)

Expand Down Expand Up @@ -52,6 +56,12 @@ func Namespace() string {
return namespace
}

func GetUser() wfv1.User {
current, err := user.Current()
errors.CheckError(err)
return wfv1.User{Name: current.Username}
}

func GetAuthString() string {
restConfig, err := Config.ClientConfig()
if err != nil {
Expand All @@ -61,5 +71,5 @@ func GetAuthString() string {
if err != nil {
log.Fatal(err)
}
return authString
return fmt.Sprintf("v2/%s/%s", authString, GetUser().Name)
Copy link
Contributor Author

@alexec alexec Mar 20, 2020

Choose a reason for hiding this comment

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

this creates strange looking, but valid tokens:

  • v2/Bearer 34534==/alex

}
3 changes: 2 additions & 1 deletion cmd/argo/commands/server.go
Expand Up @@ -14,6 +14,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/argoproj/argo/cmd/argo/commands/client"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
wfclientset "github.com/argoproj/argo/pkg/client/clientset/versioned"
"github.com/argoproj/argo/server/apiserver"
"github.com/argoproj/argo/util/help"
Expand Down Expand Up @@ -68,13 +69,13 @@ See %s`, help.ArgoSever),
"managedNamespace": managedNamespace,
"baseHRef": baseHRef}).
Info()

opts := apiserver.ArgoServerOpts{
BaseHRef: baseHRef,
Namespace: namespace,
WfClientSet: wflientset,
KubeClientset: kubeConfig,
RestConfig: config,
User: wfv1.NullUser,
AuthMode: authMode,
ManagedNamespace: managedNamespace,
ConfigName: configMap,
Expand Down
1 change: 1 addition & 0 deletions pkg/apiclient/apiclient.go
Expand Up @@ -19,6 +19,7 @@ type Client interface {
}

func NewClient(argoServer string, authSupplier func() string, clientConfig clientcmd.ClientConfig) (context.Context, Client, error) {

if argoServer != "" {
return newArgoServerClient(argoServer, authSupplier())
} else {
Expand Down
8 changes: 7 additions & 1 deletion pkg/apiclient/argo-kube-client.go
Expand Up @@ -3,6 +3,7 @@ package apiclient
import (
"context"
"fmt"
"os/user"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -12,6 +13,7 @@ import (
workflowpkg "github.com/argoproj/argo/pkg/apiclient/workflow"
workflowarchivepkg "github.com/argoproj/argo/pkg/apiclient/workflowarchive"
"github.com/argoproj/argo/pkg/apiclient/workflowtemplate"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/pkg/client/clientset/versioned"
"github.com/argoproj/argo/server/auth"
cronworkflowserver "github.com/argoproj/argo/server/cronworkflow"
Expand All @@ -38,7 +40,11 @@ func newArgoKubeClient(clientConfig clientcmd.ClientConfig) (context.Context, Cl
if err != nil {
return nil, nil, err
}
gatekeeper := auth.NewGatekeeper(auth.Server, wfClient, kubeClient, restConfig)
current, err := user.Current()
if err != nil {
return nil, nil, err
}
gatekeeper := auth.NewGatekeeper(auth.Server, wfClient, kubeClient, restConfig, wfv1.User{Name: current.Name})
ctx, err := gatekeeper.Context(context.Background())
if err != nil {
return nil, nil, err
Expand Down
109 changes: 85 additions & 24 deletions pkg/apiclient/info/info.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/apiclient/info/info.proto
Expand Up @@ -15,6 +15,7 @@ message GetInfoRequest {
message InfoResponse {
string managedNamespace = 1;
repeated github.com.argoproj.argo.pkg.apis.workflow.v1alpha1.Link links = 2;
github.com.argoproj.argo.pkg.apis.workflow.v1alpha1.User user = 3;
}

service InfoService {
Expand Down
11 changes: 11 additions & 0 deletions pkg/apiclient/info/info.swagger.json
Expand Up @@ -47,6 +47,14 @@
},
"title": "A link to another app.\n+patchStrategy=merge\n+patchMergeKey=name"
},
"github.com.argoproj.argo.pkg.apis.workflow.v1alpha1.User": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"info.InfoResponse": {
"type": "object",
"properties": {
Expand All @@ -58,6 +66,9 @@
"items": {
"$ref": "#/definitions/github.com.argoproj.argo.pkg.apis.workflow.v1alpha1.Link"
}
},
"user": {
"$ref": "#/definitions/github.com.argoproj.argo.pkg.apis.workflow.v1alpha1.User"
}
}
}
Expand Down