-
Notifications
You must be signed in to change notification settings - Fork 173
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
chore(dependency): upgrade spring boot from 2.7.x to 3.0.x and spring cloud from 2021.0.x to 2022.0.x #1216
Draft
j-sandy
wants to merge
12
commits into
spinnaker:master
Choose a base branch
from
j-sandy:sb-3-0-13
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
93b1423
chore(dependency): upgrade spring boot from 2.7.x to 3.0.x and spring…
j-sandy 4eea85e
refactor(dependency): replace javax with jakarta and HandlerIntercept…
j-sandy f15c324
refactor(exception): replace NestedIOException with IOException durin…
j-sandy 3db7c72
refactor(eureka): removed deprecated client and refactor constructor …
j-sandy 1696365
refactor(telemetry): replace the deprecated method and constructor du…
j-sandy 05883be
refactor(dependency): replace rxjava with rxjava3 during upgrade of s…
j-sandy 5d5bdc3
refactor(spring-security): refactor spring security from 5.x to 6.x …
j-sandy f816047
refactor(dependency): replace javax.inject with jakarta.inject and up…
j-sandy c21208f
refactor(test): replace spring.profiles with spring.config.activate.o…
j-sandy 6491632
refactor(test): refactor the method getType() to getTableType() as pa…
j-sandy f7777e1
refactor(test): upgrade spockframework to fix issue during upgrade of…
j-sandy 49437bb
refactor(dependency): unpin snakeyaml and upgrade logback with spring…
j-sandy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
...ctuator/src/main/java/com/netflix/spinnaker/kork/actuator/ActuatorSanitizingFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* Copyright 2024 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.kork.actuator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import org.springframework.boot.actuate.endpoint.SanitizableData; | ||
import org.springframework.boot.actuate.endpoint.SanitizingFunction; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.StringUtils; | ||
|
||
@Component | ||
public class ActuatorSanitizingFunction implements SanitizingFunction { | ||
|
||
private static final String[] REGEX_PARTS = {"*", "$", "^", "+"}; | ||
private static final Set<String> DEFAULT_KEYS_TO_SANITIZE = | ||
Set.of( | ||
"password", | ||
"secret", | ||
"key", | ||
"token", | ||
".*credentials.*", | ||
"vcap_services", | ||
"^vcap\\.services.*$", | ||
"sun.java.command", | ||
"^spring[._]application[._]json$"); | ||
private static final Set<String> URI_USERINFO_KEYS = | ||
Set.of("uri", "uris", "url", "urls", "address", "addresses"); | ||
private static final Pattern URI_USERINFO_PATTERN = | ||
Pattern.compile("^\\[?[A-Za-z][A-Za-z0-9\\+\\.\\-]+://.+:(.*)@.+$"); | ||
private List<Pattern> keysToSanitize = new ArrayList<>(); | ||
|
||
public ActuatorSanitizingFunction(List<String> additionalKeysToSanitize) { | ||
addKeysToSanitize(DEFAULT_KEYS_TO_SANITIZE); | ||
addKeysToSanitize(URI_USERINFO_KEYS); | ||
addKeysToSanitize(additionalKeysToSanitize); | ||
} | ||
|
||
public ActuatorSanitizingFunction() { | ||
addKeysToSanitize(DEFAULT_KEYS_TO_SANITIZE); | ||
addKeysToSanitize(URI_USERINFO_KEYS); | ||
} | ||
|
||
private void addKeysToSanitize(Collection<String> keysToSanitize) { | ||
for (String key : keysToSanitize) { | ||
this.keysToSanitize.add(getPattern(key)); | ||
} | ||
} | ||
|
||
private Pattern getPattern(String value) { | ||
if (isRegex(value)) { | ||
return Pattern.compile(value, Pattern.CASE_INSENSITIVE); | ||
} | ||
return Pattern.compile(".*" + value + "$", Pattern.CASE_INSENSITIVE); | ||
} | ||
|
||
private boolean isRegex(String value) { | ||
for (String part : REGEX_PARTS) { | ||
if (value.contains(part)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public void setKeysToSanitize(String... keysToSanitize) { | ||
if (keysToSanitize != null) { | ||
for (String key : keysToSanitize) { | ||
this.keysToSanitize.add(getPattern(key)); // todo: clear oll existing the make the list. | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public SanitizableData apply(SanitizableData data) { | ||
if (data.getValue() == null) { | ||
return data; | ||
} | ||
|
||
for (Pattern pattern : keysToSanitize) { | ||
if (pattern.matcher(data.getKey()).matches()) { | ||
if (keyIsUriWithUserInfo(pattern)) { | ||
return data.withValue(sanitizeUris(data.getValue().toString())); | ||
} | ||
|
||
return data.withValue(SanitizableData.SANITIZED_VALUE); | ||
} | ||
} | ||
|
||
return data; | ||
} | ||
|
||
private boolean keyIsUriWithUserInfo(Pattern pattern) { | ||
for (String uriKey : URI_USERINFO_KEYS) { | ||
if (pattern.matcher(uriKey).matches()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private Object sanitizeUris(String value) { | ||
return Arrays.stream(value.split(",")).map(this::sanitizeUri).collect(Collectors.joining(",")); | ||
} | ||
|
||
private String sanitizeUri(String value) { | ||
Matcher matcher = URI_USERINFO_PATTERN.matcher(value); | ||
String password = matcher.matches() ? matcher.group(1) : null; | ||
if (password != null) { | ||
return StringUtils.replace( | ||
value, ":" + password + "@", ":" + SanitizableData.SANITIZED_VALUE + "@"); | ||
} | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,14 @@ | |
import com.netflix.discovery.DiscoveryClient; | ||
import com.netflix.discovery.EurekaClient; | ||
import com.netflix.discovery.EurekaClientConfig; | ||
import com.netflix.discovery.shared.transport.jersey.TransportClientFactories; | ||
import com.netflix.discovery.shared.transport.jersey3.Jersey3TransportClientFactories; | ||
import com.netflix.eventbus.impl.EventBusImpl; | ||
import com.netflix.eventbus.spi.EventBus; | ||
import com.netflix.spinnaker.kork.discovery.DiscoveryAutoConfiguration; | ||
import jakarta.inject.Provider; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import javax.inject.Provider; | ||
import org.springframework.boot.actuate.health.HealthIndicator; | ||
import org.springframework.boot.actuate.health.StatusAggregator; | ||
import org.springframework.boot.autoconfigure.AutoConfigureBefore; | ||
|
@@ -46,14 +48,13 @@ public EventBus eventBus() { | |
return new EventBusImpl(); | ||
} | ||
|
||
/** @deprecated use EurekaClient rather than DiscoveryClient */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the deprecation? |
||
@Bean | ||
@Deprecated | ||
public DiscoveryClient discoveryClient( | ||
ApplicationInfoManager applicationInfoManager, | ||
EurekaClientConfig eurekaClientConfig, | ||
DiscoveryClient.DiscoveryClientOptionalArgs optionalArgs) { | ||
return new DiscoveryClient(applicationInfoManager, eurekaClientConfig, optionalArgs); | ||
TransportClientFactories transportClientFactories) { | ||
return new DiscoveryClient( | ||
applicationInfoManager, eurekaClientConfig, transportClientFactories); | ||
} | ||
|
||
@Bean | ||
|
@@ -86,13 +87,8 @@ EurekaClientConfig eurekaClientConfig( | |
} | ||
|
||
@Bean | ||
DiscoveryClient.DiscoveryClientOptionalArgs optionalArgs( | ||
EventBus eventBus, HealthCheckHandler healthCheckHandler) { | ||
DiscoveryClient.DiscoveryClientOptionalArgs args = | ||
new DiscoveryClient.DiscoveryClientOptionalArgs(); | ||
args.setEventBus(eventBus); | ||
args.setHealthCheckHandlerProvider(new StaticProvider<>(healthCheckHandler)); | ||
return args; | ||
TransportClientFactories transportClientFactories() { | ||
return Jersey3TransportClientFactories.getInstance(); | ||
} | ||
|
||
@Bean | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javadoc please. And where do all these hard-coded strings come from?