Skip to content

Commit f6124b8

Browse files
Merge pull request #15550 from smarterclayton/strategy
Automatic merge from submit-queue Changing from no-cert to edge encryption should not panic A user who doesn't have permission to change from no cert to edge on an update should not be able to cause a panic. In addition, it should be possible for an unprivileged user to strip certificate info out of a previously valid route. Add better tests. Fixes #15547 Also fixes the broken goversioninfo which prevented a 3.6.0 release build.
2 parents 7dfcee7 + c4dd4cf commit f6124b8

File tree

5 files changed

+79
-10
lines changed

5 files changed

+79
-10
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ clean:
240240
#
241241
# Example:
242242
# make release
243-
official-release: build-rpms build-cross
243+
official-release: build-cross build-rpms
244244
hack/build-images.sh
245245
.PHONY: official-release
246246

hack/lib/build/binaries.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ os::build::internal::build_binaries() {
240240
fi
241241

242242
if [[ "$platform" == "windows/amd64" ]]; then
243-
rm ${OS_ROOT}/cmd/oc/oc.syso
243+
rm -f ${OS_ROOT}/cmd/oc/oc.syso
244244
fi
245245

246246
for test in "${tests[@]:+${tests[@]}}"; do
@@ -261,6 +261,10 @@ readonly -f os::build::build_binaries
261261
# Generates the .syso file used to add compile-time VERSIONINFO metadata to the
262262
# Windows binary.
263263
function os::build::generate_windows_versioninfo() {
264+
if ! os::util::find::system_binary "goversioninfo" >/dev/null 2>&1; then
265+
os::log::warning "No system binary 'goversioninfo' found, skipping version info for Windows builds"
266+
return 0
267+
fi
264268
os::build::version::get_vars
265269
local major="${OS_GIT_MAJOR}"
266270
local minor="${OS_GIT_MINOR%+}"

hack/release.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ elif [[ "$( git rev-parse "${tag}" )" != "$( git rev-parse HEAD )" ]]; then
1515
fi
1616
commit="$( git rev-parse ${tag} )"
1717

18-
# Ensure that the build is using the latest release image
19-
docker pull "${OS_BUILD_ENV_IMAGE}"
18+
# Ensure that the build is using the latest release image and base content
19+
if [[ -z "${OS_RELEASE_STALE}" ]]; then
20+
docker pull "${OS_BUILD_ENV_IMAGE}"
21+
hack/build-base-images.sh
22+
fi
2023

21-
hack/build-base-images.sh
2224
hack/env OS_GIT_COMMIT="${commit}" make official-release
2325
OS_PUSH_ALWAYS=1 OS_PUSH_TAG="${tag}" OS_TAG="" OS_PUSH_LOCAL="1" hack/push-release.sh
2426

pkg/route/registry/route/strategy.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,40 @@ func (s routeStrategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.O
146146
return errs
147147
}
148148

149-
func certificateChanged(route, older *routeapi.Route) bool {
149+
func hasCertificateInfo(tls *routeapi.TLSConfig) bool {
150+
if tls == nil {
151+
return false
152+
}
153+
return len(tls.Certificate) > 0 ||
154+
len(tls.Key) > 0 ||
155+
len(tls.CACertificate) > 0 ||
156+
len(tls.DestinationCACertificate) > 0
157+
}
158+
159+
func certificateChangeRequiresAuth(route, older *routeapi.Route) bool {
150160
switch {
151161
case route.Spec.TLS != nil && older.Spec.TLS != nil:
152162
a, b := route.Spec.TLS, older.Spec.TLS
163+
if !hasCertificateInfo(a) {
164+
// removing certificate info is allowed
165+
return false
166+
}
153167
return a.CACertificate != b.CACertificate ||
154168
a.Certificate != b.Certificate ||
155169
a.DestinationCACertificate != b.DestinationCACertificate ||
156170
a.Key != b.Key
157-
case route.Spec.TLS == nil && older.Spec.TLS == nil:
158-
return false
171+
case route.Spec.TLS != nil:
172+
// using any default certificate is allowed
173+
return hasCertificateInfo(route.Spec.TLS)
159174
default:
160-
return true
175+
// all other cases we are not adding additional certificate info
176+
return false
161177
}
162178
}
163179

164180
func (s routeStrategy) validateHostUpdate(ctx apirequest.Context, route, older *routeapi.Route) field.ErrorList {
165181
hostChanged := route.Spec.Host != older.Spec.Host
166-
certChanged := certificateChanged(route, older)
182+
certChanged := certificateChangeRequiresAuth(route, older)
167183
if !hostChanged && !certChanged {
168184
return nil
169185
}
@@ -191,6 +207,9 @@ func (s routeStrategy) validateHostUpdate(ctx apirequest.Context, route, older *
191207
if hostChanged {
192208
return kvalidation.ValidateImmutableField(route.Spec.Host, older.Spec.Host, field.NewPath("spec", "host"))
193209
}
210+
if route.Spec.TLS == nil || older.Spec.TLS == nil {
211+
return kvalidation.ValidateImmutableField(route.Spec.TLS, older.Spec.TLS, field.NewPath("spec", "tls"))
212+
}
194213
errs := kvalidation.ValidateImmutableField(route.Spec.TLS.CACertificate, older.Spec.TLS.CACertificate, field.NewPath("spec", "tls", "caCertificate"))
195214
errs = append(errs, kvalidation.ValidateImmutableField(route.Spec.TLS.Certificate, older.Spec.TLS.Certificate, field.NewPath("spec", "tls", "certificate"))...)
196215
errs = append(errs, kvalidation.ValidateImmutableField(route.Spec.TLS.DestinationCACertificate, older.Spec.TLS.DestinationCACertificate, field.NewPath("spec", "tls", "destinationCACertificate"))...)

pkg/route/registry/route/strategy_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,50 @@ func TestHostWithWildcardPolicies(t *testing.T) {
328328
allow: false,
329329
errs: 1,
330330
},
331+
{
332+
name: "set-to-edge-changed",
333+
host: "host",
334+
expected: "host",
335+
oldHost: "host",
336+
tls: &routeapi.TLSConfig{Termination: routeapi.TLSTerminationEdge},
337+
oldTLS: nil,
338+
wildcardPolicy: routeapi.WildcardPolicyNone,
339+
allow: false,
340+
errs: 0,
341+
},
342+
{
343+
name: "cleared-edge",
344+
host: "host",
345+
expected: "host",
346+
oldHost: "host",
347+
tls: nil,
348+
oldTLS: &routeapi.TLSConfig{Termination: routeapi.TLSTerminationEdge},
349+
wildcardPolicy: routeapi.WildcardPolicyNone,
350+
allow: false,
351+
errs: 0,
352+
},
353+
{
354+
name: "removed-certificate",
355+
host: "host",
356+
expected: "host",
357+
oldHost: "host",
358+
tls: &routeapi.TLSConfig{Termination: routeapi.TLSTerminationReencrypt},
359+
oldTLS: &routeapi.TLSConfig{Termination: routeapi.TLSTerminationReencrypt, Certificate: "a"},
360+
wildcardPolicy: routeapi.WildcardPolicyNone,
361+
allow: false,
362+
errs: 0,
363+
},
364+
{
365+
name: "added-certificate-and-fails",
366+
host: "host",
367+
expected: "host",
368+
oldHost: "host",
369+
tls: &routeapi.TLSConfig{Termination: routeapi.TLSTerminationReencrypt, Certificate: "a"},
370+
oldTLS: nil,
371+
wildcardPolicy: routeapi.WildcardPolicyNone,
372+
allow: false,
373+
errs: 1,
374+
},
331375
}
332376

333377
for _, tc := range tests {

0 commit comments

Comments
 (0)