Skip to content

Commit 3e483f8

Browse files
Restrict secrets management to sodium+filesystem
1 parent 5d27192 commit 3e483f8

33 files changed

+1071
-938
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ CHANGELOG
1717
* Added new `error_controller` configuration to handle system exceptions
1818
* Added sort option for `translation:update` command.
1919
* [BC Break] The `framework.messenger.routing.senders` config key is not deep merged anymore.
20-
* Added secrets management.
20+
* Added `secrets:*` commands and `%env(secret:...)%` processor to deal with secrets seamlessly.
2121

2222
4.3.0
2323
-----

Command/SecretsAddCommand.php

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Command;
13+
14+
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
15+
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Input\InputOption;
18+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
use Symfony\Component\Console\Style\SymfonyStyle;
21+
22+
/**
23+
* @author Nicolas Grekas <p@tchwork.com>
24+
*
25+
* @internal
26+
*/
27+
final class SecretsDecryptToLocalCommand extends Command
28+
{
29+
protected static $defaultName = 'secrets:decrypt-to-local';
30+
31+
private $vault;
32+
private $localVault;
33+
34+
public function __construct(AbstractVault $vault, AbstractVault $localVault = null)
35+
{
36+
$this->vault = $vault;
37+
$this->localVault = $localVault;
38+
39+
parent::__construct();
40+
}
41+
42+
protected function configure()
43+
{
44+
$this
45+
->setDescription('Decrypts all secrets and stores them in the local vault.')
46+
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces overriding of secrets that already exist in the local vault')
47+
->setHelp(<<<'EOF'
48+
The <info>%command.name%</info> command list decrypts all secrets and stores them in the local vault..
49+
50+
<info>%command.full_name%</info>
51+
52+
When the option <info>--force</info> is provided, secrets that already exist in the local vault are overriden.
53+
54+
<info>%command.full_name% --force</info>
55+
EOF
56+
)
57+
;
58+
}
59+
60+
protected function execute(InputInterface $input, OutputInterface $output): int
61+
{
62+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
63+
64+
if (null === $this->localVault) {
65+
$io->error('The local vault is disabled.');
66+
67+
return 1;
68+
}
69+
70+
$secrets = $this->vault->list(true);
71+
72+
if (!$input->getOption('force')) {
73+
foreach ($this->localVault->list() as $k => $v) {
74+
unset($secrets[$k]);
75+
}
76+
}
77+
78+
foreach ($secrets as $k => $v) {
79+
if (null === $v) {
80+
$io->error($this->vault->getLastMessage());
81+
82+
return 1;
83+
}
84+
85+
$this->localVault->seal($k, $v);
86+
}
87+
88+
return 0;
89+
}
90+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Command;
13+
14+
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault;
15+
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Input\InputOption;
18+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
use Symfony\Component\Console\Style\SymfonyStyle;
21+
22+
/**
23+
* @author Nicolas Grekas <p@tchwork.com>
24+
*
25+
* @internal
26+
*/
27+
final class SecretsEncryptFromLocalCommand extends Command
28+
{
29+
protected static $defaultName = 'secrets:encrypt-from-local';
30+
31+
private $vault;
32+
private $localVault;
33+
34+
public function __construct(AbstractVault $vault, AbstractVault $localVault = null)
35+
{
36+
$this->vault = $vault;
37+
$this->localVault = $localVault;
38+
39+
parent::__construct();
40+
}
41+
42+
protected function configure()
43+
{
44+
$this
45+
->setDescription('Encrypts all local secrets to the vault.')
46+
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces overriding of secrets that already exist in the vault')
47+
->setHelp(<<<'EOF'
48+
The <info>%command.name%</info> command list encrypts all local secrets and stores them in the vault..
49+
50+
<info>%command.full_name%</info>
51+
52+
When the option <info>--force</info> is provided, secrets that already exist in the vault are overriden.
53+
54+
<info>%command.full_name% --force</info>
55+
EOF
56+
)
57+
;
58+
}
59+
60+
protected function execute(InputInterface $input, OutputInterface $output): int
61+
{
62+
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
63+
64+
if (null === $this->localVault) {
65+
$io->error('The local vault is disabled.');
66+
67+
return 1;
68+
}
69+
70+
$secrets = $this->localVault->list(true);
71+
72+
if (!$input->getOption('force')) {
73+
foreach ($this->vault->list() as $k => $v) {
74+
unset($secrets[$k]);
75+
}
76+
}
77+
78+
foreach ($secrets as $k => $v) {
79+
if (null === $v) {
80+
$io->error($this->localVault->getLastMessage());
81+
82+
return 1;
83+
}
84+
85+
$this->vault->seal($k, $v);
86+
}
87+
88+
return 0;
89+
}
90+
}

Command/SecretsGenerateKeyCommand.php

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

0 commit comments

Comments
 (0)