Skip to content

Commit

Permalink
Add trusted-external-ca-cert option
Browse files Browse the repository at this point in the history
To connect to an external S3 endpoint with encryption,
a root CA needs to be installed on the gnocchi units.

Func-test-PR: openstack-charmers/zaza-openstack-tests#393
Change-Id: I50fd881400d4c1bf4beaa70d75af34c28c98ea41
  • Loading branch information
camille-rodriguez committed Aug 20, 2020
1 parent 074527a commit 6820332
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/README.md
Expand Up @@ -51,6 +51,9 @@ set accordingly:
* `s3-access-key-id`
* `s3-secret-access-key`

For an encrypted S3 endpoint that is not managed by charmed Vault, the config
option `trusted-ssl-ca-cert` needs to be configured.

See file `config.yaml` for more details on the above options.

## Policy overrides
Expand Down
6 changes: 6 additions & 0 deletions src/config.yaml
Expand Up @@ -41,6 +41,12 @@ options:
description: |
The maximum number of connections to keep in a connection pool. (integer value).
Minimum value: 1
trusted-external-ca-cert:
type: string
default:
description: |
Base 64 encoded SSL CA certificate to use for an encrypted S3 endpoint.
To be used when the S3 certificates are not managed by charmed Vault.
use-policyd-override:
type: boolean
default: False
Expand Down
26 changes: 26 additions & 0 deletions src/lib/charm/openstack/gnocchi.py
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import base64
import os
import collections
import subprocess
Expand Down Expand Up @@ -56,6 +57,8 @@

DB_INTERFACE = 'shared-db'

EXTERNAL_CA_CERT_FILE = '/usr/local/share/ca-certificates/gnocchi-external.crt'

charms_openstack.charm.use_defaults('charm.default-select-package-type')
charms_openstack.charm.use_defaults('charm.default-select-release')

Expand Down Expand Up @@ -268,6 +271,29 @@ def states_to_check(self, required_relations=None):
]
return states_to_check

def configure_external_tls(self):
"""Installs an external root CA to the gnocchi units, if provided.
The purpose of this is to allow connection to an external S3 endpoint
with encryption.
:returns: None
"""
if self.options.trusted_external_ca_cert:
ca_cert = self.options.trusted_external_ca_cert.strip()
hookenv.log("Writing tls ca cert {}".format(ca_cert), hookenv.INFO)
cert_content = base64.b64decode(ca_cert).decode()
try:
with open(EXTERNAL_CA_CERT_FILE, 'w') as fd:
fd.write(cert_content)
subprocess.call(['/usr/sbin/update-ca-certificates'])
except (subprocess.CalledProcessError, PermissionError) as error:
hookenv.status_set(
'blocked',
'An error occured while uploading the external ca cert.'
)
hookenv.log('configure_external_ssl failed: {}'.format(error),
hookenv.ERROR)
return


class GnocchiCharm(GnocchiCharmBase):

Expand Down
1 change: 1 addition & 0 deletions src/reactive/gnocchi_handlers.py
Expand Up @@ -117,6 +117,7 @@ def render_config(*args):
with charm.provide_charm_instance() as charm_class:
charm_class.upgrade_if_available(args)
charm_class.configure_ssl()
charm_class.configure_external_tls()
charm_class.render_with_interfaces(args)
charm_class.enable_webserver_site()
hookenv.log("Configuration rendered", hookenv.DEBUG)
Expand Down
2 changes: 2 additions & 0 deletions src/tests/tests.yaml
Expand Up @@ -32,9 +32,11 @@ configure:
- zaza.openstack.charm_tests.ceilometer.setup.basic_setup
tests:
- zaza.openstack.charm_tests.gnocchi.tests.GnocchiTest
- zaza.openstack.charm_tests.gnocchi.tests.GnocchiExternalCATest
- test-s3:
- zaza.openstack.charm_tests.gnocchi.tests.GnocchiS3Test
- zaza.openstack.charm_tests.gnocchi.tests.GnocchiTest
- zaza.openstack.charm_tests.gnocchi.tests.GnocchiExternalCATest
target_deploy_status:
vault:
workload-status: blocked
Expand Down

0 comments on commit 6820332

Please sign in to comment.