Skip to content

Commit d068ab8

Browse files
committed
bump config server versions, add opt-in basic auth
1 parent 9ef4743 commit d068ab8

File tree

6 files changed

+81
-7
lines changed

6 files changed

+81
-7
lines changed

config-server/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ WORKDIR /scratch
99
RUN apk update && apk add ca-certificates && apk add curl && apk add patch
1010
RUN curl --get https://start.spring.io/starter.zip \
1111
-d type=gradle-project \
12-
-d bootVersion=3.4.1 \
12+
-d bootVersion=3.5.4 \
1313
-d javaVersion=$JVM \
1414
-d groupId=io.steeltoe.docker \
1515
-d artifactId=configserver \
1616
-d applicationName=ConfigServer \
1717
-d language=java \
18-
-d dependencies=cloud-config-server,actuator,cloud-eureka \
19-
-d version=4.2.0 \
18+
-d dependencies=cloud-config-server,actuator,cloud-eureka,security \
19+
-d version=4.3.0 \
2020
--output configserver.zip
2121
RUN mkdir configserver && unzip -d configserver configserver.zip
2222
COPY metadata metadata

config-server/README.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ $ docker run --publish 8888:8888 --volume /path/to/my/config:/config steeltoe.az
2626
--spring.cloud.config.server.native.searchLocations=file:///config
2727
----
2828

29+
.With Basic Auth
30+
----
31+
$ docker run --publish 8888:8888 steeltoe.azurecr.io/config-server \
32+
--auth.enabled=true \
33+
--auth.username=myCustomUser \
34+
--auth.password=myCustomPassword
35+
----
36+
2937
== Resources
3038

3139
|===
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
-t config-server:4.2 -t config-server:4 -t config-server:latest
1+
-t config-server:4.3 -t config-server:4 -t config-server:latest
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.2.0
1+
4.3.0
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--- /dev/null
2+
+++ configserver/src/main/java/io/steeltoe/docker/configserver/BasicOrNoAuthConfig.java 2025-08-15 13:15:18.461432100 -0500
3+
@@ -0,0 +1,62 @@
4+
+package io.steeltoe.docker.configserver;
5+
+
6+
+import org.springframework.beans.factory.annotation.Value;
7+
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
8+
+import org.springframework.boot.autoconfigure.security.SecurityProperties;
9+
+import org.springframework.context.annotation.Bean;
10+
+import org.springframework.context.annotation.Configuration;
11+
+import org.springframework.core.annotation.Order;
12+
+import org.springframework.security.config.Customizer;
13+
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
14+
+import org.springframework.security.core.userdetails.User;
15+
+import org.springframework.security.core.userdetails.UserDetailsService;
16+
+import org.springframework.security.crypto.password.NoOpPasswordEncoder;
17+
+import org.springframework.security.crypto.password.PasswordEncoder;
18+
+import org.springframework.security.provisioning.InMemoryUserDetailsManager;
19+
+import org.springframework.security.web.SecurityFilterChain;
20+
+
21+
+@Configuration
22+
+public class BasicOrNoAuthConfig {
23+
+
24+
+ @Bean
25+
+ @ConditionalOnProperty(prefix = "auth", name = "enabled", havingValue = "true")
26+
+ public UserDetailsService userDetailsService(
27+
+ @Value("${auth.username:devuser}") String username,
28+
+ @Value("${auth.password:devpassword}") String password) {
29+
+
30+
+ return new InMemoryUserDetailsManager(
31+
+ User.withUsername(username)
32+
+ .password(password)
33+
+ .roles("USER")
34+
+ .build());
35+
+ }
36+
+
37+
+ @SuppressWarnings("deprecation")
38+
+ @Bean
39+
+ @ConditionalOnProperty(prefix = "auth", name = "enabled", havingValue = "true")
40+
+ public PasswordEncoder passwordEncoder() {
41+
+ // For dev/test only — plaintext password
42+
+ return NoOpPasswordEncoder.getInstance();
43+
+ }
44+
+
45+
+ @Bean
46+
+ @ConditionalOnProperty(prefix = "auth", name = "enabled", havingValue = "true")
47+
+ @Order(SecurityProperties.BASIC_AUTH_ORDER)
48+
+ public SecurityFilterChain basicAuthChain(HttpSecurity http) throws Exception {
49+
+ http
50+
+ .authorizeHttpRequests(auth -> auth.anyRequest().authenticated())
51+
+ .httpBasic(Customizer.withDefaults())
52+
+ .csrf(csrf -> csrf.disable());
53+
+ return http.build();
54+
+ }
55+
+
56+
+ @Bean
57+
+ @ConditionalOnProperty(prefix = "auth", name = "enabled", havingValue = "false", matchIfMissing = true)
58+
+ @Order(SecurityProperties.BASIC_AUTH_ORDER)
59+
+ public SecurityFilterChain permitAllChain(HttpSecurity http) throws Exception {
60+
+ http
61+
+ .authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
62+
+ .csrf(csrf -> csrf.disable());
63+
+ return http.build();
64+
+ }
65+
+}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- configserver/src/main/resources/application.properties 2024-02-21 15:43:09.000000000 -0600
2-
+++ configserver/src/main/resources/application.properties 2024-04-02 13:15:18.461432100 -0500
3-
@@ -0,0 +1,9 @@
2+
+++ configserver/src/main/resources/application.properties 2025-08-15 13:15:18.461432100 -0500
3+
@@ -0,0 +1,10 @@
44
+server.port = 8888
55
+spring.cloud.config.server.git.uri = https://github.com/spring-cloud-samples/config-repo
66
+eureka.client.enabled = false
@@ -10,3 +10,4 @@
1010
+eureka.instance.virtualhostname = configserver
1111
+eureka.instance.hostname = host.docker.internal
1212
+eureka.instance.instanceId = host.docker.internal:configserver:8888
13+
+auth.enabled = false

0 commit comments

Comments
 (0)