Skip to content
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
6 changes: 5 additions & 1 deletion Gopkg.lock

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

1 change: 1 addition & 0 deletions cmd/argocd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewCommand() *cobra.Command {
command.AddCommand(NewRepoCommand(&clientOpts))
command.AddCommand(NewContextCommand(&clientOpts))
command.AddCommand(NewProjectCommand(&clientOpts))
command.AddCommand(NewUsersCommand(&clientOpts))

defaultLocalConfigPath, err := localconfig.DefaultLocalConfigPath()
errors.CheckError(err)
Expand Down
77 changes: 77 additions & 0 deletions cmd/argocd/commands/users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package commands

import (
"context"
"fmt"
"os"
"syscall"

"github.com/argoproj/argo-cd/errors"
argocdclient "github.com/argoproj/argo-cd/pkg/apiclient"
"github.com/argoproj/argo-cd/server/users"
"github.com/argoproj/argo-cd/util"
"github.com/argoproj/argo-cd/util/settings"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)

func NewUsersCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
var command = &cobra.Command{
Use: "users",
Short: "Manage users",
Run: func(c *cobra.Command, args []string) {
c.HelpFunc()(c, args)
os.Exit(1)
},
}
command.AddCommand(NewUsersChangePasswordCommand(clientOpts))
return command
}

func NewUsersChangePasswordCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
var (
CurrentPassword string
NewPassword string
)
var command = &cobra.Command{
Use: "change-password USERNAME",
Short: "Change User Password",
Run: func(c *cobra.Command, args []string) {
if len(args) == 0 {
c.HelpFunc()(c, args)
os.Exit(1)
}

if CurrentPassword == "" {
fmt.Print("*** Enter your Current Password password ")
password, err := terminal.ReadPassword(syscall.Stdin)
errors.CheckError(err)
CurrentPassword = string(password)
fmt.Print("\n")
}
if NewPassword == "" {
NewPassword = settings.ReadAndConfirmPassword()
}

userName := args[0]
body := users.Body{
CurrentPassword: CurrentPassword,
NewPassword: NewPassword,
}
UpdatePasswordRequest := users.UpdatePasswordRequest{
Name: userName,
Body: &body,
}

conn, usrIf := argocdclient.NewClientOrDie(clientOpts).NewUsersClientOrDie()
defer util.Close(conn)
_, err := usrIf.UpdatePassword(context.Background(), &UpdatePasswordRequest)
errors.CheckError(err)
fmt.Printf("password for user %s updated to %s \n", userName, NewPassword)
},
}

command.Flags().StringVar(&CurrentPassword, "current-password", "", "current password you wish to change")
command.Flags().StringVar(&NewPassword, "new-password", "", "new password you want to update to")
return command
}
20 changes: 20 additions & 0 deletions pkg/apiclient/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/argoproj/argo-cd/server/repository"
"github.com/argoproj/argo-cd/server/session"
"github.com/argoproj/argo-cd/server/settings"
"github.com/argoproj/argo-cd/server/users"
"github.com/argoproj/argo-cd/server/version"
grpc_util "github.com/argoproj/argo-cd/util/grpc"
"github.com/argoproj/argo-cd/util/localconfig"
Expand Down Expand Up @@ -51,6 +52,8 @@ type Client interface {
NewVersionClientOrDie() (*grpc.ClientConn, version.VersionServiceClient)
NewProjectClient() (*grpc.ClientConn, project.ProjectServiceClient, error)
NewProjectClientOrDie() (*grpc.ClientConn, project.ProjectServiceClient)
NewUsersClient() (*grpc.ClientConn, users.UsersServiceClient, error)
NewUsersClientOrDie() (*grpc.ClientConn, users.UsersServiceClient)
}

// ClientOptions hold address, security, and other settings for the API client.
Expand Down Expand Up @@ -312,3 +315,20 @@ func (c *client) NewProjectClientOrDie() (*grpc.ClientConn, project.ProjectServi
}
return conn, projIf
}

func (c *client) NewUsersClient() (*grpc.ClientConn, users.UsersServiceClient, error) {
conn, err := c.NewConn()
if err != nil {
return nil, nil, err
}
usrIf := users.NewUsersServiceClient(conn)
return conn, usrIf, nil
}

func (c *client) NewUsersClientOrDie() (*grpc.ClientConn, users.UsersServiceClient) {
conn, usrIf, err := c.NewUsersClient()
if err != nil {
log.Fatalf("Failed to establish connection to %s: %v", c.ServerAddr, err)
}
return conn, usrIf
}
4 changes: 2 additions & 2 deletions pkg/apis/application/v1alpha1/generated.proto

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

4 changes: 3 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/argoproj/argo-cd/server/repository"
"github.com/argoproj/argo-cd/server/session"
"github.com/argoproj/argo-cd/server/settings"
"github.com/argoproj/argo-cd/server/users"
"github.com/argoproj/argo-cd/server/version"
"github.com/argoproj/argo-cd/util"
"github.com/argoproj/argo-cd/util/db"
Expand Down Expand Up @@ -323,14 +324,15 @@ func (a *ArgoCDServer) newGRPCServer() *grpc.Server {
applicationService := application.NewServer(a.Namespace, a.KubeClientset, a.AppClientset, a.RepoClientset, db, a.enf, projectLock)
projectService := project.NewServer(a.Namespace, a.AppClientset, a.enf, projectLock)
settingsService := settings.NewServer(a.settingsMgr)
usersService := users.NewServer(a.sessionMgr, a.settingsMgr)
version.RegisterVersionServiceServer(grpcS, &version.Server{})
cluster.RegisterClusterServiceServer(grpcS, clusterService)
application.RegisterApplicationServiceServer(grpcS, applicationService)
repository.RegisterRepositoryServiceServer(grpcS, repoService)
session.RegisterSessionServiceServer(grpcS, sessionService)
settings.RegisterSettingsServiceServer(grpcS, settingsService)
project.RegisterProjectServiceServer(grpcS, projectService)

users.RegisterUsersServiceServer(grpcS, usersService)
// Register reflection service on gRPC server.
reflection.Register(grpcS)
return grpcS
Expand Down
65 changes: 56 additions & 9 deletions server/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ApplicationService"
],
"summary": "List returns list of applications",
"operationId": "ListMixin5",
"operationId": "ListMixin6",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -58,7 +58,7 @@
"ApplicationService"
],
"summary": "Create creates an application",
"operationId": "CreateMixin5",
"operationId": "CreateMixin6",
"parameters": [
{
"name": "body",
Expand All @@ -85,7 +85,7 @@
"ApplicationService"
],
"summary": "Update updates an application",
"operationId": "UpdateMixin5",
"operationId": "UpdateMixin6",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -118,7 +118,7 @@
"ApplicationService"
],
"summary": "Get returns an application by name",
"operationId": "GetMixin5",
"operationId": "GetMixin6",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -155,7 +155,7 @@
"ApplicationService"
],
"summary": "Delete deletes an application",
"operationId": "DeleteMixin5",
"operationId": "DeleteMixin6",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -865,7 +865,7 @@
"SessionService"
],
"summary": "Create a new JWT for authentication and set a cookie if using HTTP.",
"operationId": "CreateMixin6",
"operationId": "CreateMixin7",
"parameters": [
{
"name": "body",
Expand All @@ -890,7 +890,7 @@
"SessionService"
],
"summary": "Delete an existing JWT cookie if using HTTP.",
"operationId": "DeleteMixin6",
"operationId": "DeleteMixin7",
"responses": {
"200": {
"description": "(empty)",
Expand Down Expand Up @@ -956,6 +956,39 @@
}
}
},
"/api/v1/users/{name}/password": {
"put": {
"tags": [
"UsersService"
],
"summary": "Update updates an application",
"operationId": "UpdatePassword",
"parameters": [
{
"type": "string",
"name": "name",
"in": "path",
"required": true
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/usersBody"
}
}
],
"responses": {
"200": {
"description": "(empty)",
"schema": {
"$ref": "#/definitions/usersUpdatePasswordResponse"
}
}
}
}
},
"/api/version": {
"get": {
"tags": [
Expand Down Expand Up @@ -1285,6 +1318,20 @@
}
}
},
"usersBody": {
"type": "object",
"properties": {
"currentPassword": {
"type": "string"
},
"newPassword": {
"type": "string"
}
}
},
"usersUpdatePasswordResponse": {
"type": "object"
},
"v1Event": {
"description": "Event is a report of an event somewhere in the cluster.",
"type": "object",
Expand Down Expand Up @@ -1968,11 +2015,11 @@
"properties": {
"apiVersion": {
"type": "string",
"title": "Name is the resource name"
"title": "APIVersion is the resource API version"
},
"kind": {
"type": "string",
"title": "Name is the resource name"
"title": "Kind is the resource kind"
},
"message": {
"description": "A human readable message indicating details about why the resource is in this condition.",
Expand Down
52 changes: 52 additions & 0 deletions server/users/users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package users

import (
"github.com/argoproj/argo-cd/util/password"
"github.com/argoproj/argo-cd/util/session"
"github.com/argoproj/argo-cd/util/settings"
"golang.org/x/net/context"
)

// Server provides a Session service
type Server struct {
sessionMgr *session.SessionManager
settingsMgr *settings.SettingsManager
}

// NewServer returns a new instance of the Session service
func NewServer(sessionMgr *session.SessionManager, settingsMgr *settings.SettingsManager) *Server {
return &Server{
sessionMgr: sessionMgr,
settingsMgr: settingsMgr,
}

}

//UpdatePassword is used to Update a User's Passwords
func (s *Server) UpdatePassword(ctx context.Context, q *UpdatePasswordRequest) (*UpdatePasswordResponse, error) {

cdSettings, err := s.settingsMgr.GetSettings()
if err != nil {
return nil, err
}

err = s.sessionMgr.VerifyUsernamePassword(q.Name, q.Body.GetCurrentPassword())
if err != nil {
return nil, err
}

hashedPassword, err := password.HashPassword(q.Body.GetNewPassword())
if err != nil {
return nil, err
}

cdSettings.LocalUsers[q.Name] = hashedPassword

err = s.settingsMgr.SaveSettings(cdSettings)
if err != nil {
return nil, err
}

return nil, nil

}
Loading