Skip to content

Commit eb372c5

Browse files
committed
Securing the system
- Add authorization server. - Making Gateway and Store services to be the Resource Servers. - Add HTTPS support. - Change test cases to work with security. - Update docker-compose*.yml to add auth-server. - Secure Eureka service.
1 parent a83dfd7 commit eb372c5

File tree

46 files changed

+1176
-125
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1176
-125
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ build/
5959

6060
### VS Code ###
6161
.vscode/
62+
63+
### Special files
64+
test-em-all-external-auth.sh

README.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
- This project is a development of a small set of **Spring Boot** and **Cloud** based Microservices projects, that implement cloud-native intuitive, Reactive Programming, Event-driven, Microservices design patterns and coding best practices.
44
- The project follows [**CloudNative**](https://www.cncf.io/) recommendations and The [**twelve-factor app**](https://12factor.net/) methodology for building *software-as-a-service apps* to show how μServices should be built and deployed.
5-
- This project is using cutting edge technologies like Docker, Kubernetes, Elasticsearch Stack for logging and monitoring, Java SE 14, MySQL, and MongoDB databases, all components developed with TDD in mind, covering integration & performance testing, and many more.
5+
- This project uses cutting edge technologies like Docker, Kubernetes, Elasticsearch Stack for
6+
logging and monitoring, Java SE 14, MySQL, and MongoDB databases, all components developed with TDD in mind, covering integration & performance testing, and many more.
67

78
------
89
I am developing this project as stages, and all such stages are documented under project
@@ -28,8 +29,9 @@ Springy Store μService --> Parent folder.
2829
|- store-cloud-chassis --> Cloud services Parent POM, inherit from build contains all cloud libraries
2930
|- store-service-chassis --> Parent POM, inherits from cloud contains all microservices common libraries
3031
|-store-cloud-infra
32+
|- authorization-server --> Authorization server
33+
|- edge-server --> API Gateway server
3134
|- eureka-server --> Service discovery server
32-
|- edge-server --> API Gateway server
3335
|-store-common
3436
|- store-api --> API Endpoint and services definitions for all microservices
3537
|- store-utils --> Common utilities shared between all components
@@ -67,9 +69,9 @@ The following topics are going to be covered in this 1st stage (other stages top
6769
- Adding automated tests of microservices in isolation.
6870
- Adding semi-automated tests to a microservice landscape.
6971

70-
### System Boundary - μServices Landscape (Release 4.8-Latest)
72+
### System Boundary - μServices Landscape (Release 5.0-Latest)
7173

72-
![System Boundary](docs/stage1/app_ms_landscape.png)
74+
![System Boundary](docs/diagram/app_ms_landscape.png)
7375

7476
### Required software
7577

@@ -159,7 +161,7 @@ All build commands and test suite for each microservice should run successfully,
159161

160162
```bash
161163
---------------< com.siriusxi.ms.store:store-aggregator >---------------
162-
[INFO] Building Springy Store Aggregator 1.0-SNAPSHOT [12/12]
164+
[INFO] Building Springy Store Aggregator 1.0-SNAPSHOT [13/13]
163165
[INFO] --------------------------------[ pom ]---------------------------------
164166
[INFO]
165167
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ store-aggregator ---
@@ -177,12 +179,13 @@ All build commands and test suite for each microservice should run successfully,
177179
[INFO] Store Service ...................................... SUCCESS [ 8.927 s]
178180
[INFO] Eureka Discovery Server ............................ SUCCESS [ 6.536 s]
179181
[INFO] Edge Server ........................................ SUCCESS [ 32.108 s]
182+
[INFO] Authorization Server ............................... SUCCESS [ 1.616 s]
180183
[INFO] Springy Store Aggregator ........................... SUCCESS [ 0.100 s]
181184
[INFO] ------------------------------------------------------------------------
182185
[INFO] BUILD SUCCESS
183186
[INFO] ------------------------------------------------------------------------
184-
[INFO] Total time: 55.663 s
185-
[INFO] Finished at: 2020-04-26T03:38:34+02:00
187+
[INFO] Total time: 57.663 s
188+
[INFO] Finished at: 2020-05-08T03:38:34+02:00
186189
[INFO] ------------------------------------------------------------------------
187190
```
188191

@@ -201,6 +204,7 @@ All the **services**, **databases**, and **messaging service** will run in paral
201204
Creating network "ssm_default" with the default driver
202205
Creating ssm_eureka_1 ... done
203206
Creating ssm_gateway_1 ... done
207+
Creating ssm_auth-server_1 ... done
204208
Creating ssm_mysql_1 ... done
205209
Creating ssm_mongodb_1 ... done
206210
Creating ssm_rabbitmq_1 ... done
@@ -279,12 +283,15 @@ mohamed.taman@DTLNV8 ~/springy-store-microservices
279283
The result will look like this:
280284
281285
```bash
282-
Starting [Springy Store] full functionality testing....
286+
Starting 'Springy Store μServices' for [Blackbox] testing....
283287
284-
Start: Sun, Apr 30, 2020 2:34:19 PM
288+
Start Tests: Fri, May 8, 2020 12:26:28 PM
285289
HOST=localhost
286-
PORT=8080
287-
Wait for: curl http://localhost:8080/actuator/health ... Ok
290+
PORT=8443
291+
Restarting the test environment...
292+
$ docker-compose -p ssm down --remove-orphans
293+
$ docker-compose -p ssm up -d
294+
Wait for: curl -k https://localhost:8443/actuator/health... , retry #1 , retry #2, {"status":"UP"} DONE, continues...
288295
Test OK (HTTP Code: 200)
289296
Test OK (HTTP Code: 200)
290297
Test OK (HTTP Code: 200)
@@ -305,7 +312,10 @@ Test OK (HTTP Code: 422, {"httpStatus":"UNPROCESSABLE_ENTITY","message":"Invalid
305312
Test OK (actual value: "Invalid productId: -1")
306313
Test OK (HTTP Code: 400, {"timestamp":"2020-04-12T12:34:26.471+00:00","path":"/store/api/v1/products/invalidProductId","status":400,"error":"Bad Request","message":"Type mismatch.","requestId":"044dcdf2-13"})
307314
Test OK (actual value: "Type mismatch.")
308-
End: Sun, Apr 30, 2020 2:34:26 PM
315+
Test OK (HTTP Code: 401, )
316+
Test OK (HTTP Code: 200)
317+
Test OK (HTTP Code: 403, )
318+
End, all tests OK: Fri, May 8, 2020 12:29:21 PM
309319
```
310320
311321
### Closing The Story
@@ -326,6 +336,7 @@ Stopping ssm_product_1 ... done
326336
Stopping ssm_review_1 ... done
327337
Stopping ssm_mongodb_1 ... done
328338
Stopping ssm_store_1 ... done
339+
Stopping ssm_auth-server_1 ... done
329340
Stopping ssm_mysql_1 ... done
330341
Stopping ssm_rabbitmq_1 ... done
331342
Stopping ssm_eureka_1 ... done
@@ -335,6 +346,7 @@ Removing ssm_product_1 ... done
335346
Removing ssm_review_1 ... done
336347
Removing ssm_mongodb_1 ... done
337348
Removing ssm_store_1 ... done
349+
Removing ssm_auth-server_1 ... done
338350
Removing ssm_mysql_1 ... done
339351
Removing ssm_rabbitmq_1 ... done
340352
Removing ssm_eureka_1 ... done

config/keystore/edge.p12

2.57 KB
Binary file not shown.

docker-compose-kafka.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,21 @@ services:
120120
gateway:
121121
build: store-cloud-infra/edge-server
122122
ports:
123-
- "8080:8080"
123+
- "8443:8443"
124+
environment:
125+
- SPRING_PROFILES_ACTIVE=docker
126+
- SERVER_SSL_KEY_STORE=file:/keystore/edge.p12
127+
- SERVER_SSL_KEY_STORE_PASSWORD=password
128+
volumes:
129+
- $PWD/config/keystore:/keystore
130+
depends_on:
131+
- eureka
132+
restart: on-failure
133+
## End - Edge Server definition
134+
135+
## Start - Edge Server definition
136+
auth-server:
137+
build: store-cloud-infra/authorization-server
124138
environment:
125139
- SPRING_PROFILES_ACTIVE=docker
126140
depends_on:

docker-compose-partitions.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,21 @@ services:
106106
gateway:
107107
build: store-cloud-infra/edge-server
108108
ports:
109-
- "8080:8080"
109+
- "8443:8443"
110+
environment:
111+
- SPRING_PROFILES_ACTIVE=docker
112+
- SERVER_SSL_KEY_STORE=file:/keystore/edge.p12
113+
- SERVER_SSL_KEY_STORE_PASSWORD=password
114+
volumes:
115+
- $PWD/config/keystore:/keystore
116+
depends_on:
117+
- eureka
118+
restart: on-failure
119+
## End - Edge Server definition
120+
121+
## Start - Edge Server definition
122+
auth-server:
123+
build: store-cloud-infra/authorization-server
110124
environment:
111125
- SPRING_PROFILES_ACTIVE=docker
112126
depends_on:

docker-compose.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ services:
3737
store:
3838
build: store-services/store-service
3939
environment:
40+
# - SPRING_PROFILES_ACTIVE=external-OAuth-Provider
4041
- SPRING_PROFILES_ACTIVE=docker
4142
depends_on:
4243
- rabbitmq
@@ -54,7 +55,23 @@ services:
5455
gateway:
5556
build: store-cloud-infra/edge-server
5657
ports:
57-
- "8080:8080"
58+
- "8443:8443"
59+
environment:
60+
# - SPRING_PROFILES_ACTIVE=external-OAuth-Provider
61+
- SPRING_PROFILES_ACTIVE=docker
62+
# dynamically change certificate at run time
63+
- SERVER_SSL_KEY_STORE=file:/keystore/edge.p12
64+
- SERVER_SSL_KEY_STORE_PASSWORD=password
65+
volumes:
66+
- $PWD/config/keystore:/keystore
67+
depends_on:
68+
- eureka
69+
restart: on-failure
70+
## End - Edge Server definition
71+
72+
## Start - Edge Server definition
73+
auth-server:
74+
build: store-cloud-infra/authorization-server
5875
environment:
5976
- SPRING_PROFILES_ACTIVE=docker
6077
depends_on:

docs/diagram/app_ms_landscape.png

118 KB
Loading

docs/stage1/app_ms_landscape.png

-77.3 KB
Binary file not shown.

pom.xml

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,40 @@
88
<artifactId>store-aggregator</artifactId>
99
<version>1.0-SNAPSHOT</version>
1010
<name>Springy Store Aggregator</name>
11-
<description>Aggregator pom project for Springy μServices</description>
11+
<description>Aggregator pom project for all Springy Store μServices</description>
1212
<packaging>pom</packaging>
1313

14+
<!-- Start - Springy Store Project Owner -->
15+
<developers>
16+
<developer>
17+
<id>0001</id>
18+
<name>Mohamed Taman</name>
19+
<email>mohamed.taman@gmail.com</email>
20+
<roles>
21+
<role>
22+
Sr. Enterprise Architect
23+
</role>
24+
<role>
25+
Lead Software Architect
26+
</role>
27+
</roles>
28+
</developer>
29+
</developers>
30+
<!-- End - Springy Store Project Owner -->
31+
<!-- Start - Springy Store source repository -->
32+
<scm>
33+
<connection>https://github.com/mohamed-taman/Springy-Store-Microservices.git</connection>
34+
<developerConnection>git@github.com:mohamed-taman/Springy-Store-Microservices.git</developerConnection>
35+
<tag>HEAD</tag>
36+
</scm>
37+
<!-- End - Springy Store source repository -->
38+
<!-- Start - Springy Store issue management -->
39+
<issueManagement>
40+
<system>GitHub</system>
41+
<url>https://github.com/mohamed-taman/Springy-Store-Microservices/issues</url>
42+
</issueManagement>
43+
<!-- End - Springy Store issue management -->
44+
1445
<properties>
1546
<maven.install.skip>true</maven.install.skip>
1647
<maven.deploy.skip>true</maven.deploy.skip>
@@ -28,7 +59,6 @@
2859
<module>store-services/store-service</module>
2960
<module>store-cloud-infra/eureka-server</module>
3061
<module>store-cloud-infra/edge-server</module>
31-
32-
62+
<module>store-cloud-infra/authorization-server</module>
3363
</modules>
3464
</project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#### Start of builder image
2+
# ------------------------
3+
# Builder stage to prepare application for final image
4+
FROM openjdk:14-slim-buster as builder
5+
WORKDIR temp
6+
7+
# Fatjar location, but could be set to different location from command line
8+
ARG JAR_FILE=target/*.jar
9+
10+
# Copy fat jar file to current image builder
11+
COPY ${JAR_FILE} application.jar
12+
13+
# Extract the jar file layers
14+
RUN java -Djarmode=layertools -jar --enable-preview application.jar extract
15+
16+
# Workaround to avoid Copy command failure when directory is not exists.
17+
RUN test ! -d ./snapshot-dependencies \
18+
&& mkdir snapshot-dependencies \
19+
&& echo "Directory [snapshot-dependencies] created."
20+
21+
#### End of builder stage
22+
23+
#### Start of actual image
24+
# ------------------------
25+
# Build image based on JDK 14 base image, based on latest debian buster OS
26+
FROM openjdk:14-slim-buster
27+
VOLUME /tmp
28+
29+
# Set image information, but could be set to different location from command line
30+
ARG IMAGE_VERSION="1.0-SNAPSHOT"
31+
ARG IMAGE_NAME="Authorization Server"
32+
ARG MAINTAINER="Mohamed Taman <mohamed.taman@gmail.com>"
33+
34+
LABEL version=${IMAGE_VERSION} name=${IMAGE_NAME} maintainer=${MAINTAINER}
35+
36+
# Limiting security access to not user root user
37+
RUN addgroup siriusxi && useradd -g siriusxi -ms /bin/bash taman
38+
39+
# Setting user to current created user
40+
USER taman
41+
42+
# Set working directory to application folder
43+
WORKDIR /home/taman/application
44+
45+
# Copy all layers from builder stage to current image
46+
COPY --from=builder temp/dependencies/ ./
47+
COPY --from=builder temp/snapshot-dependencies/ ./
48+
COPY --from=builder temp/spring-boot-loader/ ./
49+
COPY --from=builder temp/application/ ./
50+
51+
# Expose current server to port 9999
52+
EXPOSE 9999
53+
54+
ARG JAVA_OPTS=""
55+
56+
# Run the application with JVM configs if any
57+
ENTRYPOINT ["bash", "-c", \
58+
"java -server --enable-preview -XX:+UseContainerSupport -XX:+ShowCodeDetailsInExceptionMessages \
59+
-XX:+AlwaysActAsServerClassMachine -XX:+UseG1GC -XX:+UseStringDeduplication ${JAVA_OPTS} \
60+
org.springframework.boot.loader.JarLauncher ${0} ${@}"]

0 commit comments

Comments
 (0)