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

iSCSI CHAP support #43396

Merged
merged 4 commits into from
Apr 7, 2017
Merged

iSCSI CHAP support #43396

merged 4 commits into from
Apr 7, 2017

Conversation

rootfs
Copy link
Contributor

@rootfs rootfs commented Mar 20, 2017

What this PR does / why we need it:
To support CHAP authentication in a multi-tenant setup
Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Special notes for your reviewer:

Release note:

Support iSCSI CHAP authentication

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 20, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@rootfs rootfs changed the title Iscsi CHAP support iSCSI CHAP support Mar 20, 2017
@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Mar 20, 2017
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 20, 2017
@rootfs
Copy link
Contributor Author

rootfs commented Mar 20, 2017

@fabiand

@rootfs
Copy link
Contributor Author

rootfs commented Mar 20, 2017

@kubernetes/sig-storage-misc

@rootfs
Copy link
Contributor Author

rootfs commented Mar 20, 2017

/assign @jsafrane

pkg/api/types.go Outdated
// Optional: whether support iSCSI Session CHAP authentication
// +optional
SessionCHAPAuth bool
// Optional: CHAP secret for iSCSI target and initiator authentication
Copy link
Member

Choose a reason for hiding this comment

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

Please add a note when this parameter is required.

@@ -580,6 +580,9 @@ func validateISCSIVolumeSource(iscsi *api.ISCSIVolumeSource, fldPath *field.Path
if iscsi.Lun < 0 || iscsi.Lun > 255 {
allErrs = append(allErrs, field.Invalid(fldPath.Child("lun"), iscsi.Lun, validation.InclusiveRangeError(0, 255)))
}
if iscsi.DiscoveryCHAPAuth == true && iscsi.SessionCHAPAuth == true && iscsi.SecretRef == nil {
Copy link
Member

Choose a reason for hiding this comment

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

the unit test below expects (iscsi.DiscoveryCHAPAuth == true || iscsi.SessionCHAPAuth == true) && iscsi.SecretRef == nil. And checking for boolVariable == true looks weird...

}

}
for _, k := range chap_st {
Copy link
Member

Choose a reason for hiding this comment

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

do we want to fill the username/secret when b.chap_discovery is false?

}

}
for _, k := range chap_sess {
Copy link
Member

Choose a reason for hiding this comment

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

do we want to fill the username/secret when b.chap_session is false?

// build discoverydb and discover iscsi target
b.plugin.execCommand("iscsiadm", []string{"-m", "discoverydb", "-t", "sendtargets", "-p", tp, "-I", b.iface, "-o", "new"})
// update discoverydb with CHAP secret
err = updateISCSIDiscoverydb(b, tp)
Copy link
Member

Choose a reason for hiding this comment

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

You should clear username/password on error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

last_err = fmt.Errorf("iscsi: failed to sendtargets to portal %s output: %s, err %v", tp, string(out), err)
continue
}
err = updateISCSINode(b, tp)
Copy link
Member

Choose a reason for hiding this comment

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

You should clear username/password on error

// update discoverydb with CHAP secret
err = updateISCSIDiscoverydb(b, tp)
if err != nil {
last_err = fmt.Errorf("iscsi: failed to update discoverydb to portal %s error: %v", tp, err)
Copy link
Member

Choose a reason for hiding this comment

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

IMO you should log the errors here (and everywhere where last_err is used), maybe as warnings or info, so we can see all the errors and not only the last one in the logs.

@@ -133,16 +188,28 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) error {
}
exist := waitForPathToExist(devicePath, 1, iscsiTransport)
Copy link
Member

Choose a reason for hiding this comment

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

Can this waitForPathToExist ever succeed if we know that CHAP is enabled and we did not set username / password? IMO it adds unnecessary 1 second delay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is to detect if the devices are already created. 1 is retry.

@@ -307,6 +307,13 @@ func (util *ISCSIUtil) DetachDisk(c iscsiDiskUnmounter, mntPath string) error {
glog.Errorf("iscsi: failed to detach disk Error: %s", string(out))
}
}
// delete the node record from database
Copy link
Member

Choose a reason for hiding this comment

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

this does not look like README change

@piosz piosz assigned saad-ali and unassigned piosz Mar 22, 2017
// whether support iSCSI Discovery CHAP authentication
// +optional
optional bool chapAuthDiscovery = 8;

Copy link
Contributor

Choose a reason for hiding this comment

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

@rootfs did we deliberately left "9" or Am I missing something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is generated code

Copy link
Contributor

Choose a reason for hiding this comment

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

ah.. yes. missed that part.

if source.SecretRef != nil {
if secret, err = ioutil.GetSecretForPod(pod, source.SecretRef.Name, plugin.host.GetKubeClient()); err != nil {
glog.Errorf("Couldn't get secret from %v/%v", pod.Namespace, source.SecretRef)
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

@rootfs checking secret in pod's namespace is good enough ? or do we need to have an option for specifying a 'namespace' for this secret?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This uses pod's namespace. Referencing across namespaces is not guaranteed to succeed.

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 27, 2017
@rootfs
Copy link
Contributor Author

rootfs commented Mar 28, 2017

@k8s-bot bazel test this

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 5, 2017
@humblec
Copy link
Contributor

humblec commented Apr 5, 2017

LGTM.

Signed-off-by: Huamin Chen <[email protected]>
Signed-off-by: Huamin Chen <[email protected]>
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 5, 2017
@rootfs
Copy link
Contributor Author

rootfs commented Apr 5, 2017

@k8s-bot non-cri e2e test this

@thockin
Copy link
Member

thockin commented Apr 5, 2017

/approve

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 5, 2017
@rootfs
Copy link
Contributor Author

rootfs commented Apr 5, 2017

thank you @thockin

@rootfs
Copy link
Contributor Author

rootfs commented Apr 5, 2017

@jsafrane PTAL, thanks!

@saad-ali
Copy link
Member

saad-ali commented Apr 6, 2017

lgtm will defer final lgtm to @jsafrane

}
err = updateISCSINode(b, tp)
if err != nil {
last_err = fmt.Errorf("iscsi: failed to update iscsi node to portal %s error: %v", tp, err)
Copy link
Member

Choose a reason for hiding this comment

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

missing iscsiadm -m discoverydb .. -o delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

keep the discoverydb there in case there is another open session using the same sendtarget.

glog.Errorf("iscsi: failed to attach disk:Error: %s (%v)", string(out), err)
// delete the node record from database
b.plugin.execCommand("iscsiadm", []string{"-m", "node", "-p", tp, "-I", b.iface, "-T", b.iqn, "-o", "delete"})
last_err = fmt.Errorf("iscsi: failed to attach disk:Error: %s (%v)", string(out), err)
Copy link
Member

Choose a reason for hiding this comment

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

five lines below, there is "Could not attach disk: Timeout after 10s" error. Should it update last_err? Should it delete node records?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@@ -105,6 +157,7 @@ func (util *ISCSIUtil) AttachDisk(b iscsiDiskMounter) error {
var devicePath string
var devicePaths []string
var iscsiTransport string
var last_err error
Copy link
Member

Choose a reason for hiding this comment

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

lastErr


### CHAP Secret

As illustrated in [chap-secret.yaml](chap-secret.yaml), the secret consists of the following keys:
Copy link
Member

Choose a reason for hiding this comment

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

"must have type kubernetes.io/iscsi-chap and consists of the following keys"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


These keys map to those used by Open-iSCSI initiator. Detailed documents on these keys can be found at [Open-iSCSI](https://github.com/open-iscsi/open-iscsi/blob/master/etc/iscsid.conf)

Note, all user names and passwords must be base64 encoded in the secret.
Copy link
Member

Choose a reason for hiding this comment

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

That's IMO misleading. We use base64 to encode all secret values in the yaml just for easier transport, it's not something CHAP specific. E.g. on command line we use plaintext:

$ kubectl create secret generic my-secret --from-literal=discovery.sendtargets.auth.username=alibaba --from-literal=discovery.sendtargets.auth.password=opensesame -o yaml
kind: Secret
data:
  discovery.sendtargets.auth.password: b3BlbnNlc2FtZQ==
  discovery.sendtargets.auth.username: YWxpYmFiYQ==

It's not like RBD, where the passwords must be encoded into base64 twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@rootfs rootfs force-pushed the iscsi-chap branch 2 times, most recently from 73f8920 to f9ee03a Compare April 6, 2017 14:04
@jsafrane
Copy link
Member

jsafrane commented Apr 7, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 7, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jsafrane, rootfs, thockin

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@rootfs
Copy link
Contributor Author

rootfs commented Apr 7, 2017

thanks @jsafrane great reviews!

@rootfs
Copy link
Contributor Author

rootfs commented Apr 7, 2017

@k8s-bot non-cri e2e test this

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 44119, 42538, 43802, 42336, 43396)

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. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants