diff --git a/Standards/scs-0125-v1-secure-connections.md b/Standards/scs-0125-v1-secure-connections.md new file mode 100644 index 000000000..b2df96743 --- /dev/null +++ b/Standards/scs-0125-v1-secure-connections.md @@ -0,0 +1,277 @@ +--- +title: Secure Connections +type: Standard # | Decision Record | Procedural +status: Draft +track: IaaS # | IaaS | Ops | KaaS | IAM +--- + +## Introduction + +A lot of internal and external connectivity is established to and within a cloud infrastructure. +Due to the nature of the IaaS approach, many communication channels may occasionally or even primarily carry potentially sensitive data of customers. +To protect this data from both tampering and unintended disclosure, communication channels need to be properly secured. + +For this reason, the [SCS project](https://scs.community) standardizes the use of common protection mechanisms for communication channels in OpenStack infrastructures. + +## Terminology + +| Term | Meaning | +|---|---| +| CA | Certificate Authority | +| CSP | Cloud Service Provider, provider managing the OpenStack infrastructure | +| PKI | Public Key Infrastructure | +| SDN | Software-Defined Networking | +| SSL | Secure Sockets Layer, the predecessor of TLS | +| TLS | Transport Layer Security | +| Compute Host | System within the IaaS infrastructure that runs the hypervisor services and hosts virtual machines | + +## Motivation + +As mentioned above, a lot of communication channels in an OpenStack infrastructure carry data that is potentially sensitive. +For example this includes authentication data of customers and internal OpenStack configuration data such as encryption keys among others. +OpenStack does not generically mandate or preconfigure the use of specific protection mechanisms by itself and instead only makes recommendations about best practices in its offical [Security Guide](https://docs.openstack.org/security-guide/). + +To address the potential lack of implementation of such mechanisms by a CSP and to establish a reliable foundation for communication data protection in SCS clouds, the SCS project formulates this standard for securing communication channels in the infrastructure, so that a customer can rely on adequate security mechanisms being in use. + +## Design Considerations + +There are many internal communication channels in OpenStack with different characteristics, location and eligible means of protection. +Not all channels are equally easy to secure and some protection mechanisms might put unbearable burdens on a CSP. +Hence, careful assessment is required to determine for which the SCS standard will either mandate or recommend the use of a protection mechanism. + +Note that this standard only focuses on security considerations for securing the Openstack API as well as inter-component connections, which a CSP has full control over on an infrastructure level. +This standard will not address the security of customer-deployed instances and services on top of OpenStack or other IaaS implementations. + +For this distinction to be made, applicable communication channels must be categorized and classified accordingly. + +### Communication Channels + +The following overview will classify the main communication channels. + +| # | Classification | Details | Example solution | +|---|---|---|---| +| 1 | OpenStack database backend traffic | Replication and sync between database instances of the OpenStack services' databases | SSL/TLS | +| 2 | OpenStack database frontend traffic | Communication between OpenStack services and their corresponding databases | SSL/TLS | +| 3 | Message queue traffic | Message queue communication between OpenStack components as provided by oslo.messaging | SSL/TLS | +| 4 | External API communication | HTTP traffic to services registered as external endpoints in the Keystone service catalog | SSL/TLS | +| 5 | Internal API communication | HTTP traffic to services registered as internal endpoints in the Keystone service catalog | SSL/TLS | +| 6 | Nova VM migration traffic | Nova VM migration data transfer traffic between compute nodes | QEMU-native TLS | +| 7 | External Neutron network traffic | VM-related traffic between the network/controller nodes and external networks (e.g. internet) established through routed provider networks and floating IPs | VPN | +| 8 | Internal Neutron network traffic | Traffic within Neutron SDN networks exchanged between internal systems such as network/controller and compute nodes | WireGuard | +| 9 | Storage network frontend traffic | Traffic exchanged between OpenStack and network storage backends (e.g. Ceph) | N/A* | +| 10 | Storage network replication traffic | Traffic exchanged between individual storage nodes within the network storage backend for replication purposes | N/A* | + +\* The characteristics of the storage network traffic is highly specific to the individual storage backend and no generic solution can be stated here. + +Notes about the classification categories and implications: + +1. Most database clustering solutions (e.g. MariaDB Galera) offer TLS-based encryption of their backend channels. This needs no additional configuration in OpenStack and is a configuration solely concerning the database cluster. +2. The database frontend interface is the primary connection target for the OpenStack services. OpenStack supports using TLS for database connections. +3. For the message queue, AMQP-based solutions such as RabbitMQ and QPid do offer TLS natively which is also supported by OpenStack. ZeroMQ does not and requires WireGuard or CIPSO instead. +4. External API endpoints can be protected easily by using a TLS proxy. They can then be registered with their HTTPS endpoint in the Keystone service catalog. The certificates of external APIs usually need to be signed by a well-known CA in order to be accepted by arbitrary external clients. +5. Internal API endpoints can be treated and secured similarly to the external ones using a TLS proxy and adequate certificates. +6. For protecting the data transferred between compute nodes during live-migration of VMs, [Nova offers support for QEMU-native TLS](https://docs.openstack.org/nova/latest/admin/secure-live-migration-with-qemu-native-tls.html). As an alternative, SSH is also a channel that Nova can be configured to use between hosts for this but requires passwordless SSH keys with root access to all other compute nodes which in turn requires further hardening. +7. Neutron's external network traffic leaves the IaaS infrastructure. This part is twofold: connections initiated by the VMs themselves (egress) and connections reaching VMs from the outside (ingress). The CSP cannot influence the egress connections but can offer VPNaaS for the ingress direction. +8. Neutron's internal network traffic is one of the hardest aspects to address. Due to the highly dynamic nature of SDN, connection endpoints and relations are constantly changing. There is no holistic approach currently offered or recommended by OpenStack itself. Encrypted tunnels could be established between all involved nodes but would require a scalable solution and reliable key management. WireGuard could be considered a good starting point for this. A per-tenant/per-customer encryption remains very hard to establish this way though. +9. The available means of securing frontend storage communication are dependent on the protocol used for communication between OpenStack and the storage backend. Some storage solutions and protocols might offer authentication and encryption functionality by default but that cannot be assumed to be the case for every possible backend. Furthermore, storage is highly sensitive to latency and performance impacts imposed by such measures. Due to the fact that OpenStack's volume encryption functionality encrypts block storage data before it enters the storage network, an unsecured communication channel may be considered not as much of a problem here as it is for other channels\*. +10. Storage network replication traffic is highly specific to the storage backend solution and its method of operation. For some backends this channel might not even exists, depending on their architecture. As such, in most cases it is up to the storage solution to provide adequate measures for protection of this channel. As with the frontend storage traffic, due to the possible at-rest encryption implemented by OpenStack, only already encrypted data is transferred here for some resources\*. + +\* Encryption of data implemented by OpenStack before it is passed to the storage backend currently only applies to block data of volumes that use an encrypted volume type. Other data (e.g. of unencrypted volumes, images) is transferred to and from the storage in plaintext. + +### libvirt Hypervisor Interface on Compute Nodes + +Live migration of virtual machines between compute hosts requires communication between the hypervisor services of the involved hosts. +In OpenStack, the libvirt virtualization API is used to control the hypervisor on compute nodes as well as to enable the live migration communication. +This libvirt interface allows direct control of the hypervisor. +Besides control of virtual machines themselves, in OpenStack this also includes attaching and detaching volumes, setting or retrieving their encryption keys and controlling network attachments. +As such, severe risks are associated with unauthorized access to this interface as it can easily compromise sensitive data of arbitrary tenants if abused. + +This is acknowledged in the OpenStack Security Note [OSSN-0007](https://wiki.openstack.org/wiki/OSSN/OSSN-0007), which recommends either configuring SASL and/or TLS for libvirt connections or utilizing the UNIX socket in combination with SSH. + +The OpenStack [kolla-ansible documentation](https://docs.openstack.org/kolla-ansible/latest/reference/compute/libvirt-guide.html#sasl-authentication) on Nova libvirt connections state: + +> This should not be considered as providing a secure, encrypted channel, since the username/password SASL mechanisms available for TCP are no longer considered cryptographically secure. + +This leaves only TLS or UNIX socket with SSH as viable options for securing the channel. + +#### TLS for libvirt and live migration + +Since the Stein release of OpenStack, Nova supports [QEMU-native TLS](https://docs.openstack.org/nova/latest/admin/secure-live-migration-with-qemu-native-tls.html) which protects the migration data streams using TLS. +It requires to add `LIBVIRTD_ARGS="--listen"` to the [QEMU configuration](https://libvirt.org/remote.html#libvirtd-configuration-file), which will lead to TLS being active on the libvirt interface per default (due to `listen_tls` defaulting to being enabled). +This protects data streams for migration as well as the hypervisor control channel data flow with TLS but does not restrict access. +Client certificates must be deployed additionally and libvirt configured accordingly[^4] in order to meaningfully restrict access to the interface as advised by the OSSN-0007 document, see restricting-access in [Libvirt doc](https://wiki.libvirt.org/TLSDaemonConfiguration.html#restricting-access). + +#### Local UNIX socket and SSH live migration + +As an alternative to the TLS setup, libvirt can be configured to use a local UNIX socket and Nova can be configured to use SSH to this socket for live migrations instead. +The regular libvirt port can then be limited to localhost (`127.0.0.1`) which will make it inaccessible from outside the host but still enables local connections to use it. +The challenge of this approach lies in restricting the SSH access on the compute nodes appropriately to avoid full root access across compute nodes for the SSH user identity that Nova will use for live migration. +This can be addressed by restricting the command set that is available and the paths that are accessible to these target SSH user identities on compute nodes, limiting them to the scope strictly required by the live migration. + +A basic setup for combining the UNIX socket with SSH live migration settings is illustrated below. + +Libvirt configuration: + +```conf +listen_tcp = 1 +listen_addr = "127.0.0.1" +unix_sock_group = "libvirt" +unix_sock_ro_perms = "0770" +unix_sock_rw_perms = "0770" +``` + +Nova configuration: + +```ini +[libvirt] +connection_uri= +live_migration_uri=qemu+ssh://... +live_migration_scheme = ssh + +``` + +### TLS Configuration Recommendations + +Server-side TLS configuration is complex and involves a lot of choices for protocol versions, cipher suites and algorithms. +Determining and maintaining secure configuration guidelines for this is non-trivial for a community project as it requires a high level security expertise and consistent evaluation. +For this reason, the standard should reference widely accepted best practices and established third party guidelines instead of creating and maintaining its own set of rules. + +[Mozilla publishes and maintains](https://wiki.mozilla.org/Security/Server_Side_TLS) TLS recommendations and corresponding presets for configuration and testing. +Considering Mozilla's well-established name in the internet and open source communities, this could qualify as a good basis for the standard concerning the TLS configurations. + +### Storage network protection + +As stated in the overview of communication channels, the existence and characteristics of the storage frontend and replication networks are highly specific to the storage backend solution in use. +In conjunction with the fact that storage performance is easily impacted by anything that introduces latency or reduces throughput on these channels, there is no easy recommendation on how to secure them that can be made here. + +This is partially mitigated by OpenStack's ability to encrypt storage data before it enters the storage backend, protecting the data regardless of the storage channels characteristics. +But this only applies to block data of volumes that use an encrypted volume type and does not apply to other data put into the storage backend by OpenStack, for example images. +As such, this does not fully address unsecured storage channels. + +However, requiring the network storage channels to be dedicated physical connections separate from the other channels like tenant VM traffic or API communication can increase both the reliability as well as security of the storage connections. +Therefore this standard should at least recommend a dedicated network infrastructure to be implemented for the storage if network storage backends are used, such as Ceph. + +### Options considered + +#### Option 1: fully mandate securing all channels without differentiation + +This option would reach the highest security standard and establish protection on all identified communication channels simultaneously. +However, this would burden CSPs greatly due to the difficulty of addressing some of the channels and properly maintaining the solution. +Also there is a risk of making this incompatible with existing infrastructures due to some of their specifics being mutually exclusive to the more intricate protection mechanisms such as cross-node WireGuard configurations. +As a third aspect, not all mechanisms might fulfill the CSPs requirements regarding performance and stability and the SCS standard cannot in good faith force CSPs to use technologies not suited to their infrastructures. + +This seems like a bad option from many perspectives. +It also allows very little flexibility and might even make SCS conformance unappealing to CSPs due to the immense effort required to reach it. + +#### Option 2: only make recommendations + +This option would limit the SCS project to only recommend mechanisms in this standard like presented in the OpenStack Security Guide. +Although this can increase awareness about the best practices recommended by OpenStack and maybe encourage CSPs to abide by them, it would actually contribute very little to the security baseline of SCS infrastructures as a whole since everything would stay optional. + +This option would be very easy to standardize and get consensus on due to its lightweight and optional nature. +However, the actual added value for SCS is questionable at best. + +#### Option 3: mix recommendations and obligations + +This option forms a middle ground between options 1 and 2. +For this, the standard needs to carefully assess each communication channel, mechanisms for protecting it and the effort required to do so as well as the implications. +Then, only for mechanisms that are known to be reliable, are feasible to implement and for which the benefits clearly outweigh the integration effort required, should this standard enforce their implementation in a permissive way. +For any remaining mechanisms the SCS standard should only make recommendations and refer to known best practices where applicable. + +This option would still offer improvements over arbitrary OpenStack clouds by establishing a baseline that goes beyond mere recommendations while still taking into account that not all communication channels are equally easy to secure and allowing necessary flexibility for the CSP. + +## Open questions + +### Choosing the best protection mechanism for the libvirt hypervisor interface + +As described in the Design Considerations section, there are multiple ways of securing the libvirt interface and live migration channels using TLS or SSH mechanisms. +Upon closer inspection, this consists of two problems to address: + +1) encrypting migration traffic utilizing the libvirt interface itself +2) identifying/authenticating connecting clients and properly restricting their permission set + +When considering problem no. 1 in an isolated fashion, the QEMU-native TLS approach could be considered preferable simply due to it being officially recommended and documented by upstream OpenStack and tightly integrated into QEMU. + +However, once problem no. 2 is taken into account, the choice does not seem as obvious anymore due to the fact that in order to properly authenticate clients in the TLS case, X.509 client certificate authentication along with a corresponding PKI as well as key management would be required. +Although similar aspects would be relevant for the SSH approach where SSH key and identity management as well as proper permission restriction would need to be implemented, the SSH approach could turn out less complex due to the fact that the foundation for SSH identities most likely already exists on a node-level and does not need to rely on a full PKI. + +To properly compare both possible approaches of securing the libvirt interface, extensive testing and evaulation would be necessary along with a sophisticated key and node identity management for compute nodes which this standard alone does not provide. + +### Verifying standard conformance for internal mechanisms + +Most of the mentioned communication channels to be secured are part of the internal IaaS infrastructure of a SCS cloud. +When an internal protection mechanism is implemented by the CSP it cannot be verified from outside of the infrastructure without administrative access to the infrastructure. + +Thus, the SCS community is unable to fully assess a CSPs conformance to this standard without a dedicated audit of the infrastructure. + +## Standard + +This standard will mandate or recommend appropriate measures for securing the communication channels based on existing standards and recommendations. +It will reference documents like the [OpenStack Security Guide](https://docs.openstack.org/security-guide/) where applicable. + +### Transport Layer Security (TLS) + +- All server-side TLS configurations integrated into the infrastructure as covered by this standard MUST adhere to the ["Intermediate" Mozilla TLS configuration](https://wiki.mozilla.org/Security/Server_Side_TLS#Intermediate_compatibility_.28recommended.29). + +### API Interfaces + +- Internal API endpoints of all OpenStack services MUST use TLS. Their endpoint as registered in the Keystone service catalog MUST be an HTTPS address. +- External API endpoints of all OpenStack services MUST use TLS. Their endpoint as registered in the Keystone service catalog MUST be an HTTPS address. + +You MAY refer to [TLS proxies and HTTP services](https://docs.openstack.org/security-guide/secure-communication/tls-proxies-and-http-services.html) and [Secure reference architectures](https://docs.openstack.org/security-guide/secure-communication/secure-reference-architectures.html) of the OpenStack Security Guide for best practices and recommendations. + +### Database Connections + +- The database servers used by the OpenStack services MUST be configured for TLS transport. +- All OpenStack services MUST have TLS configured for the database connection via the `ssl_ca` directive. See [OpenStack service database configuration](https://docs.openstack.org/security-guide/databases/database-access-control.html#openstack-service-database-configuration). +- Database user accounts for the OpenStack services SHOULD be configured to require TLS connections via the `REQUIRE SSL` SQL directive. See [Require user accounts to require SSL transport](https://docs.openstack.org/security-guide/databases/database-access-control.html#require-user-accounts-to-require-ssl-transport). +- Security MAY be further enhanced by configuring the OpenStack services to use X.509 client certificates for database authentication. See [Authentication with X.509 certificates](https://docs.openstack.org/security-guide/databases/database-access-control.html#authentication-with-x-509-certificates). + +### Message Queue Connections + +- If using RabbitMQ or Qpid as the message queue service, the SSL functionality of the message broker MUST be enabled and used by the OpenStack services. See [Messaging transport security](https://docs.openstack.org/security-guide/messaging/security.html#messaging-transport-security). +- If using Apache Kafka, the server listener MUST be configured to accept SSL connections. See [Apache Kafka Listener Configuration](https://kafka.apache.org/documentation/#listener_configuration). OpenStack services MUST be configured to use an SSL setting for the Kafka driver. See [Kafka Driver Security Options](https://docs.openstack.org/oslo.messaging/latest/admin/kafka.html#security-options). + +### Hypervisor and Live Migration Connections + +- The live migration connections between compute nodes SHOULD be secured by encryption. + - If QEMU and libvirt are used, QEMU-native TLS is an approach officially documented by OpenStack. See [Secure live migration with QEMU-native TLS](https://docs.openstack.org/nova/latest/admin/secure-live-migration-with-qemu-native-tls.html). As an alternative, SSH-based live migration MAY be configured instead. +- If using libvirt as the hypervisor interface on compute nodes the libvirt port (as per its `listen_addr` configuration option) SHOULD NOT be exposed to the network in an unauthenticated and unprotected fashion: + - For the QEMU-native TLS configuration, it is RECOMMENDED to enforce TLS client certificate authentication and assign corresponding client identities to connecting compute nodes. + - For the SSH-based live migration approach, it is RECOMMENDED to limit the libvirt port/socket to the local host and establish SSH key pairs for compute nodes in conjunction with restricted SSH permissions. + +See the [corresponding Design Considerations section](#libvirt-hypervisor-interface-on-compute-nodes) for more details about the mentioned approaches. + +### External VM Connections + +- As an OPTIONAL measure to assist customers in protecting external connections to their OpenStack networks and VMs, the infrastructure MAY provide VPNaaS solutions to users. + - For example the Neutron VPNaaS service MAY be integrated into the infrastructure with the Neutron VPNaaS API extension enabled. See the [Neutron VPNaaS documentation](https://docs.openstack.org/neutron-vpnaas/latest/). + +### Internal Neutron Connections + +- As an OPTIONAL measure to protect Neutron SDN traffic between physical nodes within the infrastructure, encrypted tunnels MAY be established between nodes involved in Neutron networks, such as compute and network controller nodes, at the network interfaces configured in Neutron (e.g. via WireGuard or similar solutions). + +### Storage Connections + +- For storage backends that are connected to OpenStack over the network, the network connections between the OpenStack components and the storage backend SHOULD be located on a separate physical network with dedicated interfaces at the involved nodes. +- For storage backends that transfer replication data between individual storage nodes, the connections between those nodes SHOULD be implemented by a dedicated physical network. +- Where applicable, storage traffic between OpenStack components and the storage backend (frontend traffic) as well as storage replication traffic between storage nodes themselves (backend traffic) MAY be encrypted using the storage protocols native security features (if any) or a generic solution such as WireGuard. + +## Related Documents + +- [OpenStack Security Guide](https://docs.openstack.org/security-guide/) + - [OpenStack Security Guide: Secure communication](https://docs.openstack.org/security-guide/secure-communication.html) + - [OpenStack Security Guide: Database transport security](https://docs.openstack.org/security-guide/databases/database-transport-security.html) + - [OpenStack Security Guide: Messaging transport security](https://docs.openstack.org/security-guide/messaging/security.html#messaging-transport-security) +- [Nova Documentation: Secure live migration with QEMU-native TLS](https://docs.openstack.org/nova/latest/admin/secure-live-migration-with-qemu-native-tls.html) +- [MozillaWiki: Security / Server Side TLS](https://wiki.mozilla.org/Security/Server_Side_TLS) + +## Conformance Tests + +Conformance tests are limited to communication channels exposed to users, such as the public API interfaces. +Internal channels and APIs are currently not part of the automated conformance tests because they are not exposed and cannot be audited without direct access to the infrastructure. + +There is a test suite in [`tls-checker.py`](https://github.com/SovereignCloudStack/standards/blob/main/Tests/iaas/secure-connections/tls-checker.py). +The test suite connects to the OpenStack API and retrieves all public API endpoints from the service catalog. +It then connects to each endpoint and verifies the compliance to the standard by checking SSL/TLS properties against the Mozilla TLS preset. +Please consult the associated [README.md](https://github.com/SovereignCloudStack/standards/blob/main/Tests/iaas/secure-connections/README.md) for detailed setup and testing instructions. diff --git a/Standards/scs-0214-v1-k8s-node-distribution.md b/Standards/scs-0214-v1-k8s-node-distribution.md index ce70e605e..7e48e1389 100644 --- a/Standards/scs-0214-v1-k8s-node-distribution.md +++ b/Standards/scs-0214-v1-k8s-node-distribution.md @@ -84,4 +84,3 @@ If the standard is used by a provider, the following decisions are binding and v [k8s-ha]: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/high-availability/ [k8s-large-clusters]: https://kubernetes.io/docs/setup/best-practices/cluster-large/ [scs-0213-v1]: https://github.com/SovereignCloudStack/standards/blob/main/Standards/scs-0213-v1-k8s-nodes-anti-affinity.md -[k8s-labels-docs]: https://kubernetes.io/docs/reference/labels-annotations-taints/#topologykubernetesiozone diff --git a/Standards/scs-0214-v2-k8s-node-distribution.md b/Standards/scs-0214-v2-k8s-node-distribution.md index 3b4915492..37af338ee 100644 --- a/Standards/scs-0214-v2-k8s-node-distribution.md +++ b/Standards/scs-0214-v2-k8s-node-distribution.md @@ -1,7 +1,8 @@ --- title: Kubernetes Node Distribution and Availability type: Standard -status: Draft +status: Stable +stabilized_at: 2024-11-21 replaces: scs-0214-v1-k8s-node-distribution.md track: KaaS --- @@ -100,23 +101,6 @@ These labels MUST be kept up to date with the current state of the deployment. The field gets autopopulated most of the time by either the kubelet or external mechanisms like the cloud controller. -- `topology.scs.community/host-id` - - This is an SCS-specific label; it MUST contain the hostID of the physical machine running - the hypervisor (NOT: the hostID of a virtual machine). Here, the hostID is an arbitrary identifier, - which need not contain the actual hostname, but it should nonetheless be unique to the host. - This helps identify the distribution over underlying physical machines, - which would be masked if VM hostIDs were used. - -## Conformance Tests - -The script `k8s-node-distribution-check.py` checks the nodes available with a user-provided -kubeconfig file. Based on the labels `topology.scs.community/host-id`, -`topology.kubernetes.io/zone`, `topology.kubernetes.io/region` and `node-role.kubernetes.io/control-plane`, -the script then determines whether the nodes are distributed according to this standard. -If this isn't the case, the script produces an error. -It also produces warnings and informational outputs, e.g., if labels don't seem to be set. - ## Previous standard versions This is version 2 of the standard; it extends [version 1](scs-0214-v1-k8s-node-distribution.md) with the diff --git a/Standards/scs-0214-w1-k8s-node-distribution-implementation-testing.md b/Standards/scs-0214-w1-k8s-node-distribution-implementation-testing.md index 4366365a0..6460cc195 100644 --- a/Standards/scs-0214-w1-k8s-node-distribution-implementation-testing.md +++ b/Standards/scs-0214-w1-k8s-node-distribution-implementation-testing.md @@ -16,25 +16,15 @@ Worker nodes can also be distributed over "failure zones", but this isn't a requ Distribution must be shown through labelling, so that users can access these information. Node distribution metadata is provided through the usage of the labels -`topology.kubernetes.io/region`, `topology.kubernetes.io/zone` and -`topology.scs.community/host-id` respectively. - -At the moment, not all labels are set automatically by most K8s cluster utilities, which incurs -additional setup and maintenance costs. +`topology.kubernetes.io/region` and `topology.kubernetes.io/zone`. ## Automated tests -### Notes - -The test for the [SCS K8s Node Distribution and Availability](https://github.com/SovereignCloudStack/standards/blob/main/Standards/scs-0214-v2-k8s-node-distribution.md) -checks if control-plane nodes are distributed over different failure zones (distributed into -physical machines, zones and regions) by observing their labels defined by the standard. - -### Implementation +Currently, automated testing is not readily possible because we cannot access information about +the underlying host of a node (as opposed to its region and zone). Therefore, the test will only output +a tentative result. -The script [`k8s_node_distribution_check.py`](https://github.com/SovereignCloudStack/standards/blob/main/Tests/kaas/k8s-node-distribution/k8s_node_distribution_check.py) -connects to an existing K8s cluster and checks if a distribution can be detected with the labels -set for the nodes of this cluster. +The current implementation can be found in the script [`k8s_node_distribution_check.py`](https://github.com/SovereignCloudStack/standards/blob/main/Tests/kaas/k8s-node-distribution/k8s_node_distribution_check.py). ## Manual tests diff --git a/Tests/.gitignore b/Tests/.gitignore index 27f5fd549..e3a2cb922 100644 --- a/Tests/.gitignore +++ b/Tests/.gitignore @@ -1,2 +1,3 @@ htmlcov/ .coverage +.secret diff --git a/Tests/add_subject.py b/Tests/add_subject.py new file mode 100755 index 000000000..fabeb9932 --- /dev/null +++ b/Tests/add_subject.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +# vim: set ts=4 sw=4 et: +# +# add_subject.py +# +# (c) Matthias Büchse +# SPDX-License-Identifier: Apache-2.0 +import base64 +import getpass +import os +import os.path +import re +import shutil +import signal +import subprocess +import sys + +try: + from passlib.context import CryptContext + import argon2 # noqa:F401 +except ImportError: + print('Missing passlib and/or argon2. Please do:\npip install passlib argon2_cffi', file=sys.stderr) + sys.exit(1) + +# see ../compliance-monitor/monitor.py +CRYPTCTX = CryptContext(schemes=('argon2', 'bcrypt'), deprecated='auto') +SSH_KEYGEN = shutil.which('ssh-keygen') +SUBJECT_RE = re.compile(r"[a-zA-Z0-9_\-]+") + + +def main(argv, cwd): + if len(argv) != 1: + raise RuntimeError("Need to supply precisely one argument: name of subject") + subject = argv[0] + print(f"Attempt to add subject {subject!r}") + keyfile_path = os.path.join(cwd, '.secret', 'keyfile') + tokenfile_path = os.path.join(cwd, '.secret', 'tokenfile') + if os.path.exists(keyfile_path): + raise RuntimeError(f"Keyfile {keyfile_path} already present. Please proceed manually") + if os.path.exists(tokenfile_path): + raise RuntimeError(f"Tokenfile {tokenfile_path} already present. Please proceed manually") + if not SUBJECT_RE.fullmatch(subject): + raise RuntimeError(f"Subject name {subject!r} using disallowed characters") + sanitized_subject = subject.replace('-', '_') + print("Creating API key...") + while True: + password = getpass.getpass("Enter passphrase: ") + if password == getpass.getpass("Repeat passphrase: "): + break + print("No match. Try again...") + token = base64.b64encode(f"{subject}:{password}".encode('utf-8')) + hash_ = CRYPTCTX.hash(password) + with open(tokenfile_path, "wb") as fileobj: + os.fchmod(fileobj.fileno(), 0o600) + fileobj.write(token) + print("Creating key file using `ssh-keygen`...") + subprocess.check_call([SSH_KEYGEN, '-t', 'ed25519', '-C', sanitized_subject, '-f', keyfile_path, '-N', '', '-q']) + with open(keyfile_path + '.pub', "r") as fileobj: + pubkey_components = fileobj.readline().split() + print(f''' +The following SECRET files have been created: + + - {keyfile_path} + - {tokenfile_path} + +They are required for submitting test reports. You MUST keep them secure and safe. + +Insert the following snippet into compliance-monitor/bootstrap.yaml: + + - subject: {subject} + api_keys: + - "{hash_}" + keys: + - public_key: "{pubkey_components[1]}" + public_key_type: "{pubkey_components[0]}" + public_key_name: "primary" + +Make sure to submit a pull request with the changed file. Otherwise, the reports cannot be submitted. +''', end='') + + +if __name__ == "__main__": + try: + sys.exit(main(sys.argv[1:], cwd=os.path.dirname(sys.argv[0]) or os.getcwd()) or 0) + except RuntimeError as e: + print(str(e), file=sys.stderr) + sys.exit(1) + except KeyboardInterrupt: + print("Interrupted", file=sys.stderr) + sys.exit(128 + signal.SIGINT) diff --git a/Tests/iaas/secure-connections/README.md b/Tests/iaas/secure-connections/README.md new file mode 100644 index 000000000..9262f1ee2 --- /dev/null +++ b/Tests/iaas/secure-connections/README.md @@ -0,0 +1,61 @@ +# Secure Connections Standard Test Suite + +## Test Environment Setup + +> **NOTE:** The test execution procedure does not require cloud admin rights. + +A valid cloud configuration for the OpenStack SDK in the shape of "`clouds.yaml`" is mandatory[^1]. +**This file is expected to be located in the current working directory where the test script is executed unless configured otherwise.** + +[^1]: [OpenStack Documentation: Configuring OpenStack SDK Applications](https://docs.openstack.org/openstacksdk/latest/user/config/configuration.html) + +The test execution environment can be located on any system outside of the cloud infrastructure that has OpenStack API access. +Make sure that the API access is configured properly in "`clouds.yaml`". + +It is recommended to use a Python virtual environment[^2]. +Next, install the libraries required by the test suite: + +```bash +pip3 install openstacksdk sslyze +``` + +> Note: the version of the sslyze library determines the [version of the Mozilla TLS recommendation JSON](https://wiki.mozilla.org/Security/Server_Side_TLS#JSON_version_of_the_recommendations) that it checks against. + +Within this environment execute the test suite. + +[^2]: [Python 3 Documentation: Virtual Environments and Packages](https://docs.python.org/3/tutorial/venv.html) + +## Test Execution + +The test suite is executed as follows: + +```bash +python3 tls-checker.py --os-cloud mycloud +``` + +As an alternative to "`--os-cloud`", the "`OS_CLOUD`" environment variable may be specified instead. +The parameter is used to look up the correct cloud configuration in "`clouds.yaml`". +For the example command above, this file should contain a `clouds.mycloud` section like this: + +```yaml +--- +clouds: + mycloud: + auth: + auth_url: ... + ... + ... +``` + +For any further options consult the output of "`python3 tls-checker.py --help`". + +### Script Behavior & Test Results + +The script will print all actions and passed tests to `stdout`. + +If all tests pass, the script will return with an exit code of `0`. + +If any test fails, the script will halt, print the exact error to `stderr` and return with a non-zero exit code. + +Any tests that indicate a recommendation of the standard is not met, will print a warning message under the corresponding endpoint output. +However, unmet recommendations will not count as errors. diff --git a/Tests/iaas/secure-connections/mozilla-tls-profiles/5.7.json b/Tests/iaas/secure-connections/mozilla-tls-profiles/5.7.json new file mode 100644 index 000000000..764aadaeb --- /dev/null +++ b/Tests/iaas/secure-connections/mozilla-tls-profiles/5.7.json @@ -0,0 +1,209 @@ +{ + "version": 5.7, + "href": "https://ssl-config.mozilla.org/guidelines/5.7.json", + "configurations": { + "modern": { + "certificate_curves": ["prime256v1", "secp384r1"], + "certificate_signatures": ["ecdsa-with-SHA256", "ecdsa-with-SHA384", "ecdsa-with-SHA512"], + "certificate_types": ["ecdsa"], + "ciphers": { + "caddy": [], + "go": [], + "iana": [], + "openssl": [] + }, + "ciphersuites": [ + "TLS_AES_128_GCM_SHA256", + "TLS_AES_256_GCM_SHA384", + "TLS_CHACHA20_POLY1305_SHA256" + ], + "dh_param_size": null, + "ecdh_param_size": 256, + "hsts_min_age": 63072000, + "maximum_certificate_lifespan": 90, + "ocsp_staple": true, + "oldest_clients": ["Firefox 63", "Android 10.0", "Chrome 70", "Edge 75", "Java 11", "OpenSSL 1.1.1", "Opera 57", "Safari 12.1"], + "recommended_certificate_lifespan": 90, + "rsa_key_size": null, + "server_preferred_order": false, + "tls_curves": ["X25519", "prime256v1", "secp384r1"], + "tls_versions": ["TLSv1.3"] + }, + "intermediate": { + "certificate_curves": ["prime256v1", "secp384r1"], + "certificate_signatures": ["sha256WithRSAEncryption", "ecdsa-with-SHA256", "ecdsa-with-SHA384", "ecdsa-with-SHA512"], + "certificate_types": ["ecdsa", "rsa"], + "ciphers": { + "caddy": [ + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" + ], + "go": [ + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305" + ], + "iana": [ + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" + ], + "openssl": [ + "ECDHE-ECDSA-AES128-GCM-SHA256", + "ECDHE-RSA-AES128-GCM-SHA256", + "ECDHE-ECDSA-AES256-GCM-SHA384", + "ECDHE-RSA-AES256-GCM-SHA384", + "ECDHE-ECDSA-CHACHA20-POLY1305", + "ECDHE-RSA-CHACHA20-POLY1305", + "DHE-RSA-AES128-GCM-SHA256", + "DHE-RSA-AES256-GCM-SHA384", + "DHE-RSA-CHACHA20-POLY1305" + ] + }, + "ciphersuites": [ + "TLS_AES_128_GCM_SHA256", + "TLS_AES_256_GCM_SHA384", + "TLS_CHACHA20_POLY1305_SHA256" + ], + "dh_param_size": 2048, + "ecdh_param_size": 256, + "hsts_min_age": 63072000, + "maximum_certificate_lifespan": 366, + "ocsp_staple": true, + "oldest_clients": ["Firefox 27", "Android 4.4.2", "Chrome 31", "Edge", "IE 11 on Windows 7", "Java 8u31", "OpenSSL 1.0.1", "Opera 20", "Safari 9"], + "recommended_certificate_lifespan": 90, + "rsa_key_size": 2048, + "server_preferred_order": false, + "tls_curves": ["X25519", "prime256v1", "secp384r1"], + "tls_versions": ["TLSv1.2", "TLSv1.3"] + }, + "old": { + "certificate_curves": ["prime256v1", "secp384r1"], + "certificate_signatures": ["sha256WithRSAEncryption"], + "certificate_types": ["rsa"], + "ciphers": { + "caddy": [ + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_3DES_EDE_CBC_SHA" + ], + "go": [ + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA256", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_3DES_EDE_CBC_SHA" + ], + "iana": [ + "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", + "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384", + "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", + "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", + "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", + "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", + "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256", + "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256", + "TLS_RSA_WITH_AES_128_GCM_SHA256", + "TLS_RSA_WITH_AES_256_GCM_SHA384", + "TLS_RSA_WITH_AES_128_CBC_SHA256", + "TLS_RSA_WITH_AES_256_CBC_SHA256", + "TLS_RSA_WITH_AES_128_CBC_SHA", + "TLS_RSA_WITH_AES_256_CBC_SHA", + "TLS_RSA_WITH_3DES_EDE_CBC_SHA" + ], + "openssl": [ + "ECDHE-ECDSA-AES128-GCM-SHA256", + "ECDHE-RSA-AES128-GCM-SHA256", + "ECDHE-ECDSA-AES256-GCM-SHA384", + "ECDHE-RSA-AES256-GCM-SHA384", + "ECDHE-ECDSA-CHACHA20-POLY1305", + "ECDHE-RSA-CHACHA20-POLY1305", + "DHE-RSA-AES128-GCM-SHA256", + "DHE-RSA-AES256-GCM-SHA384", + "DHE-RSA-CHACHA20-POLY1305", + "ECDHE-ECDSA-AES128-SHA256", + "ECDHE-RSA-AES128-SHA256", + "ECDHE-ECDSA-AES128-SHA", + "ECDHE-RSA-AES128-SHA", + "ECDHE-ECDSA-AES256-SHA384", + "ECDHE-RSA-AES256-SHA384", + "ECDHE-ECDSA-AES256-SHA", + "ECDHE-RSA-AES256-SHA", + "DHE-RSA-AES128-SHA256", + "DHE-RSA-AES256-SHA256", + "AES128-GCM-SHA256", + "AES256-GCM-SHA384", + "AES128-SHA256", + "AES256-SHA256", + "AES128-SHA", + "AES256-SHA", + "DES-CBC3-SHA" + ] + }, + "ciphersuites": [ + "TLS_AES_128_GCM_SHA256", + "TLS_AES_256_GCM_SHA384", + "TLS_CHACHA20_POLY1305_SHA256" + ], + "dh_param_size": 1024, + "ecdh_param_size": 256, + "hsts_min_age": 63072000, + "maximum_certificate_lifespan": 366, + "ocsp_staple": true, + "oldest_clients": ["Firefox 1", "Android 2.3", "Chrome 1", "Edge 12", "IE8 on Windows XP", "Java 6", "OpenSSL 0.9.8", "Opera 5", "Safari 1"], + "recommended_certificate_lifespan": 90, + "rsa_key_size": 2048, + "server_preferred_order": true, + "tls_curves": ["X25519", "prime256v1", "secp384r1"], + "tls_versions": ["TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"] + } + } +} diff --git a/Tests/iaas/secure-connections/mozilla-tls-profiles/README.md b/Tests/iaas/secure-connections/mozilla-tls-profiles/README.md new file mode 100644 index 000000000..08c1328fd --- /dev/null +++ b/Tests/iaas/secure-connections/mozilla-tls-profiles/README.md @@ -0,0 +1,4 @@ +# Mozilla TLS Profiles + +Files in this folder are used for automated testing. +They are pulled from [Mozilla Wiki: Security/Server Side TLS](https://wiki.mozilla.org/Security/Server_Side_TLS#JSON_version_of_the_recommendations) diff --git a/Tests/iaas/secure-connections/tls-checker.py b/Tests/iaas/secure-connections/tls-checker.py new file mode 100644 index 000000000..d080c4123 --- /dev/null +++ b/Tests/iaas/secure-connections/tls-checker.py @@ -0,0 +1,315 @@ +"""SSL/TLS checker for OpenStack API endpoints + +This script retrieves the endpoint catalog from Keystone using the OpenStack +SDK and connects to each to each public endpoint to check its SSL/TLS settings. +The script relies on an OpenStack SDK compatible clouds.yaml file for +authentication with Keystone. + +For each endpoint, SSL/TLS protocol parameters supported by the server are +checked using the SSLyze Python library. +The script will fail with a non-zero exit code in case any standard violation +is discovered such as endpoints being non-conformant to the corresponding +Mozilla TLS recommendations. +Details about the conformance issues will be printed for each endpoint to +help with identifying and addressing the violations of the Mozilla TLS preset. +""" + +import argparse +import getpass +import json +import os +import sys +import typing + +import openstack +import sslyze +from sslyze.mozilla_tls_profile.mozilla_config_checker import ( + SCAN_COMMANDS_NEEDED_BY_MOZILLA_CHECKER, MozillaTlsConfigurationChecker, + MozillaTlsConfigurationEnum, ServerNotCompliantWithMozillaTlsConfiguration, + _MozillaTlsProfileAsJson) + + +class MozillaTlsValidator(object): + """Configurable wrapper for MozillaTlsConfigurationChecker + + Configures the MozillaTlsConfigurationChecker of SSLyze according + to given parameters concerning the Mozilla TLS Profile JSON to use + and configuration level to select (old, intermediate, modern). + + For reference see: https://wiki.mozilla.org/Security/Server_Side_TLS + """ + + def __init__(self, configuration_level: str, + json_path: typing.Optional[str]) -> None: + """Create a connection to an OpenStack cloud + + :param string configuration_level: + Name of the Mozilla TLS configuration level to select. + + :param string json_path: + Optional path to a JSON file containing the Mozilla TLS + recommendations. + + :returns: MozillaTlsValidator + """ + if json_path: + print(f"INFO: Loading custom Mozilla TLS Profile JSON from " + f"{json_path}") + if not os.path.exists(json_path) or not os.path.isfile(json_path): + raise Exception( + f"No such file '{json_path}'" + ) + with open(json_path, 'r') as json_file: + json_content = json.load(json_file) + self.profile = _MozillaTlsProfileAsJson(**json_content) + else: + self.profile = None + + for level in MozillaTlsConfigurationEnum: + if level.value == configuration_level: + self.config_level = level + print(f"INFO: Using profile level '{level.value}' of the " + f"Mozilla TLS configuration") + break + else: + valid_levels = [ + level.value for level in MozillaTlsConfigurationEnum + ] + raise Exception( + f"Mozilla TLS configuration profile level " + f"'{configuration_level}' is invalid, valid " + f"options are: {valid_levels}" + ) + + def check_scan_result(self, result: sslyze.ServerScanResult): + """ + Validate the given ServerScanResult against the Mozilla TLS Profile. + + Will raise a ServerNotCompliantWithMozillaTlsConfiguration exception + if any violations of the TLS profile are detected. + """ + if self.profile: + mozilla_checker = MozillaTlsConfigurationChecker(self.profile) + else: + mozilla_checker = MozillaTlsConfigurationChecker.get_default() + mozilla_checker.check_server(self.config_level, result) + + +def connect(cloud_name: str, password: typing.Optional[str] = None + ) -> openstack.connection.Connection: + """Create a connection to an OpenStack cloud + + :param string cloud_name: + The name of the configuration to load from clouds.yaml. + + :param string password: + Optional password override for the connection. + + :returns: openstack.connnection.Connection + """ + + if password: + return openstack.connect( + cloud=cloud_name, + password=password + ) + else: + return openstack.connect( + cloud=cloud_name, + ) + + +def retrieve_endpoints(conn: openstack.connection.Connection) \ + -> dict[str, dict[str, str]]: + """Enumerate all endpoints of the service catalog returned by the + current connection categorized by interface type and service. + + Resulting structure: + { + : { + : + } + } + + where is public, internal or admin. + """ + + ret = {} + + for svc in conn.service_catalog: + svc_name = svc['name'] + for endpoint in svc.get('endpoints'): + enp_type = endpoint['interface'] + enp_url = endpoint['url'] + subdict = ret.setdefault(enp_type, {}) + subdict[svc_name] = enp_url + + print("\nINFO: the following public endpoints have been retrieved from " + "the service catalog:") + for svc_name in ret["public"].keys(): + print( + f"↳ {svc_name} @ {ret['public'][svc_name]}" + ) + + return ret + + +def verify_tls(service: str, host: str, port: int, + mozilla_tls: MozillaTlsValidator) -> bool: + """Use SSLyze library to scan the SSL/TLS interface of the server. + + Evaluates the SSL/TLS configurations the server reports as supported. + Checks the scan results against the Mozilla TLS recommendation preset. + Prints any issues found with details. + + If `mozilla_json_preset` is passed into this function, it is interpreted + as the Mozilla TLS Profile JSON to be used. If this argument is None or + not specified, the default JSON shipped with the respective SSLyze release + is used instead. The format of this optional argument is expected to be + the parsed JSON as dict. + + Returns True if no errors were encountered, False otherwise. + """ + + errors_encountered = 0 + server = sslyze.ServerNetworkLocation(host, port) + scans = SCAN_COMMANDS_NEEDED_BY_MOZILLA_CHECKER + request = sslyze.ServerScanRequest(server, scan_commands=scans) + scanner = sslyze.Scanner() + scanner.queue_scans([request]) + for result in scanner.get_results(): + assert result.scan_result, ( + f"Service '{service}' at {host}:{port} did not respond to " + f"TLS connection" + ) + try: + mozilla_tls.check_scan_result(result) + print( + f"Service '{service}' at {host}:{port} complies to " + f"TLS recommendations: PASS" + ) + except ServerNotCompliantWithMozillaTlsConfiguration as e: + print( + f"Service '{service}' at {host}:{port} complies to " + f"TLS recommendations: FAIL" + ) + for criteria, error_description in e.issues.items(): + print(f"↳ {criteria}: {error_description}") + errors_encountered += 1 + + return errors_encountered == 0 + + +def check_endpoints(endpoints: dict[str, str], + ignore: typing.Optional[str], + mozilla_tls: MozillaTlsValidator) -> None: + ignore_list = ignore.split(',') if ignore else [] + error_count = 0 + for service in endpoints: + url = endpoints[service] + host_ref = url.split("://", 1)[-1].split("/", 1)[0] + + # Check if the endpoint matches any of the given ignore patterns. + ignored = False + for ignore_pattern in ignore_list: + if ignore_pattern in host_ref: + print( + f"INFO: Matching ignore rule for '{ignore_pattern}', " + f"ignoring endpoint: {url}" + ) + ignored = True + break + if ignored: + continue + + # Default to port 443 if no port is specified + if ':' in host_ref: + host, port = host_ref.split(':', 1) + else: + host = host_ref + port = 443 + + print(f"INFO: Checking public '{service}' endpoint {host}:{port} ...") + # Collect errors instead of failing immediately; this makes the output + # more useful since all endpoints are checked in one run and the + # printed output will cover all of them, logging all issues at once + error_count = error_count if verify_tls( + service, host, int(port), mozilla_tls + ) else error_count + 1 + + print( + f"INFO: Number of endpoints that failed compliance check: " + f"{error_count} (out of {len(endpoints)})" + ) + if error_count > 0: + sys.exit(1) + + +def main(): + parser = argparse.ArgumentParser( + description="SCS Domain Manager Conformance Checker") + parser.add_argument( + "--os-cloud", type=str, + help="Name of the cloud from clouds.yaml, alternative " + "to the OS_CLOUD environment variable" + ) + parser.add_argument( + "--ask", + help="Ask for password interactively instead of reading it from the " + "clouds.yaml", + action="store_true" + ) + parser.add_argument( + "--ignore", type=str, + help="Comma-separated list of host names or host:port combinations " + "to exclude from testing", + ) + parser.add_argument( + "--debug", action="store_true", + help="Enable OpenStack SDK debug logging" + ) + parser.add_argument( + "--mozilla-profile-json", type=str, + help="Path to the Mozilla TLS Profile JSON to be used as the basis " + "for the checks (optional)", + ) + moz_tls_default_level = "intermediate" + parser.add_argument( + "--mozilla-profile-level", type=str, + default=moz_tls_default_level, + help=f"Name of the Mozilla TLS Profile configuration level name " + f"(default: {moz_tls_default_level})", + ) + args = parser.parse_args() + openstack.enable_logging(debug=args.debug) + + # parse cloud name for lookup in clouds.yaml + cloud = os.environ.get("OS_CLOUD", None) + if args.os_cloud: + cloud = args.os_cloud + assert cloud, ( + "You need to have the OS_CLOUD environment variable set to your " + "cloud name or pass it via --os-cloud" + ) + conn = connect( + cloud, + password=getpass.getpass("Enter password: ") if args.ask else None + ) + + endpoints_catalog = retrieve_endpoints(conn) + assert "public" in endpoints_catalog, ( + "No public endpoints found in the service catalog" + ) + endpoints = endpoints_catalog["public"] + + mozilla_tls = MozillaTlsValidator( + args.mozilla_profile_level, + # load the Mozilla TLS Profile from JSON if specified + args.mozilla_profile_json if args.mozilla_profile_json else None + ) + + check_endpoints(endpoints, args.ignore, mozilla_tls) + + +if __name__ == "__main__": + main() diff --git a/Tests/kaas/k8s-node-distribution/check_nodes_test.py b/Tests/kaas/k8s-node-distribution/check_nodes_test.py index d32edccfb..439d1b18e 100644 --- a/Tests/kaas/k8s-node-distribution/check_nodes_test.py +++ b/Tests/kaas/k8s-node-distribution/check_nodes_test.py @@ -42,9 +42,9 @@ def test_not_enough_nodes(caplog, load_testdata): @pytest.mark.parametrize("yaml_key", ["no-distribution-1", "no-distribution-2"]) -def test_no_distribution(yaml_key, caplog, load_testdata): +def notest_no_distribution(yaml_key, caplog, load_testdata): data = load_testdata[yaml_key] - with caplog.at_level("ERROR"): + with caplog.at_level("WARNING"): assert check_nodes(data.values()) == 2 assert len(caplog.records) == 1 record = caplog.records[0] @@ -52,7 +52,7 @@ def test_no_distribution(yaml_key, caplog, load_testdata): assert record.levelname == "ERROR" -def test_missing_label(caplog, load_testdata): +def notest_missing_label(caplog, load_testdata): data = load_testdata["missing-labels"] assert check_nodes(data.values()) == 2 hostid_missing_records = [ diff --git a/Tests/kaas/k8s-node-distribution/k8s_node_distribution_check.py b/Tests/kaas/k8s-node-distribution/k8s_node_distribution_check.py index efac000d4..038d8a67c 100755 --- a/Tests/kaas/k8s-node-distribution/k8s_node_distribution_check.py +++ b/Tests/kaas/k8s-node-distribution/k8s_node_distribution_check.py @@ -22,7 +22,6 @@ and does require these labels to be set, but should yield overall pretty good initial results. - topology.scs.openstack.org/host-id # previously kubernetes.io/hostname topology.kubernetes.io/zone topology.kubernetes.io/region node-role.kubernetes.io/control-plane @@ -47,7 +46,6 @@ LABELS = ( "topology.kubernetes.io/region", "topology.kubernetes.io/zone", - "topology.scs.community/host-id", ) logger = logging.getLogger(__name__) @@ -164,12 +162,11 @@ def compare_labels(node_list, node_type="control"): ) return - if node_type == "control": - raise DistributionException("The distribution of nodes described in the standard couldn't be detected.") - elif node_type == "worker": - logger.warning("No node distribution could be detected for the worker nodes. " - "This produces only a warning, since it is just a recommendation.") - return + # + # if node_type == "control": + # raise DistributionException("The distribution of nodes described in the standard couldn't be detected.") + logger.warning("No node distribution could be detected for the worker nodes. " + "This produces only a warning, since it is just a recommendation.") def check_nodes(nodes): diff --git a/Tests/kaas/k8s-version-policy/k8s_version_policy.py b/Tests/kaas/k8s-version-policy/k8s_version_policy.py index cef272acd..a2acd3cd5 100755 --- a/Tests/kaas/k8s-version-policy/k8s_version_policy.py +++ b/Tests/kaas/k8s-version-policy/k8s_version_policy.py @@ -171,7 +171,7 @@ def __str__(self): def parse_version(version_str: str) -> K8sVersion: - cleansed = version_str.strip().removeprefix("v") + cleansed = version_str.strip().removeprefix("v").split("+")[0] # remove leading v as well as build info try: major, minor, patch = cleansed.split(".") return K8sVersion(int(major), int(minor), int(patch)) diff --git a/Tests/requirements.in b/Tests/requirements.in index cb3c3bac0..8a96fb744 100644 --- a/Tests/requirements.in +++ b/Tests/requirements.in @@ -6,4 +6,5 @@ python-dateutil PyYAML openstacksdk # TODO: move into iaas/requirements.in requests +sslyze tomli diff --git a/Tests/requirements.txt b/Tests/requirements.txt index 19f9e1990..6597d173b 100644 --- a/Tests/requirements.txt +++ b/Tests/requirements.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.12 # by the following command: # -# pip-compile requirements.in +# pip-compile --output-file=requirements.txt requirements.in # aiohappyeyeballs==2.3.5 # via aiohttp @@ -31,7 +31,9 @@ charset-normalizer==3.3.2 click==8.1.7 # via -r requirements.in cryptography==43.0.1 - # via openstacksdk + # via + # openstacksdk + # sslyze decorator==5.1.1 # via # dogpile-cache @@ -67,6 +69,8 @@ multidict==6.0.5 # via # aiohttp # yarl +nassl==1.0.3 + # via sslyze netifaces==0.11.0 # via openstacksdk openstacksdk==3.3.0 @@ -109,10 +113,14 @@ six==1.16.0 # via # kubernetes-asyncio # python-dateutil +sslyze==1.3.4 + # via -r requirements.in stevedore==5.2.0 # via # dogpile-cache # keystoneauth1 +tls-parser==1.2.2 + # via sslyze tomli==2.0.1 # via -r requirements.in urllib3==2.2.2 diff --git a/Tests/scs-compatible-kaas.yaml b/Tests/scs-compatible-kaas.yaml index 7cb2fbd58..74cbc3edb 100644 --- a/Tests/scs-compatible-kaas.yaml +++ b/Tests/scs-compatible-kaas.yaml @@ -16,6 +16,8 @@ modules: testcases: - id: cncf-k8s-conformance tags: [mandatory] + description: > + Must fulfill all requirements of [CNCF Kubernetes conformance](https://github.com/cncf/k8s-conformance/tree/master) - id: scs-0210-v2 name: Kubernetes version policy url: https://docs.scs.community/standards/scs-0210-v2-k8s-version-policy @@ -25,6 +27,8 @@ modules: testcases: - id: version-policy-check tags: [mandatory] + description: > + Must fulfill all requirements of - id: scs-0214-v2 name: Kubernetes node distribution and availability url: https://docs.scs.community/standards/scs-0214-v2-k8s-node-distribution @@ -34,6 +38,8 @@ modules: testcases: - id: node-distribution-check tags: [mandatory] + description: > + Must fulfill all requirements of - id: scs-0219-v1 name: KaaS networking url: https://docs.scs.community/standards/scs-0219-v1-kaas-networking @@ -43,12 +49,18 @@ modules: testcases: - id: kaas-networking-check tags: [mandatory] + description: > + Must fulfill all requirements of timeline: + - date: 2024-11-26 + versions: + v1: effective - date: 2024-02-28 versions: v1: draft versions: - version: v1 + stabilized_at: 2024-11-26 include: - cncf-k8s-conformance - scs-0210-v2 diff --git a/Tests/testing/scs-compatible-test.yaml b/Tests/testing/scs-compatible-test.yaml index 5b37c8904..2d37c6bf3 100644 --- a/Tests/testing/scs-compatible-test.yaml +++ b/Tests/testing/scs-compatible-test.yaml @@ -1,6 +1,43 @@ name: SCS Compatible url: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Tests/scs-compatible.yaml +variables: + - os_cloud versions: + - version: v5 + standards: + - name: Secure Connections + url: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Standards/scs-0122-v1-secure-connections.md + parameters: + - mozilla_tls_profile_version: "5.7" + - mozilla_tls_profile_preset: "intermediate" + check_tools: + - executable: ./iaas/secure-connections/tls-checker.py + args: --os-cloud {os_cloud} --mozilla-profile-json ./iaas/secure-connections/mozilla-tls-profiles/{mozilla_tls_profile_version}.json --mozilla-profile-level {mozilla_tls_profile_preset} + id: tls-configuration-check + - name: Standard flavors + url: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Standards/scs-0103-v1-standard-flavors.md + check_tools: + - executable: ./iaas/standard-flavors/flavors-openstack.py + args: "./iaas/scs-0103-v1-flavors.yaml" + - name: Standard images + url: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Standards/scs-0104-v1-standard-images.md + check_tools: + - executable: ./iaas/standard-images/images-openstack.py + args: "./iaas/scs-0104-v1-flavors.yaml" + - name: Flavor naming + url: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Standards/scs-0100-v3-flavor-naming.md + check_tools: + - executable: ./iaas/flavor-naming/flavor-names-openstack.py + args: "--mand=./iaas/scs-0100-v3-flavors.yaml" + - name: Image metadata + url: https://raw.githubusercontent.com/SovereignCloudStack/standards/main/Standards/scs-0102-v1-image-metadata.md + check_tools: + - executable: ./iaas/image-metadata/image-md-check.py + args: -s -v + - name: OpenStack Powered Compute v2022.11 + url: https://opendev.org/openinfra/interop/src/branch/master/guidelines/2022.11.json + condition: mandatory + # Unfortunately, no wrapper to run refstack yet, needs to be added - version: v4 standards: - name: Standard flavors