Skip to content

Commit 11b494b

Browse files
committed
Add OpenStack Barbican key management support
- Implement Barbican key source with authentication and client functionality - Add comprehensive test suite including unit, integration, and property-based tests - Update configuration system to support Barbican endpoints and authentication - Integrate Barbican support into keyservice and stores - Add documentation and usage examples for Barbican configuration - Ensure backward compatibility and proper error handling Signed-off-by: Victor Palma <palma.victor@gmail.com>
1 parent a1bd885 commit 11b494b

32 files changed

Lines changed: 13513 additions & 65 deletions

README.rst

Lines changed: 199 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ SOPS: Secrets OPerationS
22
========================
33

44
**SOPS** is an editor of encrypted files that supports YAML, JSON, ENV, INI and BINARY
5-
formats and encrypts with AWS KMS, GCP KMS, Azure Key Vault, HuaweiCloud KMS, age, and PGP.
5+
formats and encrypts with AWS KMS, GCP KMS, Azure Key Vault, HuaweiCloud KMS, OpenStack Barbican, age, and PGP.
66
(`demo <https://www.youtube.com/watch?v=YTEVyLXFiq0>`_)
77

88
.. image:: https://i.imgur.com/X0TM5NI.gif
@@ -96,6 +96,30 @@ separated, in the **SOPS_PGP_FP** env variable.
9696
9797
Note: you can use both PGP and KMS simultaneously.
9898

99+
If you want to use OpenStack Barbican, export the Barbican secret references, comma
100+
separated, in the **SOPS_BARBICAN_SECRETS** env variable. You'll also need to set
101+
OpenStack authentication environment variables.
102+
103+
.. code:: bash
104+
105+
export SOPS_BARBICAN_SECRETS="550e8400-e29b-41d4-a716-446655440000,region:us-west-1:660e8400-e29b-41d4-a716-446655440001"
106+
export OS_AUTH_URL="https://keystone.example.com:5000/v3"
107+
export OS_USERNAME="sops-user"
108+
export OS_PASSWORD="secret"
109+
export OS_PROJECT_ID="abc123"
110+
export OS_DOMAIN_NAME="default"
111+
112+
Alternatively, you can use OpenStack application credentials (recommended):
113+
114+
.. code:: bash
115+
116+
export SOPS_BARBICAN_SECRETS="550e8400-e29b-41d4-a716-446655440000"
117+
export OS_AUTH_URL="https://keystone.example.com:5000/v3"
118+
export OS_APPLICATION_CREDENTIAL_ID="app-cred-id"
119+
export OS_APPLICATION_CREDENTIAL_SECRET="app-cred-secret"
120+
121+
Note: you can use Barbican with other key management services simultaneously.
122+
99123
Then simply call ``sops edit`` with a file path as argument. It will handle the
100124
encryption/decryption transparently and open the cleartext file in an editor
101125

@@ -604,13 +628,138 @@ You can also configure HuaweiCloud KMS keys in the ``.sops.yaml`` config file:
604628
hckms:
605629
- tr-west-1:abc12345-6789-0123-4567-890123456789,tr-west-2:def67890-1234-5678-9012-345678901234
606630
631+
Encrypting using OpenStack Barbican
632+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
633+
634+
OpenStack Barbican is a key management service that provides secure storage, provisioning and management of secrets. SOPS integrates with Barbican to encrypt and decrypt files using secrets stored in Barbican.
635+
636+
Authentication
637+
**************
638+
639+
SOPS supports standard OpenStack authentication methods for Barbican:
640+
641+
**Password Authentication:**
642+
643+
.. code:: bash
644+
645+
export OS_AUTH_URL="https://keystone.example.com:5000/v3"
646+
export OS_USERNAME="sops-user"
647+
export OS_PASSWORD="secret"
648+
export OS_PROJECT_ID="abc123"
649+
export OS_DOMAIN_NAME="default"
650+
651+
**Application Credentials (Recommended):**
652+
653+
.. code:: bash
654+
655+
export OS_AUTH_URL="https://keystone.example.com:5000/v3"
656+
export OS_APPLICATION_CREDENTIAL_ID="app-cred-id"
657+
export OS_APPLICATION_CREDENTIAL_SECRET="app-cred-secret"
658+
659+
**Token Authentication:**
660+
661+
.. code:: bash
662+
663+
export OS_AUTH_URL="https://keystone.example.com:5000/v3"
664+
export OS_TOKEN="existing-token"
665+
666+
Secret Reference Formats
667+
************************
668+
669+
Barbican secrets can be referenced in multiple formats:
670+
671+
- **UUID format:** ``550e8400-e29b-41d4-a716-446655440000``
672+
- **Regional format:** ``region:sjc3:550e8400-e29b-41d4-a716-446655440000``
673+
- **Full URI format:** ``https://barbican.example.com:9311/v1/secrets/550e8400-e29b-41d4-a716-446655440000``
674+
675+
Basic Usage
676+
***********
677+
678+
You can encrypt a file using the ``--barbican`` flag:
679+
680+
.. code:: sh
681+
682+
$ sops encrypt --barbican 550e8400-e29b-41d4-a716-446655440000 test.yaml > test.enc.yaml
683+
684+
Or using the environment variable:
685+
686+
.. code:: sh
687+
688+
$ export SOPS_BARBICAN_SECRETS="550e8400-e29b-41d4-a716-446655440000"
689+
$ sops encrypt test.yaml > test.enc.yaml
690+
691+
And decrypt it using:
692+
693+
.. code:: sh
694+
695+
$ sops decrypt test.enc.yaml
696+
697+
Multi-Region Support
698+
********************
699+
700+
For high availability, you can use secrets from multiple regions:
701+
702+
.. code:: sh
703+
704+
$ export SOPS_BARBICAN_SECRETS="region:sjc3:550e8400-e29b-41d4-a716-446655440000,region:dfw3:660e8400-e29b-41d4-a716-446655440001"
705+
$ sops encrypt test.yaml > test.enc.yaml
706+
707+
SOPS will automatically try secrets in order during decryption, providing failover capability if one region becomes unavailable.
708+
709+
Configuration File Support
710+
**************************
711+
712+
You can configure Barbican secrets in the ``.sops.yaml`` config file:
713+
714+
.. code:: yaml
715+
716+
creation_rules:
717+
- path_regex: \.prod\.yaml$
718+
barbican: "550e8400-e29b-41d4-a716-446655440000"
719+
barbican_auth_url: "https://keystone.example.com:5000/v3"
720+
barbican_region: "sjc3"
721+
722+
For multiple secrets:
723+
724+
.. code:: yaml
725+
726+
creation_rules:
727+
- path_regex: \.prod\.yaml$
728+
barbican:
729+
- "550e8400-e29b-41d4-a716-446655440000"
730+
- "region:dfw3:660e8400-e29b-41d4-a716-446655440001"
731+
barbican_auth_url: "https://keystone.example.com:5000/v3"
732+
733+
Mixed Key Management
734+
*******************
735+
736+
Barbican can be used alongside other key management services:
737+
738+
.. code:: sh
739+
740+
$ sops encrypt \
741+
--barbican 550e8400-e29b-41d4-a716-446655440000 \
742+
--kms arn:aws:kms:us-west-2:123456789012:key/12345678-1234-1234-1234-123456789012 \
743+
--pgp 85D77543B3D624B63CEA9E6DBC17301B491B3F21 \
744+
test.yaml > test.enc.yaml
745+
746+
Security Considerations
747+
**********************
748+
749+
- **Use Application Credentials:** More secure than username/password authentication
750+
- **Enable HTTPS:** Always use HTTPS endpoints in production
751+
- **Rotate Credentials:** Regularly rotate application credentials
752+
- **Network Security:** Use proper firewall rules and network segmentation
753+
754+
For comprehensive usage examples, troubleshooting, and best practices, see the detailed documentation in ``barbican/README.rst``.
755+
607756
Adding and removing keys
608757
~~~~~~~~~~~~~~~~~~~~~~~~
609758
610759
When creating new files, ``sops`` uses the PGP, KMS and GCP KMS defined in the
611-
command line arguments ``--kms``, ``--pgp``, ``--gcp-kms``, ``--hckms`` or ``--azure-kv``, or from
760+
command line arguments ``--kms``, ``--pgp``, ``--gcp-kms``, ``--hckms``, ``--azure-kv``, or ``--barbican``, or from
612761
the environment variables ``SOPS_KMS_ARN``, ``SOPS_PGP_FP``, ``SOPS_GCP_KMS_IDS``,
613-
``SOPS_HUAWEICLOUD_KMS_IDS``, ``SOPS_AZURE_KEYVAULT_URLS``. That information is stored in the file under the
762+
``SOPS_HUAWEICLOUD_KMS_IDS``, ``SOPS_AZURE_KEYVAULT_URLS``, ``SOPS_BARBICAN_SECRETS``. That information is stored in the file under the
614763
``sops`` section, such that decrypting files does not require providing those
615764
parameters again.
616765
@@ -654,9 +803,9 @@ disabled by supplying the ``-y`` flag.
654803
655804
The ``rotate`` command generates a new data encryption key and reencrypt all values
656805
with the new key. At the same time, the command line flag ``--add-kms``, ``--add-pgp``,
657-
``--add-gcp-kms``, ``--add-hckms``, ``--add-azure-kv``, ``--rm-kms``, ``--rm-pgp``, ``--rm-gcp-kms``,
658-
``--rm-hckms`` and ``--rm-azure-kv`` can be used to add and remove keys from a file. These flags use
659-
the comma separated syntax as the ``--kms``, ``--pgp``, ``--gcp-kms``, ``--hckms`` and ``--azure-kv``
806+
``--add-gcp-kms``, ``--add-hckms``, ``--add-azure-kv``, ``--add-barbican``, ``--rm-kms``, ``--rm-pgp``, ``--rm-gcp-kms``,
807+
``--rm-hckms``, ``--rm-azure-kv`` and ``--rm-barbican`` can be used to add and remove keys from a file. These flags use
808+
the comma separated syntax as the ``--kms``, ``--pgp``, ``--gcp-kms``, ``--hckms``, ``--azure-kv`` and ``--barbican``
660809
arguments when creating new files.
661810
662811
Use ``updatekeys`` if you want to add a key without rotating the data key.
@@ -669,6 +818,12 @@ Use ``updatekeys`` if you want to add a key without rotating the data key.
669818
# remove a pgp key from the file and rotate the data key
670819
$ sops rotate -i --rm-pgp 85D77543B3D624B63CEA9E6DBC17301B491B3F21 example.yaml
671820
821+
# add a new barbican secret to the file and rotate the data key
822+
$ sops rotate -i --add-barbican 550e8400-e29b-41d4-a716-446655440000 example.yaml
823+
824+
# remove a barbican secret from the file and rotate the data key
825+
$ sops rotate -i --rm-barbican 550e8400-e29b-41d4-a716-446655440000 example.yaml
826+
672827
673828
Direct Editing
674829
**************
@@ -694,6 +849,14 @@ And, similarly, to add a PGP master key, we add its fingerprint:
694849
pgp:
695850
- fp: 85D77543B3D624B63CEA9E6DBC17301B491B3F21
696851
852+
To add a Barbican secret, we add its secret reference:
853+
854+
.. code:: yaml
855+
856+
sops:
857+
barbican:
858+
- secret_ref: 550e8400-e29b-41d4-a716-446655440000
859+
697860
When the file is saved, SOPS will update its metadata and encrypt the data key
698861
with the freshly added master keys. The removed entries are simply deleted from
699862
the file.
@@ -878,6 +1041,10 @@ can manage the three sets of configurations for the three types of files:
8781041
- path_regex: \.hckms\.yaml$
8791042
hckms: tr-west-1:abc12345-6789-0123-4567-890123456789,tr-west-2:def67890-1234-5678-9012-345678901234
8801043
1044+
# barbican files using OpenStack Barbican
1045+
- path_regex: \.barbican\.yaml$
1046+
barbican: 550e8400-e29b-41d4-a716-446655440000,region:dfw3:660e8400-e29b-41d4-a716-446655440001
1047+
8811048
# Finally, if the rules above have not matched, this one is a
8821049
# catchall that will encrypt the file using KMS set C as well as PGP
8831050
# The absence of a path_regex means it will match everything
@@ -1883,6 +2050,17 @@ To directly specify a single key group, you can use the following keys:
18832050
- tr-west-1:abc12345-6789-0123-4567-890123456789
18842051
- tr-west-1:def67890-1234-5678-9012-345678901234
18852052
2053+
* ``barbican`` (comma-separated string, or list of strings): list of OpenStack Barbican secret references.
2054+
Secret references can be UUIDs, regional format (``region:<region>:<uuid>``), or full URIs.
2055+
Example:
2056+
2057+
.. code:: yaml
2058+
2059+
creation_rules:
2060+
- barbican:
2061+
- 550e8400-e29b-41d4-a716-446655440000
2062+
- region:sjc3:660e8400-e29b-41d4-a716-446655440001
2063+
18862064
To specify a list of key groups, you can use the following key:
18872065
18882066
* ``key_groups`` (list of key group objects): a list of key group objects.
@@ -1912,6 +2090,9 @@ To specify a list of key groups, you can use the following key:
19122090
- http://my.vault/v1/sops/keys/secondkey
19132091
hckms:
19142092
- tr-west-1:abc12345-6789-0123-4567-890123456789
2093+
barbican:
2094+
- 550e8400-e29b-41d4-a716-446655440000
2095+
- region:sjc3:660e8400-e29b-41d4-a716-446655440001
19152096
19162097
merge:
19172098
- pgp:
@@ -2000,6 +2181,18 @@ A key group supports the following keys:
20002181
20012182
- key_id: tr-west-1:abc12345-6789-0123-4567-890123456789
20022183
2184+
* ``barbican`` (list of objects): list of OpenStack Barbican secret references.
2185+
Every object must have the following key:
2186+
2187+
* ``secret_ref`` (string): the secret reference (UUID, regional format, or full URI).
2188+
2189+
Example:
2190+
2191+
.. code:: yaml
2192+
2193+
- secret_ref: 550e8400-e29b-41d4-a716-446655440000
2194+
- secret_ref: region:sjc3:660e8400-e29b-41d4-a716-446655440001
2195+
20032196
* ``age`` (list of strings): list of Age public keys.
20042197
20052198
* ``pgp`` (list of strings): list of PGP/GPG key fingerprints.

0 commit comments

Comments
 (0)