Skip to content

Commit 8febcb3

Browse files
committed
Cleaning, fixing Elgamal parameter set, run jwt-keypair post install, tls
1 parent 76d4c35 commit 8febcb3

29 files changed

+224
-469
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ yarn-error.log
2525
/_docker/
2626
/.env.testing
2727
/apache2.conf
28-
/resources/js/github/vuesocial/
2928
/letsencrypt/
3029
.idea/
3130
setup/registry/registry-creds

Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
77
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
88
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
99

10-
RUN echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
11-
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
12-
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini
13-
1410
# Set the working directory
1511
WORKDIR /var/www/html
1612

@@ -33,6 +29,6 @@ RUN chown -R www-data:www-data .
3329

3430
# Install project dependencies
3531
RUN composer install
36-
RUN composer dump-autoload -o
32+
RUN composer dump-autoload
3733

3834
RUN php artisan storage:link

README.md

Lines changed: 6 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,24 @@ helm repo update
2525
helm install ingress-nginx ingress-nginx/ingress-nginx
2626
# wait some time!
2727

28-
# Install a private registry
29-
cd setup/registry
30-
./install.sh install
31-
# ./uninstall.sh
32-
33-
# Create regcred in node namespace
34-
./setup/registry/install.sh regcred <namespace>
35-
3628
```
3729

3830
# Install
3931

4032
```shell
41-
4233
docker build -t biscofil/kairos_php:webserver .
4334
docker tag biscofil/kairos_php:webserver biscofil/kairos_php:webserver-1.0.0
44-
docker push biscofil/kairos_php:webserver-1.0.0
35+
kind load docker-image biscofil/kairos_php:webserver-1.0.0
4536

46-
docker tag biscofil/kairos_php:webserver docker-registry.127.0.0.1.nip.io/kairos_php:webserver-1.0.0
37+
docker tag biscofil/kairos_php:webserver docker.io/kairos_php:webserver-1.0.0
4738
# echo registryPass | docker login -u admin docker-registry.127.0.0.1.nip.io --password-stdin
48-
docker push docker-registry.127.0.0.1.nip.io/kairos_php:webserver-1.0.0
39+
kind load docker-image docker.io/kairos_php:webserver-1.0.0
4940

5041
# SSL
5142

5243
./cert.sh
5344

5445
openssl req -x509 -nodes -days 2 -newkey rsa:2048 -keyout ingress-tls.key -out ingress-tls.crt -subj "/CN=kairos-webserver.127.0.0.1.nip.io"
55-
5646
kubectl delete secret my-tls-secret
5747
kubectl create secret tls my-tls-secret --key ingress-tls.key --cert ingress-tls.crt
5848
rm ingress-tls.key ingress-tls.crt
@@ -63,10 +53,9 @@ helm package helm
6353

6454
# Deploy one node
6555
kubectl create ns node1
66-
# TODO generate random values in helm_secret.ini
67-
# php artisan key:generate
68-
# php artisan generate:jwt-keypair
69-
56+
# generate random values into helm_secret.ini
57+
python3 generate_secret_ini_file.py
58+
# TODO: manually insert missing values in helm_secret.ini
7059
kubectl create secret generic kairos-secrets --from-env-file=helm_secret.ini --namespace node1
7160
helm install kairos Kairos-0.1.0.tgz --namespace node1 -f values.yaml
7261
helm upgrade kairos Kairos-0.1.0.tgz --namespace node1 -f values.yaml
@@ -82,59 +71,6 @@ helm upgrade kairos Kairos-0.1.0.tgz --namespace node1 -f values.yaml
8271
- remove folder creation in docker image
8372
- adapt `php artisan generate:jwt-keypair` to kubernertes
8473

85-
# Legacy (deprecated)
86-
87-
```shell
88-
#install docker (https://docs.docker.com/engine/install/ubuntu/)
89-
sudo apt-get update
90-
sudo apt-get install \
91-
apt-transport-https \
92-
ca-certificates \
93-
curl \
94-
gnupg \
95-
lsb-release
96-
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
97-
echo \
98-
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
99-
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
100-
sudo apt-get update
101-
sudo apt-get install docker-ce docker-ce-cli containerd.io
102-
103-
# install docker-compose (https://docs.docker.com/compose/install/)
104-
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
105-
sudo chmod +x /usr/local/bin/docker-compose
106-
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
107-
108-
109-
# disable SSL commenting 000-default.conf
110-
mkdir helios
111-
112-
U_ID=$(id -u $USER) G_ID=$(id -u $USER) docker-compose up -d
113-
docker pull certbot/certbot
114-
# RUN docker run -it --rm -v $(pwd)/letsencrypt/c.....
115-
# enable SSL commenting 000-default.conf
116-
U_ID=$(id -u $USER) G_ID=$(id -u $USER) docker-compose down
117-
U_ID=$(id -u $USER) G_ID=$(id -u $USER) docker-compose up -d
118-
# php artisan key:generate
119-
# php artisan generate:jwt-keypair
120-
# php artisan storage:link
121-
```
122-
123-
# Adding SSL to the server domain.xyz (deprecated)
124-
125-
```shell
126-
docker pull certbot/certbot
127-
U_ID=$(id -u $USER) G_ID=$(id -u $USER) docker-compose build
128-
U_ID=$(id -u $USER) G_ID=$(id -u $USER) docker-compose up -d
129-
U_ID=$(id -u $USER) G_ID=$(id -u $USER) docker-compose down
130-
docker run -it --rm -v $(pwd)/letsencrypt/certs:/etc/letsencrypt -v $(pwd)/letsencrypt/data:/data/letsencrypt \
131-
certbot/certbot certonly \
132-
--webroot \
133-
--webroot-path=/data/letsencrypt \
134-
-d domain.xyz \
135-
--email your@email.com \
136-
--agree-tos
137-
```
13874

13975
# Docker changes (deprecated)
14076

app/Models/Election.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class Election extends Model
173173
//
174174
'min_peer_count_t' => 'int',
175175
'anonymization_method' => AnonymizationMethodEnum::class,
176-
'cryptosystem' => CryptoSystemEnum::class,
176+
'cryptosystem' => CryptoSystemEnum::class, // TODO also store parameters (P,G,Q)
177177
'public_key' => PublicKeyCaster::class,
178178
'private_key' => SecretKeyCaster::class,
179179
//

app/Providers/AppServiceProvider.php

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,80 @@
55
use App\Models\PeerServer;
66
use Illuminate\Support\Facades\Log;
77
use Illuminate\Support\Facades\Schema;
8+
use Illuminate\Support\Facades\DB;
89
use Illuminate\Support\ServiceProvider;
910

1011
class AppServiceProvider extends ServiceProvider
1112
{
1213

13-
// public const ActAsPeerServerKey = 'act_as_peer_server';
14+
// public const ActAsPeerServerKey = 'act_as_peer_server';
1415

15-
/**
16-
* Register any application services.
17-
* @return void
18-
* @noinspection PhpMissingParentCallCommonInspection
19-
*/
20-
public function register()
21-
{
22-
//
23-
}
16+
/**
17+
* Register any application services.
18+
* @return void
19+
* @noinspection PhpMissingParentCallCommonInspection
20+
*/
21+
public function register()
22+
{
23+
//
24+
}
2425

25-
/**
26-
* Bootstrap any application services.
27-
*
28-
* @return void
29-
*/
30-
public function boot()
31-
{
26+
/**
27+
* Bootstrap any application services.
28+
*
29+
* @return void
30+
*/
31+
public function boot()
32+
{
3233

33-
Schema::defaultStringLength(191);
34+
try {
35+
DB::connection();
36+
} catch (\Exception $e) {
37+
Log::warning('Leaving AppServiceProvider because DB connection is not made');
38+
return;
39+
}
3440

35-
$connection = config('database.default');
36-
$driver = config("database.connections.{$connection}.driver");
37-
if ($driver === "sqlite") {
38-
\Illuminate\Support\Facades\DB::getDoctrineSchemaManager()
39-
->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'string');
40-
}
41+
Schema::defaultStringLength(191);
4142

42-
$me = null;
43-
try {
43+
$connection = config('database.default');
44+
$driver = config("database.connections.{$connection}.driver");
45+
if ($driver === "sqlite") {
46+
\Illuminate\Support\Facades\DB::getDoctrineSchemaManager()
47+
->getDatabasePlatform()->registerDoctrineTypeMapping('point', 'string');
48+
}
4449

45-
// TODO if testing and if request contains "act_as_peer_server" then act as another peer
46-
// if (in_array(config('app.env'), ['testing', 'local'])
47-
// && $request->hasHeader(self::ActAsPeerServerKey)) {
48-
// $peerID = intval($request->header(self::ActAsPeerServerKey));
49-
// Log::warning("Acting as peer server $peerID");
50-
// $me = PeerServer::findOrFail($peerID);
51-
// } else {
52-
$me = PeerServer::me(false);
53-
// }
50+
$me = null;
51+
try {
5452

55-
} catch (\Exception $e) {
56-
Log::warning('Failed getCurrentServer() in AppServiceProvider');
57-
}
58-
// take the RSA keypair of the current server for JWT auth
53+
// TODO if testing and if request contains "act_as_peer_server" then act as another peer
54+
// if (in_array(config('app.env'), ['testing', 'local'])
55+
// && $request->hasHeader(self::ActAsPeerServerKey)) {
56+
// $peerID = intval($request->header(self::ActAsPeerServerKey));
57+
// Log::warning("Acting as peer server $peerID");
58+
// $me = PeerServer::findOrFail($peerID);
59+
// } else {
60+
$me = PeerServer::me(false);
61+
// }
5962

60-
if ($me) {
61-
config(['app.locale' => $me->locale]);
62-
// config(['app.timezone' => $me->timezone]);
63-
if ($me->jwt_public_key && $me->jwt_secret_key) {
64-
config(['jwt.keys.private' => $me->jwt_secret_key->toString()]);
65-
config(['jwt.keys.public' => $me->jwt_public_key->toString()]);
66-
}
67-
}
63+
} catch (\Exception $e) {
64+
Log::warning('Failed getCurrentServer() in AppServiceProvider');
65+
}
66+
// take the RSA keypair of the current server for JWT auth
6867

69-
/**
70-
* can be accessed with @see getCurrentServer()
71-
*/
72-
$this->app->singleton('peer_server_me', function ($app) use ($me) {
73-
return $me;
74-
});
68+
if ($me) {
69+
config(['app.locale' => $me->locale]);
70+
// config(['app.timezone' => $me->timezone]);
71+
if ($me->jwt_public_key && $me->jwt_secret_key) {
72+
config(['jwt.keys.private' => $me->jwt_secret_key->toString()]);
73+
config(['jwt.keys.public' => $me->jwt_public_key->toString()]);
74+
}
7575
}
76+
77+
/**
78+
* can be accessed with @see getCurrentServer()
79+
*/
80+
$this->app->singleton('peer_server_me', function ($app) use ($me) {
81+
return $me;
82+
});
83+
}
7684
}

app/Voting/CryptoSystems/ElGamal/EGParameterSet.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public function __construct(BigInteger $g, BigInteger $p, BigInteger $q)
4848
}
4949

5050
/**
51-
*
51+
* TODO these can change, from one peer to the other
52+
* TODO share your parameter with others
5253
*/
5354
public static function getDefault(): self
5455
{

compile_js.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# npm install
33

44
# edit .env file
5-
npm ci
5+
# npm ci
6+
npm install
67
# npm run test
78

89
# export MIX_ENV_MODE="dev"

generate_secret_ini_file.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import secrets
2+
import string
3+
import base64
4+
import logging
5+
6+
7+
def generate_password(size):
8+
# Generate a secure password
9+
alphabet = string.ascii_letters + string.digits # + string.punctuation
10+
return ''.join(secrets.choice(alphabet) for i in range(size))
11+
12+
def generate_base64_password(size):
13+
binary_string = secrets.token_bytes(size)
14+
return base64.b64encode(binary_string).decode()
15+
16+
config = {}
17+
with open("helm_secret.ini.example", "r") as f:
18+
for line in f.readlines():
19+
try:
20+
if not line.strip():
21+
continue
22+
if "=" not in line:
23+
key=line
24+
value=""
25+
else:
26+
key, value = line.split('=')
27+
key = key.strip()
28+
value = value.strip()
29+
config[key] = value
30+
except ValueError:
31+
# syntax error
32+
logging.error(f"Syntax error in line: {line}")
33+
pass
34+
35+
config['JWT_SECRET'] = generate_password(64)
36+
config['DB_PASSWORD'] = generate_password(32)
37+
config['APP_KEY'] = 'base64:' + generate_base64_password(64)
38+
39+
with open("helm_secret.ini", "w") as f:
40+
for key, value in config.items():
41+
f.write(f"{key}={value}\n")
File renamed without changes.

helm/templates/job-init.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: kairos-init
5+
annotations:
6+
"helm.sh/hook": post-install
7+
"helm.sh/hook-delete-policy": hook-succeeded
8+
spec:
9+
template:
10+
spec:
11+
initContainers:
12+
- name: init-cont
13+
image: busybox:1.31
14+
command: ['sh', '-c', 'echo -e "Checking for the availability of MySQL Server deployment"; while ! nc -z {{.Values.database.serviceName}} 3306; do sleep 1; printf "-"; done; echo -e " >> MySQL DB Server has started";']
15+
containers:
16+
- image: "{{ .Values.image }}:{{ .Chart.AppVersion }}"
17+
imagePullPolicy: Always
18+
name: kairos-init
19+
envFrom:
20+
- configMapRef:
21+
name: kairos-webserver-env
22+
- secretRef:
23+
name: kairos-secrets
24+
command: ["/bin/sh"]
25+
args:
26+
- -c
27+
- >-
28+
php artisan generate:jwt-keypair
29+
resources:
30+
requests:
31+
ephemeral-storage: "100Mi"
32+
restartPolicy: Never
33+
volumes:
34+
- name: kairos-webserver-claim
35+
persistentVolumeClaim:
36+
claimName: kairos-webserver-claim
37+
backoffLimit: 1

0 commit comments

Comments
 (0)