Skip to content

Commit 2262ecb

Browse files
Merge pull request #7 from travisghansen/next
CHAP
2 parents d3bb146 + 0623573 commit 2262ecb

File tree

4 files changed

+96
-14
lines changed

4 files changed

+96
-14
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ FreeNAS side. In case of issue, follow the provisioner's logs using:
121121
kubectl -n kube-system logs -f freenas-iscsi-provisioner-<id>
122122
```
123123

124+
## CHAP settings
125+
126+
You should create a secret which holds CHAP authentication credentials based on `deploy/freenas-iscsi-chap.yaml`.
127+
- If you have authentication enabled for the portal (discovery) then set `discovery*` parameters in the secret, and in StorageClass you should set `targetDiscoveryCHAPAuth` to `true`.
128+
- If you want authentication for the targets, then set `node*` parameters in the secret, and in StorageClass you should set `targetGroupAuthtype` and `targetGroupAuthgroup` accordingly, and also set `targetSessionCHAPAuth` to `true`.
129+
124130
# Performance
125131

126132
100 10MiB PVCs
@@ -177,7 +183,7 @@ make fmt
177183
- volume resizing - https://github.com/kubernetes/community/blob/master/contributors/design-proposals/storage/grow-volume-size.md
178184
- volume snapshots - https://github.com/kubernetes/community/blob/master/contributors/design-proposals/storage/volume-snapshotting.md
179185
- mount options - https://github.com/kubernetes/community/blob/master/contributors/design-proposals/storage/mount-options.md
180-
- CHAP
186+
- ~~CHAP~~
181187
- fsType
182188
- properly handle `zvol` API differences with `volsize` getting sent as string and returned as int
183189
- loop GetBy<foo> requests that require `limit` param

deploy/class.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ metadata:
66
# annotations:
77
# storageclass.kubernetes.io/is-default-class: "true"
88
provisioner: freenas.org/iscsi
9+
# Delete|Retain
10+
reclaimPolicy: Delete
911
allowVolumeExpansion: false
1012
parameters:
1113
# set the default filesystem
@@ -77,6 +79,28 @@ parameters:
7779
# default:
7880
#targetGroupAuthgroup:
7981

82+
# Whether portal discovery authentication is employed
83+
# default: false
84+
#targetDiscoveryCHAPAuth:
85+
86+
# Whether session authentication is employed
87+
# default: false
88+
#targetSessionCHAPAuth:
89+
90+
# If either of the two settings above are true, then iSCSI
91+
# secretRef will be filled according to the following settings
92+
#
93+
# Note: once volumes have been provisioned you should NOT change
94+
# the secret name or namespace settings
95+
#
96+
# Namespace of secret which holds iscsi credentials
97+
# default: kube-system
98+
#authSecretNamespace:
99+
100+
# Name of secret which holds iscsi credentials
101+
# default: freenas-iscsi-chap
102+
#authSecretName:
103+
80104
# compression setting on the zvol
81105
# options: "" (inherit), lz4, gzip-9, etc
82106
# default: (inherit)

deploy/freenas-iscsi-chap.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
kind: Secret
2+
apiVersion: v1
3+
type: kubernetes.io/iscsi-chap
4+
metadata:
5+
namespace: kube-system
6+
name: freenas-iscsi-chap
7+
stringData:
8+
# Set the relevant auth credentials here
9+
discovery.sendtargets.auth.username: ""
10+
discovery.sendtargets.auth.password: ""
11+
discovery.sendtargets.auth.username_in: ""
12+
discovery.sendtargets.auth.password_in: ""
13+
node.session.auth.username: ""
14+
node.session.auth.password: ""
15+
node.session.auth.username_in: ""
16+
node.session.auth.password_in: ""

provisioner/provisioner.go

Lines changed: 49 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ var (
2222

2323
type freenasProvisionerConfig struct {
2424
// common params
25-
FSType string
25+
FSType string
26+
ReclaimPolicy *v1.PersistentVolumeReclaimPolicy
2627

2728
// Provisioner options
2829
ProvisionerRollbackPartialFailures bool
@@ -41,6 +42,11 @@ type freenasProvisionerConfig struct {
4142
TargetGroupInitiatorgroup int
4243
TargetGroupPortalgroup int
4344

45+
// Authentication options
46+
DiscoveryCHAPAuth bool
47+
SessionCHAPAuth bool
48+
AuthSecretRef *v1.SecretReference
49+
4450
// Zvol options
4551
ZvolCompression string
4652
ZvolDedup string
@@ -93,6 +99,13 @@ func (p *freenasProvisioner) GetConfig(storageClassName string) (*freenasProvisi
9399
var targetGroupInitiatorgroup int
94100
var targetGroupPortalgroup int
95101

102+
// Authentication options
103+
var targetDiscoveryCHAPAuth = false
104+
var targetSessionCHAPAuth = false
105+
var authSecretNamespace = "kube-system"
106+
var authSecretName = "freenas-iscsi-chap"
107+
var authSecretRef *v1.SecretReference
108+
96109
// zvol defaults
97110
var zvolCompression string
98111
var zvolDedup string
@@ -153,6 +166,16 @@ func (p *freenasProvisioner) GetConfig(storageClassName string) (*freenasProvisi
153166
case "targetGroupPortalgroup":
154167
targetGroupPortalgroup, _ = strconv.Atoi(v)
155168

169+
// Authentication options
170+
case "targetDiscoveryCHAPAuth":
171+
targetDiscoveryCHAPAuth, _ = strconv.ParseBool(v)
172+
case "targetSessionCHAPAuth":
173+
targetSessionCHAPAuth, _ = strconv.ParseBool(v)
174+
case "authSecretNamespace":
175+
authSecretNamespace = v
176+
case "authSecretName":
177+
authSecretName = v
178+
156179
// Zvol options
157180
case "zvolCompression":
158181
zvolCompression = v
@@ -216,8 +239,16 @@ func (p *freenasProvisioner) GetConfig(storageClassName string) (*freenasProvisi
216239
provisionerTargetPortal = serverHost + ":3260"
217240
}
218241

242+
if targetDiscoveryCHAPAuth || targetSessionCHAPAuth {
243+
authSecretRef = &v1.SecretReference{
244+
Namespace: authSecretNamespace,
245+
Name: authSecretName,
246+
}
247+
}
248+
219249
return &freenasProvisionerConfig{
220-
FSType: fsType,
250+
FSType: fsType,
251+
ReclaimPolicy: class.ReclaimPolicy,
221252

222253
// Provisioner options
223254
ProvisionerRollbackPartialFailures: provisionerRollbackPartialFailures,
@@ -236,6 +267,11 @@ func (p *freenasProvisioner) GetConfig(storageClassName string) (*freenasProvisi
236267
TargetGroupInitiatorgroup: targetGroupInitiatorgroup,
237268
TargetGroupPortalgroup: targetGroupPortalgroup,
238269

270+
// Authentication options
271+
DiscoveryCHAPAuth: targetDiscoveryCHAPAuth,
272+
SessionCHAPAuth: targetSessionCHAPAuth,
273+
AuthSecretRef: authSecretRef,
274+
239275
// Zvol options
240276
ZvolCompression: zvolCompression,
241277
ZvolDedup: zvolDedup,
@@ -554,7 +590,7 @@ func (p *freenasProvisioner) Provision(options controller.VolumeOptions) (*v1.Pe
554590
},
555591
},
556592
Spec: v1.PersistentVolumeSpec{
557-
PersistentVolumeReclaimPolicy: options.PersistentVolumeReclaimPolicy,
593+
PersistentVolumeReclaimPolicy: *config.ReclaimPolicy,
558594
AccessModes: options.PVC.Spec.AccessModes,
559595
Capacity: v1.ResourceList{
560596
v1.ResourceName(v1.ResourceStorage): options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)],
@@ -563,16 +599,16 @@ func (p *freenasProvisioner) Provision(options controller.VolumeOptions) (*v1.Pe
563599
VolumeMode: options.PVC.Spec.VolumeMode,
564600
PersistentVolumeSource: v1.PersistentVolumeSource{
565601
ISCSI: &v1.ISCSIPersistentVolumeSource{
566-
TargetPortal: config.ProvisionerTargetPortal,
567-
Portals: portals,
568-
IQN: iscsiConfig.Basename + ":" + iscsiName,
569-
ISCSIInterface: config.ProvisionerISCSIInterface,
570-
Lun: int32(*targetToExtent.Lunid),
571-
ReadOnly: extent.Ro,
572-
FSType: config.FSType,
573-
//DiscoveryCHAPAuth: false,
574-
//SessionCHAPAuth: false,
575-
//SecretRef: getSecretRef(getBool(options.Parameters["chapAuthDiscovery"]), getBool(options.Parameters["chapAuthSession"]), &v1.SecretReference{Name: viper.GetString("provisioner-name") + "-chap-secret"}),
602+
TargetPortal: config.ProvisionerTargetPortal,
603+
Portals: portals,
604+
IQN: iscsiConfig.Basename + ":" + iscsiName,
605+
ISCSIInterface: config.ProvisionerISCSIInterface,
606+
Lun: int32(*targetToExtent.Lunid),
607+
ReadOnly: extent.Ro,
608+
FSType: config.FSType,
609+
DiscoveryCHAPAuth: config.DiscoveryCHAPAuth,
610+
SessionCHAPAuth: config.SessionCHAPAuth,
611+
SecretRef: config.AuthSecretRef,
576612
},
577613
},
578614
},

0 commit comments

Comments
 (0)