Skip to content

Commit 283c209

Browse files
committed
ID-39: support encrypted secrets
1 parent 604a1c4 commit 283c209

27 files changed

+554
-33
lines changed

CHANGELOG.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
|Base directory for certificate files.
1010

1111
Use the `--base-dir` parameter of the configuration tool or the `axway.config.certs.basedir` property of the plugin to specify the base directory for certificate files.
12+
13+
|https://github.com/Axway-API-Management-Plus/apigw-maven-plugin/issues/39[#39]
14+
|Enhancement
15+
|Support for confidential properties.
16+
17+
For confidential properties the configuration tools supports to pass a secrets file.
18+
It is a JSON file where the values of the properties are encrypted by a passphrase.
19+
1220
|===
1321

1422
== Version 0.12.0

doc/manual/_config-tool.adoc

Lines changed: 112 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The FED builder takes the `.pol` and `.env` archive and JSON files to configure
2121
The script is invoked with the `jython` interpreter provided with the package and deployment tools of the API Gateway.
2222

2323
....
24-
$ jython buildfed.py --help
24+
$ buildfed.sh --help
2525
Usage: buildfed.py OPTIONS
2626
2727
Options:
@@ -56,7 +56,13 @@ Options:
5656
--passphrase-out=PASSPHRASE
5757
Passphrase for output archive files [optional]
5858
-s, --simulate Enable simulation mode [optional]
59-
-b, --base-dir Base directory for certificate files [optional]
59+
-b DIRECTORY, --base-dir=DIRECTORY
60+
Base directory for certificate files [optional]
61+
--secrets-file=FILEPATH
62+
Path of JSON file containing confidential propertiers
63+
[optional]
64+
--secrets-passphrase=PASSPHRASE
65+
Passphrase to decrypt confidential properties [optional]
6066
....
6167

6268
If environmentalized fields or certificates are not configured, the build fails.
@@ -67,7 +73,6 @@ Missing fields or certificates are automatically added to the configuration file
6773
|Option
6874
|Description
6975

70-
7176
|-e, --env
7277
|The `.env` file as generated by the `projpack` tool.
7378
The option is mandatory.
@@ -150,9 +155,75 @@ To avoid errors due to incompatible types (e.g. placeholder string used for an i
150155
|-b, --base-dir
151156
|Base directory for certificate files.
152157
If specified relative path to certificate files is based on this directory.
158+
159+
|--secrets-file
160+
|Path of JSON file containing confidential properties.
161+
The file has to be created by the `encrypt` tool.
162+
163+
|--secrets-passphrase
164+
|Passphrase to decryt confidential properties.
165+
This parameter is requried if a secrets file is specified.
166+
The passphrase has to be the same as on creating the secrets file.
153167
|===
154168

155169

170+
== Encrypt Secrets
171+
172+
The `encrypt` tools is used to generate an initial secrets file and to encrypt the values of the properties.
173+
The script is invoked with the `jython` interpreter provided with the package and deployment tools of the API Gateway.
174+
175+
The tool requries a path to the secrets file and a passphrase to encryt the values.
176+
If the secrets file doesn't exist a new file will be created.
177+
For existing files the given passphrase is checked against the passphrase used on file creation.
178+
179+
....
180+
$ encrypt.sh -h
181+
Usage: secrets.py OPTIONS
182+
183+
Options:
184+
--version show program's version number and exit
185+
-h, --help show this help message and exit
186+
-v, --verbose Enable verbose messages [optional]
187+
--secrets-file=FILEPATH
188+
Path of JSON file containing confidential properties
189+
--secrets-passphrase=PASSPHRASE
190+
Passphrase to decrypt confidential values
191+
192+
Encrypt credentials.
193+
....
194+
195+
[cols="2,5a", options="header"]
196+
|===
197+
|Option
198+
|Description
199+
200+
|--secrets-file
201+
|Path of JSON file containing confidential properties.
202+
203+
|--secrets-passphrase
204+
|Passphrase to decrypt confidential properties.
205+
This parameter is requried if a secrets file is specified.
206+
|===
207+
208+
To add new properties tag the values with the `encrypt:` prefix.
209+
Values having this prefix will be encrypted on running the tool.
210+
211+
[source,json]
212+
----
213+
{
214+
"secrets": {
215+
"__": "3QjoMSfhSelmvMlvcgCdyHf+oTyVnHlyneA3stpN0iQKJ1BUIrY9OA==", <1>
216+
"my.password": "encrypt:changeme", <2>
217+
"cert.password": "eL5+ogfSxQue8+NA0/l859g/2nTFwxBUp/7l7z/sMOE=" <3>
218+
}
219+
}
220+
----
221+
<1> Marker to check the passphrase. Don't delete or change it.
222+
<2> The prefix `encrypt:` indicates that the value `changeme` has to be encrypted.
223+
<3> Values without the prefix are already encrypted and will not be changed.
224+
225+
NOTE: The `encrypt` tool use the cipher of the entity store.
226+
156227
== Configuration Files
157228

158229
For the configuration of the environment specific deployment archive, various configuration files are used.
@@ -269,9 +340,20 @@ If the `gateway.info.json` file is not available the property contains an empty
269340
"value": "USERNAME" <11>
270341
}
271342
}
343+
},
344+
"/[CircuitContainer]name=Hello World/[FilterCircuit]name=Hello World Message/[SetAttributeFilter]name=Secret": {
345+
"description": "Some secret information",
346+
"fields": {
347+
"attributeValue#0": {
348+
"source": "secrets" <12>
349+
"type": "string",
350+
"used": true,
351+
"value": "secret" <13>
352+
}
353+
}
272354
}
273355
}
274-
"properties": { <12>
356+
"properties": { <14>
275357
"foobar": "myvalue"
276358
}
277359
}
@@ -289,9 +371,12 @@ The property is automatically maintained by the plugin.
289371
<9> Literal value for the field.
290372
<10> Specifies an environment variable as the source for the field value.
291373
<11> Field value is retrieved from the `USERNAME` environment variable.
292-
<12> An optional local definition of properties.
374+
<12> Specifies an property from the secrets file as the source for the field value.
375+
<13> Field value is retrieved from the `secret` property in the secrets file.
376+
<14> An optional local definition of properties.
293377
If the same property is defined in a separate property file (see below), the separate property has precedence.
294378

379+
295380
NOTE: If `value` is _null_ the field is treated as undefined and the build will fail.
296381

297382
=== Certificates
@@ -418,3 +503,25 @@ The shift of properties to a separate file enables them to be exclude from the s
418503
In productive environments secretes may be stored in a secured configuration database.
419504
For the build process the property file may be temporarily generated from the configuration database.
420505
====
506+
507+
=== Secrets
508+
509+
A secrets file is used to store confidential configurations (e.g. passwords).
510+
The values of the properties are encrypted and can be access with a passphrase only.
511+
All values are encrypted with the same passphrase.
512+
513+
.gateway.crypt.json
514+
[source,json]
515+
----
516+
{
517+
"secrets": { <1>
518+
"__": "3QjoMSfhSelmvMlvcgCdyHf+oTyVnHlyneA3stpN0iQKJ1BUIrY9OA==", <2>
519+
"my.password": "encrypt:changeme", <3>
520+
"cert.password": "eL5+ogfSxQue8+NA0/l859g/2nTFwxBUp/7l7z/sMOE=" <4>
521+
}
522+
}
523+
----
524+
<1> The `secrets` property is requried.
525+
<2> Marker to check the passphrase. Don't delete or change it.
526+
<3> The prefix `encrypt:` indicates that the value `changeme` has to be encrypted by the `encrypt` tool.
527+
<4> Values without the prefix are already encrypted.

doc/manual/_reference.adoc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ Default: 8090
357357
Default: admin
358358

359359
|axway.anm.password
360-
|Password word Admin Node Manager (required for deployment only)
360+
|Password for Admin Node Manager (required for deployment only)
361361

362362
Default: _none_
363363

@@ -372,6 +372,12 @@ Default: _none_
372372
Default: false
373373

374374
NOTE: It is not checked if the source files are newer than the target artifact.
375+
376+
|axway.config.secrets.file
377+
|Path to file storing secrets.
378+
379+
|axway.config.secrets.passphrase
380+
|Passphrase to decrypt/encrypt values of secrets file.
375381
|===
376382

377383
== Plugin Configuration
@@ -400,6 +406,9 @@ The plugin can also be configured in the `pom.xml` via the <configuration> eleme
400406
</configPropertFiles>
401407
402408
<configCertsBaseDir>${basedir}/src/main/axwgw/certs</configCertsBaseDir> <!--5-->
409+
410+
<configSecretsFile>${basedir}/src/main/axwgw/gateway.crypt.json</configSecretsFile> <!--6-->
411+
<configSecretsPassphrase>changeme</configSecretsPassphrase> <!--7-->
403412
</configuration>
404413
</plugin>
405414
<!- ... ->
@@ -409,3 +418,5 @@ The plugin can also be configured in the `pom.xml` via the <configuration> eleme
409418
<3> Location of a configuration file for properties.
410419
<4> Location of a list of configuration files for properties.
411420
<5> Base directory for certificate files.
421+
<6> Path to secrets file.
422+
<7> Passphrase to decrypt/encrypt values of secrets file.

doc/manual/_usage.adoc

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ For deployment following properties are used:
236236
|`axway.config.props.files`
237237
|Comma separated list of paths to properties configuration files.
238238
|no
239+
240+
|`axway.config.secrets.file`
241+
|Path to secrets file.
242+
|no
243+
244+
|`axway.config.secrets.passphrase`
245+
|Passphrase to decrypt/encrypt values of secrets file.
246+
|yes, if secrets file is specified
239247
|===
240248

241249
Example:
@@ -378,7 +386,34 @@ The plugin includes some Python based scripts to configure environment specific
378386
The scripts can also be used as standalone tools.
379387
The goal `apigw:tools` extracts the included script to the `${project.build.directory}/tools` directory.
380388

381-
$ mvn apigw:tools
389+
.Command Line
390+
....
391+
$ mvn apigw:tools
392+
....
393+
394+
=== Encrypt Secrets File
395+
To create an empty secrets file or to add properties to secrets file, the goal `apigw:encrypt` can be used.
396+
A passphrase is used to initially create the secrets file.
397+
The same passphrase as used to create the file has to be used to decrypt values.
398+
399+
.gateway.crypt.json
400+
[source,json]
401+
----
402+
{
403+
"secrets": { <1>
404+
"__": "3QjoMSfhSelmvMlvcgCdyHf+oTyVnHlyneA3stpN0iQKJ1BUIrY9OA==", <2>
405+
"my.password": "encrypt:changeme", <3>
406+
}
407+
}
408+
----
409+
<1> The `secrets` property is requried.
410+
<2> Marker to check the passphrase. Don't delete or change it.
411+
<3> The prefix `encrypt:` indicates that the value `changeme` has to be encrypted by the `encrypt` tool.
412+
413+
.Command Line
414+
....
415+
$ mvn apigw:encrypt -Daxway.config.secrets.file=gateway.crypt.json -Daxway.config.secrets.passphrase=changeme
416+
....
382417

383418
== Maven Goals
384419
This section provides a short overview of the goals supported by the Maven plugin.
@@ -419,4 +454,8 @@ This section provides a short overview of the goals supported by the Maven plugi
419454
|apigw:deploy
420455
|Deploy project to a gateway.
421456
|yes|yes|yes
457+
458+
|apigw:encrypt
459+
|Encrypt plain values of secrets file.
460+
|yes|yes|yes
422461
|===

example/config-tool/config/gateway.certs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"update": {
1919
"file": "staged-server.p12",
2020
"password": "cert.password.staged.server",
21-
"source": "property",
21+
"source": "secrets",
2222
"type": "p12"
2323
}
2424
},

example/config-tool/config/gateway.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"description": "",
4949
"fields": {
5050
"address#0": {
51-
"source": "property",
51+
"source": "secrets",
5252
"type": "string",
5353
"used": true,
5454
"value": "service.address"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"secrets": {
3+
"__": "3QjoMSfhSelmvMlvcgCdyHf+oTyVnHlyneA3stpN0iQKJ1BUIrY9OA==",
4+
"cert.password.staged.server": "Y4H5Is1CiuA8V3jN91y1qpxc3n5IBbM9DSbWH5kqq6w=",
5+
"service.address": "eL5+ogfSxQue8+NA0/l859g/2nTFwxBUp/7l7z/sMOE="
6+
}
7+
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"properties": {
3-
"service.address": "localhost",
43
"service.port": 18443
54
}
65
}

example/config-tool/config/passwords.props.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

example/config-tool/encrypt.cmd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@ECHO off
2+
SETLOCAL
3+
SET CMD_HOME=%~dp0
4+
CD /d "%CMD_HOME%"
5+
SET ENCRYPT="..\..\src\main\resources\scripts\encrypt.cmd"
6+
7+
CALL %ENCRYPT% --secrets-file=config/gateway.crypt.json --secrets-passphrase=changeme
8+
ENDLOCAL

0 commit comments

Comments
 (0)