Skip to content

Commit 26a08c4

Browse files
committed
Add support for a Quickstart Docker image
This change adds support for generating a valid Docker image containing the Parsec service and client tool which can be used for introductory quickstart operations. It also refactors the construction of the quickstart tarball to take advantage of a Docker-based build environment. Signed-off-by: Dennis Gove <dgove1@bloomberg.net>
1 parent 199285b commit 26a08c4

File tree

8 files changed

+292
-131
lines changed

8 files changed

+292
-131
lines changed

.dockerignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
quickstart/quickstart.Dockerfile
2+
quickstart/package.sh
3+
quickstart/*.tar.gz
4+
.idea/
5+
6+
# Copied from .gitignore
7+
/target
8+
*.psa_its
9+
*.swp
10+
tags
11+
*DS_Store
12+
*vscode
13+
*.patch
14+
mappings/
15+
kim-mappings/
16+
NVChip
17+
.devcontainer

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ kim-mappings/
2626
# TPM simulator state file
2727
NVChip
2828
.devcontainer
29+
30+
# Quickstart tarball
31+
quickstart/*.tar.gz
32+
33+
# IDE settings files
34+
.idea

packaging_assets/package.sh

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

quickstart/docker_README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Parsec Quickstart - Docker
2+
3+
This Docker container is constructed specifically as an introductory quickstart for the Parsec service and client tool. It is not intended for use in any production system.
4+
5+
The container is started with the following command
6+
7+
```bash
8+
$> docker run --rm --name parsec -it parsec-quickstart bash
9+
qs@319b139eb85e:/parsec/quickstart$
10+
```
11+
12+
## Directory Layout & Environment Settings
13+
14+
```
15+
parsec
16+
├── bin
17+
│ ├── parsec # The parsec binary
18+
│ └── parsec-tool # The parsec client tool
19+
└── quickstart
20+
├── README.md # This README
21+
├── config.toml # The config file used by parsec
22+
└── parsec-cli-tests.sh # Standard parsec-tool tests
23+
```
24+
25+
```
26+
PWD=/parsec/quickstart
27+
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/parsec/bin
28+
PARSEC_SERVICE_ENDPOINT=unix:/parsec/quickstart/parsec.sock
29+
```
30+
31+
## Usage
32+
33+
The following describe standard quickstart usage examples.
34+
35+
### Start the PARSEC service
36+
37+
```bash
38+
# This will execute the parsec binary found in /parsec/bin using the config file
39+
# found at /parsec/quickstart/config.toml.
40+
# The socket path will be placed at /parsec/quickstart/parsec.sock
41+
qs@319b139eb85e:/parsec/quickstart$ parsec &
42+
[INFO parsec] Parsec started. Configuring the service...
43+
[INFO parsec_service::key_info_managers::sqlite_manager] SQLiteKeyInfoManager - Found 0 key info mapping records
44+
[INFO parsec_service::utils::service_builder] Creating a Mbed Crypto Provider.
45+
[INFO parsec] Parsec is ready.
46+
47+
qs@319b139eb85e:/parsec/quickstart$
48+
```
49+
50+
### Ping Parsec
51+
52+
```bash
53+
# This will execute a ping command using the parsec-tool binary.
54+
# The container has already configured the environment variable
55+
# PARSEC_SERVICE_ENDPOINT=unix:/parsec/quickstart/parsec.sock
56+
# which will allow all parsec-tool commands to successfully find
57+
# the necessary socket.
58+
qs@319b139eb85e:/parsec/quickstart$ parsec-tool ping
59+
[INFO ] Service wire protocol version
60+
1.0
61+
```
62+
63+
### Parsec Tool Examples
64+
65+
```bash
66+
# List Providers
67+
qs@319b139eb85e:/parsec/quickstart$ parsec-tool list-providers
68+
[INFO ] Available providers:
69+
ID: 0x01 (Mbed Crypto provider)
70+
Description: User space software provider, based on Mbed Crypto - the reference implementation of the PSA crypto API
71+
Version: 0.1.0
72+
Vendor: Arm
73+
UUID: 1c1139dc-ad7c-47dc-ad6b-db6fdb466552
74+
75+
ID: 0x00 (Core provider)
76+
Description: Software provider that implements only administrative (i.e. no cryptographic) operations
77+
Version: 1.1.0
78+
Vendor: Unspecified
79+
UUID: 47049873-2a43-4845-9d72-831eab668784
80+
81+
# Create RSA Key
82+
qs@319b139eb85e:/parsec/quickstart$ parsec-tool create-rsa-key --key-name demo1
83+
[INFO ] Creating RSA encryption key...
84+
[INFO ] Key "demo1" created.
85+
86+
# Encrypt data using the RSA Key
87+
qs@319b139eb85e:/parsec/quickstart$ parsec-tool encrypt --key-name demo1 "Super secret data"
88+
[INFO ] Encrypting data with RsaPkcs1v15Crypt...
89+
RuPgZld6....brHqQd7xJg==
90+
91+
# Decrypt ciphertext using the RSA Key
92+
qs@319b139eb85e:/parsec/quickstart$ parsec-tool decrypt --key-name demo1 RuPgZld6....brHqQd7xJg==
93+
[INFO ] Decrypting data with RsaPkcs1v15Crypt...
94+
Super secret data
95+
```
96+
97+
### Run the Test Script
98+
99+
```bash
100+
qs@319b139eb85e:/parsec/quickstart$ ./parsec-cli-tests.sh
101+
Checking Parsec service...
102+
[INFO ] Service wire protocol version
103+
1.0
104+
105+
Testing Mbed Crypto provider
106+
107+
- Test random number generation
108+
[INFO ] Generating 10 random bytes...
109+
[INFO ] Random bytes:
110+
24 A1 19 DB 3F 3C A0 82 FE 63
111+
....
112+
```

quickstart/package.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
# Copyright 2022 Contributors to the Parsec project.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Create a quickstart package
7+
8+
# Avoid silent failures
9+
set -euf -o pipefail
10+
11+
PACKAGE_PATH=$(pwd)
12+
ASSETS_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
13+
PARSEC_DIR=$(dirname $ASSETS_DIR)
14+
15+
# Usage
16+
USAGE_STR=\
17+
"Usage:\n"\
18+
"package.sh [Options]\n"\
19+
"Options:\n"\
20+
" -o {path}: Output absolute path, the default path is the current directory i.e. $(pwd)\n"\
21+
" -h : Display this help menu\n"
22+
23+
# Flags
24+
while getopts v:o:j:h flag
25+
do
26+
case "${flag}" in
27+
o) PACKAGE_PATH=${OPTARG};;
28+
h) echo -e $USAGE_STR; exit 0;;
29+
esac
30+
done
31+
32+
check_release_tag() {
33+
CURRENT_TAG=$(git name-rev --tags HEAD | cut -d "/" -f 2)
34+
LATTEST_TAG=$(git tag --sort=committerdate | tail -1)
35+
if [ -z "$LATTEST_TAG" ];then
36+
echo "Warning:No tags"
37+
fi
38+
if [ "$LATTEST_TAG" == "$CURRENT_TAG" ]; then
39+
echo "Packaging release tag: $LATTEST_TAG"
40+
else
41+
echo "Warning: The current HEAD does't match the latest tagged"
42+
echo "Warning: Please checkout the latest tag : $LATTEST_TAG"
43+
read -n 1 -p "Do you want to continue anyway [y/n]?" choice
44+
if [ "$choice" != "y" ]; then
45+
exit 1
46+
fi
47+
fi
48+
}
49+
50+
build_runnable_image() {
51+
docker build --target runnable_image --tag parsec-quickstart -f quickstart.Dockerfile ${PARSEC_DIR}
52+
}
53+
54+
build_extract_tarball() {
55+
docker build --target tarball_builder --tag parsec-quickstart-tarball -f quickstart.Dockerfile ${PARSEC_DIR}
56+
57+
# Extract the tarball out of the image used to construct it and place it in ${PACKAGE_PATH}
58+
docker run -v ${PACKAGE_PATH}:/opt/mount --rm parsec-quickstart-tarball bash -c 'cp /parsec-tar/*.tar.gz /opt/mount/'
59+
}
60+
61+
echo "Packaging started..."
62+
63+
trap EXIT
64+
65+
check_release_tag
66+
build_runnable_image
67+
build_extract_tarball
68+
69+
echo "Finalizing packages"

0 commit comments

Comments
 (0)