Skip to content

Commit ead75a4

Browse files
authored
Merge pull request #124 from codenrhoden/disable-field-len
Add option to disable field length checking
2 parents 3e243d0 + 27bbd86 commit ead75a4

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ environment variables:
237237
Invalid responses are marshalled into a gRPC error with a code
238238
of <code>Internal</code>.</td>
239239
</tr>
240+
<tr>
241+
<td><code>X_CSI_SPEC_DISABLE_LEN_CHECK</code></td>
242+
<td>A flag that disables validation of CSI message field lengths.</td>
243+
</tr>
240244
<tr>
241245
<td><code>X_CSI_REQUIRE_STAGING_TARGET_PATH</code></td>
242246
<td>

envvars.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ const (
114114
// a code of "Internal."
115115
EnvVarSpecRepValidation = "X_CSI_SPEC_REP_VALIDATION"
116116

117+
// EnvVarDisableFieldLen is the name of the environment variable used
118+
// to determine whether or not to disable validation of CSI request and
119+
// response field lengths against the permitted lenghts defined in the spec
120+
EnvVarDisableFieldLen = "X_CSI_SPEC_DISABLE_LEN_CHECK"
121+
117122
// EnvVarRequireStagingTargetPath is the name of the environment variable
118123
// used to determine whether or not the NodePublishVolume request field
119124
// StagingTargetPath is required.

middleware.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (sp *StoragePlugin) initInterceptors(ctx context.Context) {
3737
withCredsCtrlrUnpubVol = sp.getEnvBool(ctx, EnvVarCredsCtrlrUnpubVol)
3838
withCredsNodeStgVol = sp.getEnvBool(ctx, EnvVarCredsNodeStgVol)
3939
withCredsNodePubVol = sp.getEnvBool(ctx, EnvVarCredsNodePubVol)
40+
withDisableFieldLen = sp.getEnvBool(ctx, EnvVarDisableFieldLen)
4041
)
4142

4243
// Enable all cred requirements if the general option is enabled.
@@ -170,6 +171,11 @@ func (sp *StoragePlugin) initInterceptors(ctx context.Context) {
170171
specvalidator.WithRequiresPublishContext())
171172
log.Debug("enabled spec validator opt: requires pub context")
172173
}
174+
if withDisableFieldLen {
175+
specOpts = append(specOpts,
176+
specvalidator.WithDisableFieldLenCheck())
177+
log.Debug("disabled spec validator opt: field length check")
178+
}
173179
sp.Interceptors = append(sp.Interceptors,
174180
specvalidator.NewServerSpecValidator(specOpts...))
175181
}

middleware/specvalidator/spec_validator.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type opts struct {
3333
requiresCtlrUnpubVolSecrets bool
3434
requiresNodeStgVolSecrets bool
3535
requiresNodePubVolSecrets bool
36+
disableFieldLenCheck bool
3637
}
3738

3839
// WithRequestValidation is a Option that enables request validation.
@@ -131,6 +132,14 @@ func WithRequiresNodePublishVolumeSecrets() Option {
131132
}
132133
}
133134

135+
// WithDisableFieldLenCheck is a Option
136+
// that indicates that the length of fields should not be validated
137+
func WithDisableFieldLenCheck() Option {
138+
return func(o *opts) {
139+
o.disableFieldLenCheck = true
140+
}
141+
}
142+
134143
type interceptor struct {
135144
opts opts
136145
}
@@ -276,8 +285,10 @@ func (s *interceptor) validateRequest(
276285
}
277286

278287
// Validate field sizes.
279-
if err := validateFieldSizes(req); err != nil {
280-
return err
288+
if !s.opts.disableFieldLenCheck {
289+
if err := validateFieldSizes(req); err != nil {
290+
return err
291+
}
281292
}
282293

283294
// Check to see if the request has a volume ID and if it is set.
@@ -359,8 +370,10 @@ func (s *interceptor) validateResponse(
359370
}
360371

361372
// Validate the field sizes.
362-
if err := validateFieldSizes(rep); err != nil {
363-
return err
373+
if !s.opts.disableFieldLenCheck {
374+
if err := validateFieldSizes(rep); err != nil {
375+
return err
376+
}
364377
}
365378

366379
switch tobj := rep.(type) {

usage.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ GLOBAL OPTIONS
120120
Invalid responses are marshalled into a gRPC error with a code
121121
of "Internal."
122122
123+
X_CSI_SPEC_DISABLE_LEN_CHECK
124+
A flag that disables validation of CSI message field lengths.
125+
123126
X_CSI_REQUIRE_STAGING_TARGET_PATH
124127
A flag that enables treating the following fields as required:
125128
* NodePublishVolumeRequest.StagingTargetPath

0 commit comments

Comments
 (0)