Skip to content

Commit 4e4e66c

Browse files
authored
Rev jackson-databind to deal with latest vulnerabilities. (#163)
* Fix Jackson databind to deal with latest CVE * rev minio version used in async thumbnails test to pick up newer jetty version * fix up async thumbnails to test new minio version
1 parent 4136d55 commit 4e4e66c

12 files changed

Lines changed: 138 additions & 113 deletions

File tree

examples/async-thumbnails/README.md

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ this example. Run:
3232
```
3333

3434
This will start a local functions service, a local flow completion
35-
service, and will set up a `myapp` application and three routes: `/resize128`,
36-
`/resize256` and `/resize512`. The routes are implemented as Fn functions
37-
which just invoke `imagemagick` to convert the images to the specified sizes.
35+
service, and will set up a `myapp` application and three functions: `resize128`,
36+
`resize256` and `resize512`. These functions just invoke `imagemagick` to convert the images to the specified sizes.
3837

3938
The setup script also starts a docker container with an object storage daemon
4039
based on `minio` (with access key `alpha` and secret key `betabetabetabeta`).
@@ -48,14 +47,9 @@ docker container, so that you can verify when the thumbnails are uploaded.
4847
Build the function locally:
4948

5049
```bash
51-
$ fn build
50+
$ fn deploy --local --app myapp
5251
```
5352

54-
Create a route to host the function:
55-
56-
```bash
57-
$ fn create route myapp /async-thumbnails
58-
```
5953

6054
Configure the app. In order to do this you must determine the IP address of the
6155
storage server docker container:
@@ -68,18 +62,18 @@ $ docker inspect --type container -f '{{range .NetworkSettings.Networks}}{{.IPAd
6862
and then use it as the storage host:
6963

7064
```bash
71-
$ fn config route myapp /async-thumbnails OBJECT_STORAGE_URL http://172.17.0.4:9000
65+
$ fn config app myapp OBJECT_STORAGE_URL http://172.17.0.4:9000
7266
myapp /async-thumbnails updated OBJECT_STORAGE_URL with http://172.17.0.4:9000
73-
$ fn config route myapp /async-thumbnails OBJECT_STORAGE_ACCESS alpha
67+
$ fn config app myapp OBJECT_STORAGE_ACCESS alpha
7468
myapp /async-thumbnails updated OBJECT_STORAGE_ACCESS with alpha
75-
$ fn config route myapp /async-thumbnails OBJECT_STORAGE_SECRET betabetabetabeta
69+
$ fn config app myapp OBJECT_STORAGE_SECRET betabetabetabeta
7670
myapp /async-thumbnails updated OBJECT_STORAGE_SECRET with betabetabetabeta
7771
```
7872

7973
Invoke the function by passing the provided test image:
8074

8175
```bash
82-
$ curl -X POST --data-binary @test-image.png -H "Content-type: application/octet-stream" "http://localhost:8080/r/myapp/async-thumbnails"
76+
$ curl -X POST --data-binary @test-image.png -H "Content-type: application/octet-stream" "http://localhost:8080/t/myapp/async-thumbnails"
8377
{"imageId":"bd74fff4-0388-4c6f-82f2-8cde9ba9b6fc"}
8478
```
8579

@@ -116,6 +110,13 @@ public class ThumbnailsFunction {
116110
.orElseThrow(() -> new RuntimeException("Missing configuration: OBJECT_STORAGE_ACCESS"));
117111
storageSecretKey = ctx.getConfigurationByKey("OBJECT_STORAGE_SECRET")
118112
.orElseThrow(() -> new RuntimeException("Missing configuration: OBJECT_STORAGE_SECRET"));
113+
114+
resize128ID = ctx.getConfigurationByKey("RESIZE_128_FN_ID")
115+
.orElseThrow(() -> new RuntimeException("Missing configuration: RESIZE_128_FN_ID"));
116+
resize256ID = ctx.getConfigurationByKey("RESIZE_256_FN_ID")
117+
.orElseThrow(() -> new RuntimeException("Missing configuration: RESIZE_256_FN_ID"));
118+
resize512ID = ctx.getConfigurationByKey("RESIZE_512_FN_ID")
119+
.orElseThrow(() -> new RuntimeException("Missing configuration: RESIZE_512_FN_ID"));
119120
}
120121

121122
// ...
@@ -155,11 +156,11 @@ public class ThumbnailsFunction {
155156
Flow runtime = Flows.currentFlow();
156157

157158
runtime.allOf(
158-
runtime.invokeFunction("myapp/resize128", HttpMethod.POST, Headers.emptyHeaders(), imageBuffer)
159+
runtime.invokeFunction(resize128ID, HttpMethod.POST, Headers.emptyHeaders(), imageBuffer)
159160
.thenAccept((img) -> objectUpload(img.getBodyAsBytes(), id + "-128.png")),
160-
runtime.invokeFunction("myapp/resize256", HttpMethod.POST, Headers.emptyHeaders(), imageBuffer)
161+
runtime.invokeFunction(resize256ID, HttpMethod.POST, Headers.emptyHeaders(), imageBuffer)
161162
.thenAccept((img) -> objectUpload(img.getBodyAsBytes(), id + "-256.png")),
162-
runtime.invokeFunction("myapp/resize512", HttpMethod.POST, Headers.emptyHeaders(), imageBuffer)
163+
runtime.invokeFunction(resize512ID, HttpMethod.POST, Headers.emptyHeaders(), imageBuffer)
163164
.thenAccept((img) -> objectUpload(img.getBodyAsBytes(), id + "-512.png")),
164165
runtime.supply(() -> objectUpload(imageBuffer, id + ".png"))
165166
);
@@ -218,8 +219,9 @@ in [Testing Functions](../../docs/TestingFunctions.md).
218219
```java
219220
public class ThumbnailsFunctionTest {
220221

221-
@Rule
222-
public final FnTestingRule testing = FnTestingRule.createDefault();
222+
@Rule
223+
public final FnTestingRule fn = FnTestingRule.createDefault();
224+
private final FlowTesting flow = FlowTesting.create(fn);
223225

224226
// ...
225227
}
@@ -259,20 +261,22 @@ public class ThumbnailsFunctionTest {
259261

260262
@Test
261263
public void testThumbnail() {
262-
testing
263264

264-
.setConfig("OBJECT_STORAGE_URL", "http://localhost:" + mockServer.port())
265-
.setConfig("OBJECT_STORAGE_ACCESS", "alpha")
266-
.setConfig("OBJECT_STORAGE_SECRET", "betabetabetabeta")
265+
fn.setConfig("OBJECT_STORAGE_URL", "http://localhost:" + mockServer.port())
266+
.setConfig("OBJECT_STORAGE_ACCESS", "alpha")
267+
.setConfig("OBJECT_STORAGE_SECRET", "betabetabetabeta")
268+
.setConfig("RESIZE_128_FN_ID","myapp/resize128")
269+
.setConfig("RESIZE_256_FN_ID","myapp/resize256")
270+
.setConfig("RESIZE_512_FN_ID","myapp/resize512");
267271

268-
.givenFn("myapp/resize128")
272+
flow.givenFn("myapp/resize128")
269273
.withAction((data) -> "128".getBytes())
270274
.givenFn("myapp/resize256")
271275
.withAction((data) -> "256".getBytes())
272276
.givenFn("myapp/resize512")
273277
.withAction((data) -> "512".getBytes())
274278

275-
.givenEvent()
279+
fn.givenEvent()
276280
.withBody("testing".getBytes())
277281
.enqueue();
278282

@@ -301,21 +305,23 @@ public class ThumbnailsFunctionTest {
301305

302306
@Test
303307
public void anExternalFunctionFailure() {
304-
testing
305-
.setConfig("OBJECT_STORAGE_URL", "http://localhost:" + mockServer.port())
306-
.setConfig("OBJECT_STORAGE_ACCESS", "alpha")
307-
.setConfig("OBJECT_STORAGE_SECRET", "betabetabetabeta")
308-
309-
.givenFn("myapp/resize128")
310-
.withResult("128".getBytes())
311-
.givenFn("myapp/resize256")
312-
.withResult("256".getBytes())
313-
.givenFn("myapp/resize512")
314-
.withFunctionError()
315-
316-
.givenEvent()
317-
.withBody("testing".getBytes())
318-
.enqueue();
308+
fn.setConfig("OBJECT_STORAGE_URL", "http://localhost:" + mockServer.port())
309+
.setConfig("OBJECT_STORAGE_ACCESS", "alpha")
310+
.setConfig("OBJECT_STORAGE_SECRET", "betabetabetabeta")
311+
.setConfig("RESIZE_128_FN_ID","myapp/resize128")
312+
.setConfig("RESIZE_256_FN_ID","myapp/resize256")
313+
.setConfig("RESIZE_512_FN_ID","myapp/resize512");
314+
315+
flow.givenFn("myapp/resize128")
316+
.withResult("128".getBytes())
317+
.givenFn("myapp/resize256")
318+
.withResult("256".getBytes())
319+
.givenFn("myapp/resize512")
320+
.withFunctionError();
321+
322+
fn.givenEvent()
323+
.withBody("testing".getBytes())
324+
.enqueue();
319325

320326
// Mock the http endpoint
321327
mockMinio();
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
name: fn-example/async-thumbnails
2-
version: 0.0.1
1+
schema_version: 20180708
2+
name: async-thumbnails
3+
version: 0.0.8
34
runtime: java
45
cmd: com.fnproject.fn.examples.ThumbnailsFunction::handleRequest
5-
path: /async-thumbnails
6-
format: http
7-
timeout: 30
6+
format: http-stream
7+
timeout: 120
8+
triggers:
9+
- name: async-thumbnails
10+
type: http
11+
source: /async-thumbnails

examples/async-thumbnails/pom.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
<fdk.version>1.0.0-SNAPSHOT</fdk.version>
1212
<mockito.version>2.8.47</mockito.version>
13+
<jackson.version>2.9.7</jackson.version>
1314
</properties>
1415

1516
<groupId>com.fnproject.fn.examples</groupId>
1617
<artifactId>async-thumbnails</artifactId>
1718
<version>1.0.0-SNAPSHOT</version>
1819

1920
<dependencies>
21+
2022
<dependency>
2123
<groupId>com.fnproject.fn</groupId>
2224
<artifactId>api</artifactId>
@@ -32,10 +34,15 @@
3234
<artifactId>commons-net</artifactId>
3335
<version>3.6</version>
3436
</dependency>
37+
<dependency>
38+
<groupId>com.fasterxml.jackson.core</groupId>
39+
<artifactId>jackson-databind</artifactId>
40+
<version>${jackson.version}</version>
41+
</dependency>
3542
<dependency>
3643
<groupId>io.minio</groupId>
3744
<artifactId>minio</artifactId>
38-
<version>3.0.12</version>
45+
<version>5.0.1</version>
3946
</dependency>
4047
<dependency>
4148
<groupId>com.fnproject.fn</groupId>
@@ -65,7 +72,7 @@
6572
<dependency>
6673
<groupId>com.github.tomakehurst</groupId>
6774
<artifactId>wiremock</artifactId>
68-
<version>2.18.0</version>
75+
<version>2.19.0</version>
6976
</dependency>
7077
</dependencies>
7178

examples/async-thumbnails/run.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
#!/bin/bash
2+
set -e
23

3-
fn build
4+
fn --verbose deploy --app myapp --local
45

5-
fn create route myapp /async-thumbnails
66

7-
STORAGE_SERVER_IP=`docker inspect --type container -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' example-storage-server`
8-
fn config route myapp /async-thumbnails OBJECT_STORAGE_URL http://${STORAGE_SERVER_IP}:9000
9-
fn config route set myapp /async-thumbnails OBJECT_STORAGE_ACCESS alpha
10-
fn config route set myapp /async-thumbnails OBJECT_STORAGE_SECRET betabetabetabeta
11-
12-
curl -X POST --data-binary @test-image.png -H "Content-type: application/octet-stream" "http://localhost:8080/r/myapp/async-thumbnails"
7+
echo "Calling function"
8+
curl -v -X POST --data-binary @test-image.png -H "Content-type: application/octet-stream" "http://localhost:8080/t/myapp/async-thumbnails"
139

1410
echo "Contents of bucket"
1511
mc ls -r example-storage-server
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: example/resize128
2-
version: 0.0.1
1+
schema_version: 20180708
2+
name: resize128
3+
version: 0.0.5
34
entrypoint: convert - -resize 128x128 -
4-
path: /resize128
5+
format: default
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: example/resize256
2-
version: 0.0.1
1+
schema_version: 20180708
2+
name: resize256
3+
version: 0.0.5
34
entrypoint: convert - -resize 256x256 -
4-
path: /resize256
5+
format: default
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: example/resize512
2-
version: 0.0.1
1+
schema_version: 20180708
2+
name: resize512
3+
version: 0.0.8
34
entrypoint: convert - -resize 512x512 -
4-
path: /resize512
5+
format: default

examples/async-thumbnails/setup/setup.sh

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,21 @@ fi
5151
STORAGE_SERVER_IP=`docker inspect --type container -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' example-storage-server`
5252

5353
# Start functions server if not there
54-
if [[ -z `docker ps | grep "functions"` ]]; then
55-
docker run -d --name functions \
56-
-e NO_PROXY="$STORAGE_SERVER_IP:$NO_PROXY" \
57-
-p 8080:8080 \
58-
-v /var/run/docker.sock:/var/run/docker.sock \
59-
"$FUNCTIONS_IMAGE"
60-
# Give it time to start up
54+
if [[ -z `docker ps | grep "fnserver"` ]]; then
55+
fn start -d
6156
sleep 3
6257
else
6358
echo "Functions server is already up."
6459
fi
6560
# Get its IP
66-
FUNCTIONS_SERVER_IP=`docker inspect --type container -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' functions`
61+
FUNCTIONS_SERVER_IP=`docker inspect --type container -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' fnserver`
6762

6863
# Start flow service if not there
6964
if [[ -z `docker ps | grep "flow-service"` ]]; then
7065
docker run -d --name flow-service \
7166
-e LOG_LEVEL=debug \
7267
-e NO_PROXY="$FUNCTIONS_SERVER_IP:$NO_PROXY" \
73-
-e API_URL=http://$FUNCTIONS_SERVER_IP:8080/r \
68+
-e API_URL=http://$FUNCTIONS_SERVER_IP:8080/invoke \
7469
-p 8081:8081 \
7570
"$COMPLETER_IMAGE"
7671
# Give it time to start up
@@ -86,42 +81,37 @@ if [[ `fn list apps` == *"myapp"* ]]; then
8681
echo "App myapp is already there."
8782
else
8883
fn create app myapp
89-
fn config app myapp COMPLETER_BASE_URL http://10.167.103.193:8081
9084
fi
9185

92-
if [[ `fn list routes myapp` == *"/resize128"* ]]; then
93-
echo "Route /resize128 is already there."
94-
else
95-
# This works around proxy issues
96-
cd $SCRIPT_DIR/resize128 && \
97-
docker build -t example/resize128:0.0.1 \
98-
--build-arg http_proxy=$http_proxy \
99-
--build-arg https_proxy=$https_proxy \
100-
. && \
101-
fn create route myapp /resize128
102-
fi
103-
if [[ `fn list routes myapp` == *"/resize256"* ]]; then
104-
echo "Route /resize256 is already there."
105-
else
106-
# This works around proxy issues
107-
cd $SCRIPT_DIR/resize256 && \
108-
docker build -t example/resize256:0.0.1 \
109-
--build-arg http_proxy=$http_proxy \
110-
--build-arg https_proxy=$https_proxy \
111-
. && \
112-
fn create route myapp /resize256
113-
fi
114-
if [[ `fn list routes myapp` == *"/resize512"* ]]; then
115-
echo "Route /resize512 is already there."
116-
else
117-
# This works around proxy issues
118-
cd $SCRIPT_DIR/resize512 && \
119-
docker build -t example/resize512:0.0.1 \
120-
--build-arg http_proxy=$http_proxy \
121-
--build-arg https_proxy=$https_proxy \
122-
. && \
123-
fn create route myapp /resize512
124-
fi
86+
87+
fn config app myapp COMPLETER_BASE_URL http://${COMPLETER_SERVER_IP}:8081
88+
fn config app myapp OBJECT_STORAGE_URL http://${STORAGE_SERVER_IP}:9000
89+
fn config app myapp OBJECT_STORAGE_ACCESS alpha
90+
fn config app myapp OBJECT_STORAGE_SECRET betabetabetabeta
91+
92+
(
93+
cd ${SCRIPT_DIR}/resize128
94+
fn deploy --app myapp --local
95+
)
96+
97+
fn config app myapp RESIZE_128_FN_ID $(fn list functions myapp | grep resize128 | awk '{print $3}')
98+
99+
(
100+
cd ${SCRIPT_DIR}/resize256
101+
fn deploy --app myapp --local
102+
)
103+
104+
fn config app myapp RESIZE_256_FN_ID $(fn list functions myapp | grep resize256 | awk '{print $3}')
105+
106+
107+
(
108+
cd ${SCRIPT_DIR}/resize512
109+
fn deploy --app myapp --local
110+
)
111+
112+
fn config app myapp RESIZE_512_FN_ID $(fn list functions myapp | grep resize512 | awk '{print $3}')
113+
114+
125115

126116

127117
if mc config host list | grep example-storage-server &>/dev/null ; then

0 commit comments

Comments
 (0)