Skip to content
This repository was archived by the owner on Oct 2, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
5ef911c
chore(dependency): upgrade spring boot from 2.7.x to 3.0.x and spring…
j-sandy Dec 3, 2024
828a55d
refactor(dependency): replace javax with jakarta and HandlerIntercept…
j-sandy Dec 6, 2024
0dc68a1
refactor(exception): replace NestedIOException with IOException durin…
j-sandy Dec 11, 2024
3386f74
refactor(eureka): removed deprecated client and refactor constructor …
j-sandy Dec 11, 2024
66f2d8c
refactor(telemetry): replace the deprecated method and constructor du…
j-sandy Dec 11, 2024
ac20f15
refactor(dependency): replace rxjava with rxjava3 during upgrade of s…
j-sandy Dec 11, 2024
4d0b66b
refactor(spring-security): refactor spring security from 5.x to 6.x …
j-sandy Dec 12, 2024
3230319
refactor(dependency): replace javax.inject with jakarta.inject and up…
j-sandy Dec 18, 2024
6632c05
refactor(test): replace spring.profiles with spring.config.activate.o…
j-sandy Dec 18, 2024
a980df2
refactor(test): refactor the method getType() to getTableType() as pa…
j-sandy Dec 18, 2024
5345b79
refactor(test): upgrade spockframework to fix issue during upgrade of…
j-sandy Dec 18, 2024
17f10c5
refactor(dependency): unpin snakeyaml and upgrade logback with spring…
j-sandy Dec 24, 2024
b993c8d
Merge branch 'master' of https://github.com/j-sandy/kork into sb-3-0-13
j-sandy Feb 18, 2025
9b0bdd6
refactor(dependency): upgrade wiremock as part of spring boot 3.x and…
j-sandy Feb 18, 2025
8016793
Merge branch 'spinnaker:master' into sb-3-0-13
j-sandy Apr 28, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,28 @@

import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
import org.springframework.boot.actuate.health.HealthEndpoint;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@Order(Ordered.HIGHEST_PRECEDENCE + 67)
public class ActuatorEndpointsConfiguration extends WebSecurityConfigurerAdapter {
@EnableWebSecurity
public class ActuatorEndpointsConfiguration {

@Override
public void configure(HttpSecurity http) throws Exception {
@Bean
public SecurityFilterChain configure(HttpSecurity http) throws Exception {
// The health endpoint should always be exposed without auth.
http.requestMatcher(EndpointRequest.to(HealthEndpoint.class))
.authorizeRequests()
http.securityMatcher(EndpointRequest.to(HealthEndpoint.class));
http.authorizeHttpRequests()
.requestMatchers(EndpointRequest.to(HealthEndpoint.class))
.permitAll()
.anyRequest()
.permitAll();
.authenticated();
return http.build();
}
}
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 {
Copy link
Contributor

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?


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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@

import static java.lang.String.format;

import com.netflix.spinnaker.kork.actuator.ActuatorSanitizingFunction;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.SanitizableData;
import org.springframework.boot.actuate.endpoint.Sanitizer;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
Expand All @@ -33,7 +36,9 @@
@Endpoint(id = "resolvedEnv")
public class ResolvedEnvironmentEndpoint {

private final Sanitizer sanitizer = new Sanitizer();
private final Sanitizer sanitizer;
private final ActuatorSanitizingFunction actuatorSanitizingFunction =
new ActuatorSanitizingFunction();
private final Environment environment;

@Autowired
Expand All @@ -42,7 +47,8 @@ public ResolvedEnvironmentEndpoint(
this.environment = environment;
Optional.ofNullable(properties.getKeysToSanitize())
.map(p -> p.toArray(new String[0]))
.ifPresent(sanitizer::setKeysToSanitize);
.ifPresent(actuatorSanitizingFunction::setKeysToSanitize);
sanitizer = new Sanitizer(List.of(actuatorSanitizingFunction));
}

@ReadOperation
Expand All @@ -53,7 +59,9 @@ public Map<String, Object> resolvedEnv() {
property -> property,
property -> {
try {
return sanitizer.sanitize(property, environment.getProperty(property));
return sanitizer.sanitize(
new SanitizableData(null, property, environment.getProperty(property)),
true);
} catch (Exception e) {
return format("Exception occurred: %s", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.netflix.spinnaker.kork.configserver.autoconfig;

import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotNull;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Condition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.netflix.spectator.jvm.Jmx;
import com.netflix.spectator.micrometer.MicrometerRegistry;
import io.micrometer.core.instrument.MeterRegistry;
import javax.annotation.PreDestroy;
import jakarta.annotation.PreDestroy;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
Expand Down
2 changes: 1 addition & 1 deletion kork-credentials-api/kork-credentials-api.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
api project(":kork-plugins-api")
implementation project(":kork-annotations")
implementation project(":kork-exceptions")
implementation 'javax.annotation:javax.annotation-api'
implementation 'jakarta.annotation:jakarta.annotation-api'

testRuntimeOnly "cglib:cglib-nodep"
testRuntimeOnly "org.objenesis:objenesis"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.netflix.spinnaker.credentials.Credentials;
import com.netflix.spinnaker.credentials.CredentialsRepository;
import javax.annotation.PostConstruct;
import jakarta.annotation.PostConstruct;
import lombok.Getter;

public abstract class AbstractCredentialsLoader<T extends Credentials>
Expand Down
2 changes: 1 addition & 1 deletion kork-credentials/kork-credentials.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {
implementation 'org.apache.logging.log4j:log4j-api'
implementation "org.springframework.boot:spring-boot"
implementation 'org.springframework.boot:spring-boot-starter-json'
implementation 'javax.annotation:javax.annotation-api'
implementation 'jakarta.annotation:jakarta.annotation-api'
implementation 'org.slf4j:slf4j-api'

testRuntimeOnly "cglib:cglib-nodep"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package com.netflix.spinnaker.kork.crypto;

import java.io.IOException;
import java.security.GeneralSecurityException;
import org.springframework.core.NestedIOException;

public class NestedSecurityIOException extends NestedIOException {
public class NestedSecurityIOException extends IOException {
public NestedSecurityIOException(GeneralSecurityException e) {
super(e.getMessage(), e);
}
Expand Down
5 changes: 3 additions & 2 deletions kork-eureka/kork-eureka.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ dependencies {
implementation project(":kork-core")
implementation project(":kork-exceptions")

implementation "javax.inject:javax.inject:1"
implementation "jakarta.inject:jakarta.inject-api" // Transitive dependency of com.netflix.eureka:eureka-client-jersey3
implementation "org.springframework.boot:spring-boot-autoconfigure"
implementation "org.springframework.boot:spring-boot-starter-actuator"

implementation "com.netflix.archaius:archaius-core"
implementation "commons-configuration:commons-configuration"
implementation "com.netflix.eureka:eureka-client"
implementation "com.netflix.eureka:eureka-client-jersey3"
implementation "com.netflix.eureka:eureka-core-jersey3"
implementation "com.netflix.netflix-commons:netflix-eventbus"

testImplementation "org.springframework.boot:spring-boot-starter-test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import com.netflix.config.DynamicConfiguration;
import com.netflix.config.FixedDelayPollingScheduler;
import com.netflix.spinnaker.kork.eureka.EurekaAutoConfiguration;
import jakarta.annotation.PreDestroy;
import java.util.*;
import java.util.concurrent.TimeUnit;
import javax.annotation.PreDestroy;
import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.commons.configuration.CompositeConfiguration;
import org.springframework.beans.BeansException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -46,14 +48,13 @@ public EventBus eventBus() {
return new EventBusImpl();
}

/** @deprecated use EurekaClient rather than DiscoveryClient */
@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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import com.netflix.spinnaker.kork.discovery.InstanceStatus;
import com.netflix.spinnaker.kork.discovery.RemoteStatusChangedEvent;
import com.netflix.spinnaker.kork.exceptions.SystemException;
import jakarta.annotation.PreDestroy;
import java.util.Objects;
import javax.annotation.PreDestroy;
import org.springframework.context.ApplicationEventPublisher;

public class EurekaStatusSubscriber implements DiscoveryStatusPublisher {
Expand Down
Loading
Loading