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

stronger validation for tls termination type #1768

Merged
merged 1 commit into from
Apr 17, 2015
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
16 changes: 8 additions & 8 deletions pkg/route/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"

"fmt"
routeapi "github.com/openshift/origin/pkg/route/api"
)

Expand Down Expand Up @@ -49,8 +50,9 @@ func validateTLS(tls *routeapi.TLSConfig) fielderrors.ValidationErrorList {
return nil
}

switch tls.Termination {
//reencrypt must specify cert, key, cacert, and destination ca cert
if tls.Termination == routeapi.TLSTerminationReencrypt {
case routeapi.TLSTerminationReencrypt:
if len(tls.Certificate) == 0 {
result = append(result, fielderrors.NewFieldRequired("certificate"))
}
Expand All @@ -66,10 +68,8 @@ func validateTLS(tls *routeapi.TLSConfig) fielderrors.ValidationErrorList {
if len(tls.DestinationCACertificate) == 0 {
result = append(result, fielderrors.NewFieldRequired("destinationCACertificate"))
}
}

//passthrough term should not specify any cert
if tls.Termination == routeapi.TLSTerminationPassthrough {
case routeapi.TLSTerminationPassthrough:
if len(tls.Certificate) > 0 {
result = append(result, fielderrors.NewFieldInvalid("certificate", tls.Certificate, "passthrough termination does not support certificates"))
}
Expand All @@ -85,10 +85,8 @@ func validateTLS(tls *routeapi.TLSConfig) fielderrors.ValidationErrorList {
if len(tls.DestinationCACertificate) > 0 {
result = append(result, fielderrors.NewFieldInvalid("destinationCACertificate", tls.DestinationCACertificate, "passthrough termination does not support certificates"))
}
}

//edge cert should specify cert, key, and cacert
if tls.Termination == routeapi.TLSTerminationEdge {
case routeapi.TLSTerminationEdge:
if len(tls.Certificate) == 0 {
result = append(result, fielderrors.NewFieldRequired("certificate"))
}
Expand All @@ -104,7 +102,9 @@ func validateTLS(tls *routeapi.TLSConfig) fielderrors.ValidationErrorList {
if len(tls.DestinationCACertificate) > 0 {
result = append(result, fielderrors.NewFieldInvalid("destinationCACertificate", tls.DestinationCACertificate, "edge termination does not support destination certificates"))
}
default:
msg := fmt.Sprintf("invalid value for termination, acceptable values are %s, %s, %s, or emtpy (no tls specified)", routeapi.TLSTerminationEdge, routeapi.TLSTerminationPassthrough, routeapi.TLSTerminationReencrypt)
result = append(result, fielderrors.NewFieldInvalid("termination", tls.Termination, msg))
}

return result
}
10 changes: 10 additions & 0 deletions pkg/route/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,13 @@ func TestValidateReencryptTermInvalid(t *testing.T) {
t.Errorf("Unexpected error list encountered: %#v. Expected 4 errors, got %v", errs, len(errs))
}
}

func TestValidateTLSInvalidTermination(t *testing.T) {
errs := validateTLS(&api.TLSConfig{
Termination: "invalid",
})

if len(errs) != 1 {
t.Errorf("Unexpected error list encountered: %#v. Expected 1 errors, got %v", errs, len(errs))
}
}