Commit ddc1796a authored by Laura Dominguez's avatar Laura Dominguez
Browse files

Make CCIPS unit test and modified KEM method in openssl's configuration file

parent 7c68119a
Loading
Loading
Loading
Loading
+1 −0
Changes for .gitlab-ci.yml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ workflow:
include:
  #- local: '/manifests/.gitlab-ci.yml'
  - local: '/src/monitoring/.gitlab-ci.yml'
  - local: '/src/ccips/.gitlab-ci.yml'
  - local: '/src/nbi/.gitlab-ci.yml'
  - local: '/src/mcp_server/.gitlab-ci.yml'
  - local: '/src/agentic/.gitlab-ci.yml'
+131 −0
Changes for src/ccips/.gitlab-ci.yml: 131 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2026 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Build, tag, and push the CCIPS Docker image to the GitLab Docker registry
build ccips:
  variables:
    IMAGE_NAME: 'ccips'
    IMAGE_TAG: "candidate-${CI_COMMIT_SHORT_SHA}"
  stage: build
  before_script:
    - docker image prune --force
    - bash scripts/dockerhub_login.sh
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
    - docker ps -aq | xargs -r docker rm -f
  script:
    - docker buildx build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile .
    - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
  after_script:
    - docker image prune --force
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
    - changes:
      - src/common/**/*.py
      - proto/*.proto
      - src/$IMAGE_NAME/**/*.{py,in,yml}
      - src/$IMAGE_NAME/Dockerfile
      - src/$IMAGE_NAME/tests/*.py
      - manifests/${IMAGE_NAME}*.yaml
      - .gitlab-ci.yml

# End-to-end test for CCIPS when NBI is deployed
# This test runs only when the deployment component is 'nbi'
end2end_test ccips:
  variables:
    IMAGE_NAME: 'ccips'
    IMAGE_TAG: "candidate-${CI_COMMIT_SHORT_SHA}"
    TEST_IMAGE_TAG: "candidate-${CI_COMMIT_SHORT_SHA}"
  stage: end2end_test
  timeout: 30m
  before_script:
    - bash scripts/ci_cleanup_gitlab_runner.sh
    - bash scripts/dockerhub_login.sh
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    # Pull required Docker images
    - docker pull "${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG}"
    - docker pull "${CI_REGISTRY_IMAGE}/nbi:${IMAGE_TAG}"
    
    # Prepare Kubernetes storage and registry
    - bash scripts/ci_prepare_microk8s_storage_registry.sh
    
    # Deploy TeraFlowSDN with CCIPS and NBI
    - export TFS_COMPONENTS="context device pathcomp service ccips nbi"
    - export TFS_IMAGE_TAG="${IMAGE_TAG}"
    - export TFS_REGISTRY_IMAGES="${CI_REGISTRY_IMAGE}/"
    - export TFS_SKIP_BUILD="YES"
    
    # Initialize deployment configuration
    - source scripts/ci_apply_deploy_specs_overrides.sh
    
    # Deploy infrastructure and services
    - ./deploy/crdb.sh
    - ./deploy/nats.sh
    - ./deploy/kafka.sh
    
    # Deploy TeraFlow components (context, device, pathcomp, service, ccips, nbi)
    - ./deploy/tfs.sh
    - ./deploy/show.sh
    
    # Wait for CCIPS service to be ready
    - >
      kubectl rollout status deployment/ccipsservice -n ${TFS_K8S_NAMESPACE} --timeout=5m
    
    # Wait for NBI service to be ready
    - >
      kubectl rollout status deployment/nbiservice -n ${TFS_K8S_NAMESPACE} --timeout=5m
    
    # Run the end-to-end test
    - >
      kubectl run ccips-e2e-test-${CI_PIPELINE_ID} 
      --image="${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG}"
      --rm -i --restart=Never
      --namespace=${TFS_K8S_NAMESPACE}
      --env="PYTHONUNBUFFERED=1"
      --env="CCIPSSERVICE_SERVICE_HOST=ccipsservice"
      --env="CCIPSSERVICE_SERVICE_PORT_GRPC=10071"
      --env="LOG_LEVEL=INFO"
      -- python -m pytest -v src/ccips/tests/test_end2end.py --junitxml=/tmp/ccips_e2e_report.xml
    
    # Retrieve test results from the pod (if still running)
    - kubectl logs -n ${TFS_K8S_NAMESPACE} ccips-e2e-test-${CI_PIPELINE_ID} || true
  
  after_script:
    - kubectl logs -n ${TFS_K8S_NAMESPACE} deployment/ccipsservice --tail=100 || true
    - kubectl logs -n ${TFS_K8S_NAMESPACE} deployment/nbiservice --tail=100 || true
    - kubectl logs -n ${TFS_K8S_NAMESPACE} deployment/contextservice --tail=100 || true
    - kubectl logs -n ${TFS_K8S_NAMESPACE} deployment/deviceservice --tail=100 || true
  
  rules:
    # Run this test when the deployment contains NBI and changes affect ccips or nbi
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
      when: manual
    - changes:
        - src/common/**/*.py
        - proto/*.proto
        - src/ccips/**/*.{py,in,yml}
        - src/ccips/Dockerfile
        - src/ccips/tests/*.py
        - src/nbi/**/*.{py,in,yml}
        - src/nbi/tests/*.py
        - manifests/ccips*.yaml
        - manifests/nbiservice.yaml
        - .gitlab-ci.yml
      when: manual
  artifacts:
    when: always
    reports:
      junit: /tmp/ccips_e2e_report.xml
    expire_in: 1 week
+8 −1
Changes for src/ccips/Dockerfile: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@ RUN apt-get update && \
ARG OPENSSL_VERSION=3.6.0
ARG OPENSSL_SHA256=""

# Copy custom OpenSSL configuration with PQC/ML-KEM support
COPY src/ccips/openssl.cnf /tmp/openssl.cnf.custom

RUN set -eux \
    && mkdir -p /tmp/openssl-build \
    && cd /tmp/openssl-build \
@@ -55,8 +58,9 @@ RUN set -eux \
    && ln -s /usr/local/lib64/libcrypto.so.3 /usr/lib/x86_64-linux-gnu/libcrypto.so.3 \
    && ln -s /usr/local/lib64/libssl.so.3 /usr/lib/x86_64-linux-gnu/libssl.so \
    && ln -s /usr/local/lib64/libcrypto.so.3 /usr/lib/x86_64-linux-gnu/libcrypto.so \
    && cp /tmp/openssl.cnf.custom /usr/local/ssl/openssl.cnf \
    && cd / \
    && rm -rf /tmp/openssl-build
    && rm -rf /tmp/openssl-build /tmp/openssl.cnf.custom


# Make the runtime linker aware of the new library directory even for
@@ -66,6 +70,9 @@ RUN ldconfig;

RUN /usr/local/bin/openssl version

# Verify OpenSSL configuration includes ML-KEM groups
RUN /usr/local/bin/openssl list -groups | grep -i mlkem

# Verify that Python's _ssl extension resolves against OpenSSL 3.6.0.
RUN python3 -c 'import ssl; print(ssl.OPENSSL_VERSION); assert ssl.OPENSSL_VERSION.startswith("OpenSSL 3.6.0")'; 

src/ccips/openssl.cnf

0 → 100644
+168 −0
Changes for src/ccips/openssl.cnf: 168 added lines, 0 removed lines.
Original line number Diff line number Diff line
#
# OpenSSL 3.6.0 Configuration with PQC/ML-KEM Support
# TeraFlow CCIPS Component
#

# ============================================================================
# OpenSSL Initialization Section
# ============================================================================

[openssl_init]
providers = provider_sect
ssl_conf = ssl_configuration

# ============================================================================
# Provider Configuration
# ============================================================================

[provider_sect]
default = default_sect
legacy = legacy_sect

[default_sect]
activate = 1

[legacy_sect]
activate = 1

# ============================================================================
# SSL/TLS Configuration with MLKEM
# ============================================================================

[ssl_configuration]
system_default = tls_defaults

[tls_defaults]
# Post-Quantum Key Exchange Groups with ML-KEM hybrid algorithms
# Priority order: larger key sizes first, then hybrid combinations
Groups = X448MLKEM1024:X25519MLKEM768:SecP384r1MLKEM1024:SecP256r1MLKEM768:MLKEM1024

# ============================================================================
# Default CA Section
# ============================================================================

[ca]
default_ca = CA_default

[CA_default]
dir              = ./demoCA
certs            = $dir/certs
crl_dir          = $dir/crl
new_certs_dir    = $dir/newcerts
database         = $dir/index.txt
serial           = $dir/serial
RANDFILE         = $dir/private/.rand

private_key      = $dir/private/cakey.pem
certificate      = $dir/certs/cacert.pem
crlnumber        = $dir/crlnumber
crl              = $dir/crl.pem
crl_extensions   = crl_ext
default_crl_days = 30
default_md       = sha256

name_opt         = ca_default
cert_opt         = ca_default
default_days     = 365
preserve         = no
policy           = policy_loose
unique_subject   = no

[policy_loose]
countryName             = optional
stateOrProvinceName      = optional
localityName            = optional
organizationName        = optional
organizationalUnitName  = optional
commonName              = supplied
emailAddress            = optional

# ============================================================================
# Request Section
# ============================================================================

[req]
default_bits       = 2048
default_keyfile    = private/cakey.pem
default_md         = sha256
string_mask        = utf8only
x509_extensions    = v3_ca
req_extensions     = v3_req
distinguished_name = req_distinguished_name
attributes         = req_attributes

[req_distinguished_name]
countryName                     = Country Name (2 letter code)
countryName_default             = ES
stateOrProvinceName              = State or Province Name (full name)
stateOrProvinceName_default      = Madrid
localityName                    = Locality Name (eg, city)
organizationName                = Organization Name (eg, company)
organizationName_default        = TeraFlow
organizationalUnitName          = Organizational Unit Name (eg, section)
organizationalUnitName_default  = CCIPS
commonName                      = Common Name (eg, your name or your server hostname)
commonName_default              = teraflow.local
emailAddress                    = Email Address
emailAddress_default             = admin@teraflow.local

[req_attributes]
challengePassword               = A challenge password
challengePassword_min           = 4
challengePassword_max           = 20

# ============================================================================
# Certificate Extensions
# ============================================================================

[v3_req]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names

[v3_ca]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

[v3_intermediate_ca]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true, pathlen:0
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

[usr_cert]
basicConstraints = CA:FALSE
nsCertType = client, email
nsComment = "OpenSSL Generated Client Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
extendedKeyUsage = clientAuth, emailProtection

[server_cert]
basicConstraints = CA:FALSE
nsCertType = server
nsComment = "OpenSSL Generated Server Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer:always
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names

[crl_ext]
authorityKeyIdentifier=keyid:always

[ocsp]
basicConstraints = CA:FALSE
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost
DNS.2 = teraflow.local
DNS.3 = *.teraflow.local
IP.1 = 127.0.0.1
IP.2 = ::1
+45 −0
Changes for src/ccips/tests/conftest.py: 45 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Copyright 2022-2026 ETSI SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
pytest configuration and fixtures for CCIPS tests.
"""

import logging
import pytest

from ccips.client.DeviceClient import DeviceClient

LOGGER = logging.getLogger(__name__)


@pytest.fixture(scope='session')
def ccips_client():
    """
    Session-scoped fixture providing a CCIPS gRPC client.
    
    The client connects to the CCIPS service using environment-based
    configuration from the ServiceNameEnum.CCIPS settings.
    """
    LOGGER.info('Initializing CCIPS DeviceClient fixture...')
    _client = DeviceClient()
    
    LOGGER.info(f'CCIPS client configured for endpoint: {_client.endpoint}')
    LOGGER.info(f'CCIPS client timeout: {_client.timeout} seconds')
    
    yield _client
    
    LOGGER.info('Closing CCIPS DeviceClient fixture...')
    _client.close()
    LOGGER.info('CCIPS DeviceClient fixture closed.')
Loading