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

Feature: Implement vcpctl create solution user for CCM (Stage 2) #44

Merged
merged 1 commit into from
Sep 4, 2018

Conversation

fanzhangio
Copy link

@fanzhangio fanzhangio commented Aug 23, 2018

  • Add Client for delegating vim25 and ssoadmin
  • Add Credential for client, session and sso
  • Add CreateUserFunc for creating solution user and person user
  • Implement creating default solution user and granting WSTrust
    permission and Administrator role.

fixes #15

Special notes for your reviewer:
Stage 2 for vcpctl implementation

Release note:
NONE

none

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 23, 2018
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 23, 2018
@fanzhangio
Copy link
Author

/assign

Copy link
Member

@frapposelli frapposelli left a comment

Choose a reason for hiding this comment

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

just a couple of comments to be addressed.

@dougm PTAL at the solution user create process

pkg/cli/cli.go Outdated
u.solution.Certificate = cert
}
if u.solution.Certificate == "" {
return fmt.Errorf("Need solution user certificate (--cert) to create solution user\n")
Copy link
Member

Choose a reason for hiding this comment

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

What are the steps to create/fetch this certificate?

Copy link
Author

Choose a reason for hiding this comment

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

A vCenter Solution User can only use public key authentication via SAML, a Solution User does not have a plain text password. So the SSO_TOKEN needs to be provided (by ENV currently). This solution.Certificate contains the cert data decoded from crt file.
In command line, the cert file need to be passed to --cert flag.

--cert  k8s-vcp.crt

It stores the raw data in ClientOption, and decoded into User.solution.Certificate

Copy link
Member

Choose a reason for hiding this comment

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

We could add an option to generate the key pair too, can wait for a later PR though.

Copy link
Member

Choose a reason for hiding this comment

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

Trailing \n should be removed from the error message.

pkg/cli/util.go Outdated
return "https://username:password@" + ip.String() + "/sdk"
}
}
return "https://username:password@host/sdk"
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little puzzled on why you need to hardcode username:password in the URL here.

Also, seems like url.Parse would be more suitable for the type of parsing you're doing here.

Copy link
Author

Choose a reason for hiding this comment

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

The basic idea is to initialize UserInfo with username and password. The following
processCredential() call will overwrite the actual credentials based on the Credential strategy.

type Credential struct {
	username string
	password string
	cert     string
	Secrete  VCCMSecret
}
  1. declarative username and password
  2. Secrete in k8s

Copy link
Member

Choose a reason for hiding this comment

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

soap.ParseURL can be used here instead? ok to initialize UserInfo, but it should be with empty "" username and password.

Copy link
Author

@fanzhangio fanzhangio left a comment

Choose a reason for hiding this comment

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

@frapposelli
Thanks for your comments !

pkg/cli/util.go Outdated
if v == "https" || v == "http" {
continue
}
ip = net.ParseIP(v)
Copy link
Author

Choose a reason for hiding this comment

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

There is a small bug in for range loop, where token v should be trimmed by //

v = strings.Trim(v, "//")

Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

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

A few minor suggestions, otherwise looking good @fanzhangio

provisionCmd.Flags().StringVar(&vcport, "vcport", "", "specify vCenter Port ")
provisionCmd.Flags().StringVar(&vcUser, "vcuser", "", "specify vCenter user ")
provisionCmd.Flags().StringVar(&vcPassword, "vcpassword", "", "specify vCenter Password ")
provisionCmd.Flags().StringVar(&vchost, "host", "", "specify vCenter IP ")
Copy link
Member

Choose a reason for hiding this comment

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

Flag descriptions should start with an uppercase letter, and not have a trailing space.

Copy link
Author

Choose a reason for hiding this comment

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

done

pkg/cli/cli.go Outdated
u.solution.Certificate = cert
}
if u.solution.Certificate == "" {
return fmt.Errorf("Need solution user certificate (--cert) to create solution user\n")
Copy link
Member

Choose a reason for hiding this comment

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

We could add an option to generate the key pair too, can wait for a later PR though.

pkg/cli/cli.go Outdated
u.solution.Certificate = cert
}
if u.solution.Certificate == "" {
return fmt.Errorf("Need solution user certificate (--cert) to create solution user\n")
Copy link
Member

Choose a reason for hiding this comment

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

Trailing \n should be removed from the error message.

pkg/cli/cli.go Outdated
}
p := types.PrincipalId{Name: "k8s-vcp", Domain: c.Domain}

if _, err := c.SetRole(ctx, p, "Administrator"); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Role should probably be a flag, we can default to Administrator. A separate feature for vcpctl could be to create a role with the minimum set of privileges required by VCP.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, added a flag for role (default is Administrator).
Create Role could be in separate PR.

username string
password string
cert string
Secrete VCCMSecret
Copy link
Member

Choose a reason for hiding this comment

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

Secrete -> Secret

Copy link
Author

Choose a reason for hiding this comment

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

Done

o.credential = c
}

func (c Credential) setPassowrd(p string) {
Copy link
Member

Choose a reason for hiding this comment

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

setPassowrd -> setPassword

Copy link
Member

Choose a reason for hiding this comment

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

Why the getters and setters here, rather than just use the fields directly?

Copy link
Author

Choose a reason for hiding this comment

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

Removed setters and getters.

@@ -22,6 +22,10 @@ import (
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphere"
)

// Config represents configuration of cpv
Copy link
Member

Choose a reason for hiding this comment

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

cpv -> vcp

Copy link
Author

Choose a reason for hiding this comment

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

Done.

pkg/cli/user.go Outdated
return err
}

// SSO admin server has its own session manager. There is no SSO token persistence yet, so just use an env
Copy link
Member

Choose a reason for hiding this comment

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

The persistence comment only applied to govc - sessions are persisted by default by govc in ~/.govmomi/sessions

pkg/cli/util.go Outdated
return "https://username:password@" + ip.String() + "/sdk"
}
}
return "https://username:password@host/sdk"
Copy link
Member

Choose a reason for hiding this comment

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

soap.ParseURL can be used here instead? ok to initialize UserInfo, but it should be with empty "" username and password.

- Add Client for delegating vim25 and ssoadmin
- Add Credential for client, session and sso
- Add CreateUserFunc for creating solution user and person user
- Implement creating default solution user and granting WSTrust
permission and Administrator role.
Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 4, 2018
@frapposelli
Copy link
Member

/lgtm
/approve

👍

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: frapposelli

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 4, 2018
@k8s-ci-robot k8s-ci-robot merged commit 5347344 into kubernetes:master Sep 4, 2018
@fanzhangio fanzhangio changed the title Feature: Implement vcpctl create solution user for CCM Feature: Implement vcpctl create solution user for CCM (Stage 2) Sep 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create vcpctl tool to facilitate CCM provisioning
4 participants