Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict secrets management to sodium+filesystem
- Loading branch information
1 parent
02b5d74
commit be8b267
Showing
33 changed files
with
869 additions
and
938 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 0 additions & 70 deletions
70
src/Symfony/Bundle/FrameworkBundle/Command/SecretsAddCommand.php
This file was deleted.
Oops, something went wrong.
97 changes: 0 additions & 97 deletions
97
src/Symfony/Bundle/FrameworkBundle/Command/SecretsGenerateKeyCommand.php
This file was deleted.
Oops, something went wrong.
123 changes: 123 additions & 0 deletions
123
src/Symfony/Bundle/FrameworkBundle/Command/SecretsGenerateKeysCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\ConsoleOutputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
/** | ||
* @author Tobias Schultze <http://tobion.de> | ||
* @author Jérémy Derussé <jeremy@derusse.com> | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
*/ | ||
final class SecretsGenerateKeysCommand extends Command | ||
{ | ||
protected static $defaultName = 'secrets:generate-keys'; | ||
|
||
private $vault; | ||
private $localVault; | ||
|
||
public function __construct(AbstractVault $vault, AbstractVault $localVault = null) | ||
{ | ||
$this->vault = $vault; | ||
$this->localVault = $localVault; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setDescription('Generates new encryption keys.') | ||
->addOption('local', 'l', InputOption::VALUE_NONE, 'Updates the local vault.') | ||
->addOption('rotate', 'r', InputOption::VALUE_NONE, 'Re-encrypts existing secrets with the newly generated keys.') | ||
->setHelp(<<<'EOF' | ||
The <info>%command.name%</info> command generates a new encryption key. | ||
<info>%command.full_name%</info> | ||
If encryption keys already exist, the command must be called with | ||
the <info>--rotate</info> option in order to override those keys and re-encrypt | ||
existing secrets. | ||
<info>%command.full_name% --rotate</info> | ||
EOF | ||
) | ||
; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output); | ||
$vault = $input->getOption('local') ? $this->localVault : $this->vault; | ||
|
||
if (null === $vault) { | ||
$io->success('The local vault is disabled.'); | ||
|
||
return 1; | ||
} | ||
|
||
if (!$input->getOption('rotate')) { | ||
if ($vault->generateKeys()) { | ||
$io->success($vault->getLastMessage()); | ||
|
||
if ($this->vault === $vault) { | ||
$io->caution('DO NOT COMMIT THE DECRYPTION KEY FOR THE PROD ENVIRONMENT⚠️'); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
$io->warning($vault->getLastMessage()); | ||
|
||
return 1; | ||
} | ||
|
||
$secrets = []; | ||
foreach ($vault->list(true) as $name => $value) { | ||
if (null === $value) { | ||
$io->error($vault->getLastMessage()); | ||
|
||
return 1; | ||
} | ||
|
||
$secrets[$name] = $value; | ||
} | ||
|
||
if (!$vault->generateKeys(true)) { | ||
$io->warning($vault->getLastMessage()); | ||
|
||
return 1; | ||
} | ||
|
||
$io->success($vault->getLastMessage()); | ||
|
||
if ($secrets) { | ||
foreach ($secrets as $name => $value) { | ||
$vault->seal($name, $value); | ||
} | ||
|
||
$io->comment('Existing secrets have been rotated to the new keys.'); | ||
} | ||
|
||
if ($this->vault === $vault) { | ||
$io->caution('DO NOT COMMIT THE DECRYPTION KEY FOR THE PROD ENVIRONMENT⚠️'); | ||
} | ||
|
||
return 0; | ||
} | ||
} |
Oops, something went wrong.