Skip to content

Commit f7c1695

Browse files
committed
Randomize kernel secret in the standalone image through a configuration file
1 parent 911d6e8 commit f7c1695

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ COPY --chown=$UID:$GID --from=composer_build /srv/app ./
8787
COPY --chown=$UID:$GID --from=node_build /srv/app/public/build public/build/
8888
COPY --chown=$UID:$GID readme.md license.md ./
8989
COPY --chown=$UID:$GID bin/console bin/dirigent bin/
90-
COPY --chown=$UID:$GID docker/dirigent.yaml /srv/app/config/
90+
COPY --chown=$UID:$GID docker/config.yaml config/dirigent.yaml
9191
COPY --chown=$UID:$GID docker/env.php ./.env.dirigent.local.php
9292
COPY --chown=$UID:$GID config config/
9393
COPY --chown=$UID:$GID docs docs/

docker/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
framework:
2+
secret: '%env(file:KERNEL_SECRET_FILE)%'

docker/env.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'DATABASE_URL' => 'postgresql://dirigent@127.0.0.1:5432/dirigent?serverVersion=16&charset=utf8',
66
'DIRIGENT_IMAGE' => '1',
77
'GITHUB_TOKEN' => '',
8+
'KERNEL_SECRET_FILE' => '/srv/config/secrets/kernel_secret',
89
'MAILER_DSN' => 'null://null',
910
'MESSENGER_TRANSPORT_DSN' => 'doctrine://default?auto_setup=0',
1011
'SENTRY_DSN' => '',
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
if [ -f "/srv/config/secrets/kernel_secret" ]; then
6+
echo "Kernel secret exists"
7+
fi
8+
9+
# Make sure secrets directory exists
10+
mkdir -p /srv/config/secrets
11+
12+
# Generate a kernel secret and save the value
13+
secret=$(openssl rand -base64 12)
14+
echo $secret > /srv/config/secrets/kernel_secret
15+
16+
echo "Generated a new kernel secret"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace CodedMonkey\Dirigent\Tests\Docker\Standalone;
4+
5+
class InitTest extends DockerStandaloneTestCase
6+
{
7+
public function testKernelSecretGenerated(): void
8+
{
9+
$this->assertContainerFileExists(
10+
'/srv/config/secrets/kernel_secret',
11+
'A kernel_secret file must be generated.',
12+
);
13+
}
14+
}

0 commit comments

Comments
 (0)