Commit de2e6ee1 authored by Alex Kakiris's avatar Alex Kakiris
Browse files

make Vault address configurable

parent 5133b13d
Loading
Loading
Loading
Loading
+1 −0
Changes for README.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ Notes:
- If any of those service names are changed in your OpenCAPIF deployment, you must update docker-compose.yml accordingly (for example CAPIF_HOSTNAME, REGISTER_HOSTNAME, VAULT_HOSTNAME, and extra_hosts). This will be improved in future versions.
- CCF_ONBOARDING_URL, CCF_API_ONBOARDING_URL, CCF_PUBLISH_URL, CCF_DISCOVER_URL, and CCF_SECURITY_URL are static per deployment and must match the ccf_* paths returned by CAPIF's /getauth response; a mismatch is logged as a WARNING on login.
- The CSR subject fields can be set via `CERT_ORGANIZATION` (default `Telefonica I+D`), `CERT_ORGANIZATIONAL_UNIT` (`Innovation`), `CERT_LOCALITY` (`Madrid`), `CERT_STATE` (`Madrid`), `CERT_COUNTRY` (`ES`, must be a 2-letter code) and `CERT_EMAIL` (`inno@tid.es`). They have defaults, so they don't need to be set in `docker-compose.yml`.
- `VAULT_ADDR` sets the Vault base URL (e.g. `https://vault.example:8200`). If unset, it defaults to `http://$VAULT_HOSTNAME:$VAULT_PORT`. Note: Vault requests use `verify=False`, so with an `https://` address traffic is encrypted but Vault's certificate is not verified.

Example /etc/hosts entries for a default local setup:

+4 −3
Changes for capif_backend/backoffice_service/__main__.py: 4 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ from .controllers.me_controller import me_routes
from flask_cors import CORS

from .utils.certs import generate_keypair_and_csr
from .utils.vault import vault_addr, vault_headers

# Create Flask app
app = Flask(__name__)
@@ -69,8 +70,8 @@ if LOAD_FROM_VAULT:

    # Get ca.cert from Vault
    config = Config().get_config()  # get configuration from config.py
    url = 'http://{}:{}/v1/secret/data/ca'.format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT'))
    headers = {'X-Vault-Token': os.getenv('VAULT_TOKEN')}
    url = f"{vault_addr()}/v1/secret/data/ca"
    headers = vault_headers()
    response = requests.request("GET", url, headers=headers, verify=False)

    # Print the full response content for inspection
@@ -85,7 +86,7 @@ if LOAD_FROM_VAULT:
    ca_file.close()

    # Request Vault to sign the CSR
    url = 'http://{}:{}/v1/pki_int/sign/my-ca'.format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT'))
    url = f"{vault_addr()}/v1/pki_int/sign/my-ca"
    data = {
        'format': 'pem_bundle',
        'ttl': '43000h',
+11 −0
Changes for capif_backend/backoffice_service/utils/vault.py: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
import os

def vault_addr():
    """Base URL of Vault. VAULT_ADDR, otherwise falls back to http://VAULT_HOSTNAME:VAULT_PORT as before."""
    addr = os.getenv("VAULT_ADDR")
    if addr:
        return addr.rstrip("/")
    return "http://{}:{}".format(os.getenv('VAULT_HOSTNAME'), os.getenv('VAULT_PORT'))

def vault_headers():
    return {'X-Vault-Token': os.getenv('VAULT_TOKEN')}
 No newline at end of file