├── ironic_secureboot_driver ├── tests │ ├── __init__.py │ ├── base.py │ └── test_driver.py ├── __init__.py └── driver.py ├── .stestr.conf ├── .coveragerc ├── requirements.txt ├── test-requirements.txt ├── .gitignore ├── setup.py ├── setup.cfg ├── tox.ini ├── Contributing.md ├── README.md ├── Code-of-Conduct.md └── LICENSE /ironic_secureboot_driver/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.stestr.conf: -------------------------------------------------------------------------------- 1 | [DEFAULT] 2 | test_path=./ironic_secureboot_driver/tests 3 | top_dir=./ 4 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | branch = True 3 | source = ironic_secureboot_driver 4 | 5 | [report] 6 | ignore_errors = True 7 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # The order of packages is significant, because pip processes them in the order 2 | # of appearance. Changing the order has an impact on the overall integration 3 | # process, which may cause wedges in the gate later. 4 | 5 | pbr>=2.0 # Apache-2.0 6 | -------------------------------------------------------------------------------- /test-requirements.txt: -------------------------------------------------------------------------------- 1 | # The order of packages is significant, because pip processes them in the order 2 | # of appearance. Changing the order has an impact on the overall integration 3 | # process, which may cause wedges in the gate later. 4 | 5 | hacking>=0.12.0,<0.13 # Apache-2.0 6 | 7 | coverage>=4.0,!=4.4 # Apache-2.0 8 | python-subunit>=0.0.18 # Apache-2.0/BSD 9 | oslotest>=1.10.0 # Apache-2.0 10 | stestr>=1.0.0 # Apache-2.0 11 | testtools>=1.4.0 # MIT 12 | 13 | git+https://git.openstack.org/openstack/ironic#egg=ironic 14 | -------------------------------------------------------------------------------- /ironic_secureboot_driver/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | # not use this file except in compliance with the License. You may obtain 5 | # a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | import pbr.version 16 | 17 | 18 | __version__ = pbr.version.VersionInfo( 19 | 'ironic-secureboot-driver').version_string() 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg* 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | bin 14 | var 15 | sdist 16 | develop-eggs 17 | .installed.cfg 18 | lib 19 | lib64 20 | 21 | # Installer logs 22 | pip-log.txt 23 | 24 | # Unit test / coverage reports 25 | cover/ 26 | .coverage* 27 | !.coveragerc 28 | .tox 29 | nosetests.xml 30 | .testrepository 31 | .stestr 32 | .venv 33 | 34 | # Translations 35 | *.mo 36 | 37 | # Mr Developer 38 | .mr.developer.cfg 39 | .project 40 | .pydevproject 41 | 42 | # Complexity 43 | output/*.html 44 | output/*/index.html 45 | 46 | # Sphinx 47 | doc/build 48 | 49 | # pbr generates these 50 | AUTHORS 51 | ChangeLog 52 | 53 | # Editors 54 | *~ 55 | .*.swp 56 | .*sw? 57 | 58 | # Files created by releasenotes build 59 | releasenotes/build 60 | -------------------------------------------------------------------------------- /ironic_secureboot_driver/tests/base.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright 2010-2011 OpenStack Foundation 4 | # Copyright (c) 2013 Hewlett-Packard Development Company, L.P. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 7 | # not use this file except in compliance with the License. You may obtain 8 | # a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | # License for the specific language governing permissions and limitations 16 | # under the License. 17 | 18 | from oslotest import base 19 | 20 | 21 | class TestCase(base.BaseTestCase): 22 | 23 | """Test case base class for all unit tests.""" 24 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Hewlett-Packard Development Company, L.P. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 | # implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT 17 | import setuptools 18 | 19 | # In python < 2.7.4, a lazy loading of package `pbr` will break 20 | # setuptools if some other modules registered functions in `atexit`. 21 | # solution from: http://bugs.python.org/issue15881#msg170215 22 | try: 23 | import multiprocessing # noqa 24 | except ImportError: 25 | pass 26 | 27 | setuptools.setup( 28 | setup_requires=['pbr'], 29 | pbr=True) 30 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = ironic-secureboot-driver 3 | summary = Ironic plugin to provide a boot driver and hardware type for secureboot deployments at Oath. 4 | description-file = 5 | README.md 6 | author = Oath 7 | author-email = jim.rollenhagen@oath.com 8 | classifier = 9 | Environment :: OpenStack 10 | Intended Audience :: Information Technology 11 | Intended Audience :: System Administrators 12 | License :: OSI Approved :: Apache Software License 13 | Operating System :: POSIX :: Linux 14 | Programming Language :: Python 15 | Programming Language :: Python :: 2 16 | Programming Language :: Python :: 2.7 17 | Programming Language :: Python :: 3 18 | Programming Language :: Python :: 3.5 19 | 20 | [files] 21 | packages = 22 | ironic_secureboot_driver 23 | 24 | [entry_points] 25 | ironic.hardware.types = 26 | secureboot_ipmi = ironic_secureboot_driver.driver:SecurebootIPMIHardware 27 | ironic.hardware.interfaces.boot = 28 | secureboot = ironic_secureboot_driver.driver:Secureboot 29 | ironic.hardware.interfaces.management = 30 | httpmi = ironic_secureboot_driver.driver:HttpmiManagement 31 | ironic.hardware.interfaces.power = 32 | httpmi = ironic_secureboot_driver.driver:HttpmiPower 33 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | minversion = 2.0 3 | envlist = py36,py35,py27,pep8 4 | skipsdist = True 5 | 6 | [testenv] 7 | usedevelop = True 8 | install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} 9 | setenv = 10 | VIRTUAL_ENV={envdir} 11 | PYTHONWARNINGS=default::DeprecationWarning 12 | OS_STDOUT_CAPTURE=1 13 | OS_STDERR_CAPTURE=1 14 | OS_TEST_TIMEOUT=60 15 | deps = -r{toxinidir}/test-requirements.txt 16 | commands = stestr run {posargs} 17 | 18 | [testenv:pep8] 19 | commands = flake8 {posargs} 20 | 21 | [testenv:venv] 22 | commands = {posargs} 23 | 24 | [testenv:cover] 25 | setenv = 26 | VIRTUAL_ENV={envdir} 27 | PYTHON=coverage run --source ironic_secureboot_driver --parallel-mode 28 | commands = 29 | stestr run {posargs} 30 | coverage combine 31 | coverage html -d cover 32 | coverage xml -o cover/coverage.xml 33 | 34 | [testenv:debug] 35 | commands = oslo_debug_helper {posargs} 36 | 37 | [flake8] 38 | # E123, E125 skipped as they are invalid PEP-8. 39 | # H102 disabled because Oath prefers the short version 40 | show-source = True 41 | ignore = E123,E125,H102 42 | builtins = _ 43 | exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build 44 | -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | First, thanks for taking the time to contribute to our project! The following information provides a guide for making contributions. 3 | 4 | ## Code of Conduct 5 | 6 | By participating in this project, you agree to abide by the [Oath Code of Conduct](Code-of-Conduct.md). Everyone is welcome to submit a pull request or open an issue to improve the documentation, add improvements, or report bugs. 7 | 8 | ## How to Ask a Question 9 | 10 | If you simply have a question that needs an answer, [create an issue](https://help.github.com/articles/creating-an-issue/), and label it as a question. 11 | 12 | ## How To Contribute 13 | 14 | ### Report a Bug or Request a Feature 15 | 16 | If you encounter any bugs while using this software, or want to request a new feature or enhancement, feel free to [create an issue](https://help.github.com/articles/creating-an-issue/) to report it, make sure you add a label to indicate what type of issue it is. 17 | 18 | ### Contribute Code 19 | Pull requests are welcome for bug fixes. If you want to implement something new, please [request a feature first](#report-a-bug-or-request-a-feature) so we can discuss it. 20 | 21 | #### Creating a Pull Request 22 | - The following line must be included in your pull request: 23 | > I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner. 24 | Please follow [best practices](https://github.com/trein/dev-best-practices/wiki/Git-Commit-Best-Practices) for creating git commits. 25 | 26 | When your code is ready to be submitted, you can [submit a pull request](https://help.github.com/articles/creating-a-pull-request/) to begin the code review process. 27 | -------------------------------------------------------------------------------- /ironic_secureboot_driver/tests/test_driver.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018, Oath Inc 2 | # Licensed under the terms of the Apache 2.0 license. See LICENSE file in 3 | # https://github.com/yahoo/ironic-secureboot-driver 4 | 5 | from ironic.common import exception as ironic_exc 6 | from ironic.conductor import task_manager 7 | from ironic.drivers.modules import pxe 8 | from ironic.tests.unit.db import base as ironic_base 9 | from ironic.tests.unit.objects import utils as ironic_obj_utils 10 | 11 | from ironic_secureboot_driver import driver 12 | from ironic_secureboot_driver.tests import base 13 | 14 | 15 | def setup_configs(self): 16 | self.config(enabled_hardware_types='secureboot_ipmi') 17 | self.config(enabled_boot_interfaces='secureboot') 18 | self.config(enabled_deploy_interfaces='ramdisk') 19 | self.config(enabled_management_interfaces='ipmitool') 20 | self.config(enabled_power_interfaces='ipmitool') 21 | 22 | 23 | class TestHardwareType(base.TestCase): 24 | 25 | def setUp(self): 26 | super(TestHardwareType, self).setUp() 27 | self.ht = driver.SecurebootIPMIHardware() 28 | 29 | def test_supported_boot_interfaces(self): 30 | expected = [driver.Secureboot] 31 | self.assertEqual(expected, self.ht.supported_boot_interfaces) 32 | 33 | def test_supported_deploy_interfaces(self): 34 | expected = [pxe.PXERamdiskDeploy] 35 | self.assertEqual(expected, self.ht.supported_deploy_interfaces) 36 | 37 | 38 | class TestBootInterface(ironic_base.DbTestCase): 39 | def setUp(self): 40 | super(TestBootInterface, self).setUp() 41 | setup_configs(self) 42 | node = { 43 | 'driver': 'secureboot_ipmi', 44 | 'deploy_interface': 'ramdisk', 45 | 'boot_interface': 'secureboot', 46 | } 47 | self.node = ironic_obj_utils.create_test_node(self.context, **node) 48 | 49 | def test_validate_success(self): 50 | with task_manager.acquire(self.context, self.node.uuid) as task: 51 | task.node.driver_info = { 52 | 'secureboot_key': 'PEM-wrapped key data', 53 | 'secureboot_key_dat': 'encrypted key data', 54 | 'secureboot_certificate': 'cert data' 55 | } 56 | task.driver.boot.validate(task) 57 | 58 | def test_validate_no_key(self): 59 | with task_manager.acquire(self.context, self.node.uuid) as task: 60 | task.node.driver_info = { 61 | 'secureboot_key_dat': 'encrypted key data', 62 | 'secureboot_certificate': 'cert data' 63 | } 64 | self.assertRaises(ironic_exc.MissingParameterValue, 65 | task.driver.boot.validate, task) 66 | 67 | def test_validate_no_key_dat(self): 68 | with task_manager.acquire(self.context, self.node.uuid) as task: 69 | task.node.driver_info = { 70 | 'secureboot_key': 'PEM-wrapped key data', 71 | 'secureboot_certificate': 'cert data' 72 | } 73 | self.assertRaises(ironic_exc.MissingParameterValue, 74 | task.driver.boot.validate, task) 75 | 76 | def test_validate_no_cert(self): 77 | with task_manager.acquire(self.context, self.node.uuid) as task: 78 | task.node.driver_info = { 79 | 'secureboot_key': 'PEM-wrapped key data', 80 | 'secureboot_key_dat': 'encrypted key data', 81 | } 82 | self.assertRaises(ironic_exc.MissingParameterValue, 83 | task.driver.boot.validate, task) 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ARCHIVED 2 | 3 | 4 | # ironic-secureboot-driver 5 | 6 | > An Ironic plugin to provide a boot driver and hardware type for secureboot 7 | deployments. 8 | 9 | ## Background 10 | 11 | Oath needs to securely boot hardware in locations all around the world. To do this we 12 | use GRUB with iPXE that is verified via registers in the TPM; this has access 13 | to a secure key that's accessible only when the system configuration and boot 14 | components match the sealed values. iPXE will fetch an encrypted key and 15 | certificate; if the proper registers are set, the key can be unencrypted with 16 | the secure key. The key and certificate are then used for mutual TLS 17 | authentication to a trusted server that provides a bootable image. This image can be 18 | booted as a ramdisk, and iPXE will chainload to this image. 19 | 20 | This driver provides a boot interface that works in tandem with the 'ramdisk' 21 | deploy interface to skip the agent ramdisk process and boot directly to the 22 | instance. It does this by booting to disk and laying down files for the image server to 23 | provide to the baremetal nodes. 24 | 25 | ## Install 26 | 27 | Install with pip into the virtualenv or system where ironic is installed: 28 | 29 | $ git clone git@github.com:yahoo/ironic-secureboot-driver 30 | $ pip install ironic-secureboot-driver 31 | 32 | This driver also requires a web server on the same host as the conductor. The 33 | host should serve from `$httpboot/insecure` without mutual TLS auth, and 34 | from `$httpboot/secure` with mutual TLS auth, where `$httpboot` is configured 35 | in ironic at `[deploy]/http_root`. 36 | 37 | Images should be placed in `/images`, and are reference in the nodes' 38 | `instance_info` field relative to that location. 39 | 40 | ## Usage 41 | 42 | Enable the hardware type and interfaces in ironic.conf: 43 | 44 | enabled_boot_interfaces = pxe,secureboot 45 | enabled_hardware_types = ipmi,secureboot_ipmi 46 | enabled_deploy_interfaces = direct,ramdisk 47 | 48 | Restart ironic to pick up the config changes. 49 | 50 | Register a node using the right interfaces and hardware type: 51 | 52 | $ openstack baremetal node create \ 53 | --driver secureboot_ipmi \ 54 | --boot-interface secureboot \ 55 | --deploy-interface ramdisk 56 | 57 | Set the certificate and key data on the node: 58 | 59 | $ openstack baremetal node set \ 60 | --driver-info secureboot_key=$(cat $uuid.key) \ 61 | --driver-info secureboot_key_dat=$(base64 -w 0 $uuid.key.dat) \ 62 | --driver-info secureboot_certificate=$(cat $uuid.cert) \ 63 | $uuid 64 | 65 | Note that generating the keys and certificates is up to the user, as the 66 | encryption and boot process may be different between deployments. In general: 67 | 68 | * $uuid.key is a PEM-wrapped encrypted private key for the node 69 | * $uuid.key.dat is an encrypted blob of the private key for the node 70 | * $uuid.cert is the client certificate for the node 71 | 72 | Set the image info for the deployment: 73 | 74 | $ openstack baremetal node set \ 75 | --instance-info kernel=vmlinuz-ramdisk-ssh \ 76 | --instance-info ramdisk=initrd-ramdisk-ssh.img \ 77 | --instance-info squash=squashfs-ramdisk-ssh.img \ 78 | $uuid 79 | 80 | And finally, deploy the node: 81 | 82 | $ openstack baremetal node deploy $uuid 83 | 84 | ## Contribute 85 | 86 | * Free software: Apache license 87 | * Source: https://github.com/yahoo/ironic-secureboot-driver 88 | * Bugs: https://github.com/yahoo/ironic-secureboot-driver/issues 89 | 90 | Please refer to [the contributing.md file](Contributing.md) for information 91 | about how to get involved. We welcome issues, questions, and pull requests. 92 | Please be sure to follow our [code of conduct](Code-of-Conduct.md). 93 | 94 | ## License 95 | 96 | Copyright 2018 Oath Inc. 97 | 98 | This project is licensed under the terms of the Apache 2.0 open source license. 99 | Please refer to [LICENSE](LICENSE) for the full terms. 100 | -------------------------------------------------------------------------------- /Code-of-Conduct.md: -------------------------------------------------------------------------------- 1 | # Oath Open Source Code of Conduct 2 | 3 | ## Summary 4 | This Code of Conduct is our way to encourage good behavior and discourage bad behavior in our open source community. We invite participation from many people to bring different perspectives to support this project. We pledge to do our part to foster a welcoming and professional environment free of harassment. We expect participants to communicate professionally and thoughtfully during their involvement with this project. 5 | 6 | Participants may lose their good standing by engaging in misconduct. For example: insulting, threatening, or conveying unwelcome sexual content. We ask participants who observe conduct issues to report the incident directly to the project's Response Team at opensource-conduct@oath.com. Oath will assign a respondent to address the issue. We may remove harassers from this project. 7 | 8 | This code does not replace the terms of service or acceptable use policies of the websites used to support this project. We acknowledge that participants may be subject to additional conduct terms based on their employment which may govern their online expressions. 9 | 10 | ## Details 11 | This Code of Conduct makes our expectations of participants in this community explicit. 12 | * We forbid harassment and abusive speech within this community. 13 | * We request participants to report misconduct to the project’s Response Team. 14 | * We urge participants to refrain from using discussion forums to play out a fight. 15 | 16 | ### Expected Behaviors 17 | We expect participants in this community to conduct themselves professionally. Since our primary mode of communication is text on an online forum (e.g. issues, pull requests, comments, emails, or chats) devoid of vocal tone, gestures, or other context that is often vital to understanding, it is important that participants are attentive to their interaction style. 18 | 19 | * **Assume positive intent.** We ask community members to assume positive intent on the part of other people’s communications. We may disagree on details, but we expect all suggestions to be supportive of the community goals. 20 | * **Respect participants.** We expect participants will occasionally disagree. Even if we reject an idea, we welcome everyone’s participation. Open Source projects are learning experiences. Ask, explore, challenge, and then respectfully assert if you agree or disagree. If your idea is rejected, be more persuasive not bitter. 21 | * **Welcoming to new members.** New members bring new perspectives. Some may raise questions that have been addressed before. Kindly point them to existing discussions. Everyone is new to every project once. 22 | * **Be kind to beginners.** Beginners use open source projects to get experience. They might not be talented coders yet, and projects should not accept poor quality code. But we were all beginners once, and we need to engage kindly. 23 | * **Consider your impact on others.** Your work will be used by others, and you depend on the work of others. We expect community members to be considerate and establish a balance their self-interest with communal interest. 24 | * **Use words carefully.** We may not understand intent when you say something ironic. Poe’s Law suggests that without an emoticon people will misinterpret sarcasm. We ask community members to communicate plainly. 25 | * **Leave with class.** When you wish to resign from participating in this project for any reason, you are free to fork the code and create a competitive project. Open Source explicitly allows this. Your exit should not be dramatic or bitter. 26 | 27 | ### Unacceptable Behaviors 28 | Participants remain in good standing when they do not engage in misconduct or harassment. To elaborate: 29 | * **Don't be a bigot.** Calling out project members by their identity or background in a negative or insulting manner. This includes, but is not limited to, slurs or insinuations related to protected or suspect classes e.g. race, color, citizenship, national origin, political belief, religion, sexual orientation, gender identity and expression, age, size, culture, ethnicity, genetic features, language, profession, national minority statue, mental or physical ability. 30 | * **Don't insult.** Insulting remarks about a person’s lifestyle practices. 31 | * **Don't dox.** Revealing private information about other participants without explicit permission. 32 | * **Don't intimidate.** Threats of violence or intimidation of any project member. 33 | * **Don't creep.** Unwanted sexual attention or content unsuited for the subject of this project. 34 | * **Don't disrupt.** Sustained disruptions in a discussion. 35 | * **Let us help.** Refusal to assist the Response Team to resolve an issue in the community. 36 | 37 | We do not list all forms of harassment, nor imply some forms of harassment are not worthy of action. Any participant who *feels* harassed or *observes* harassment, should report the incident. Victim of harassment should not address grievances in the public forum, as this often intensifies the problem. Report it, and let us address it off-line. 38 | 39 | ### Reporting Issues 40 | If you experience or witness misconduct, or have any other concerns about the conduct of members of this project, please report it by contacting our Response Team at opensource-conduct@oath.com who will handle your report with discretion. Your report should include: 41 | * Your preferred contact information. We cannot process anonymous reports. 42 | * Names (real or usernames) of those involved in the incident. 43 | * Your account of what occurred, and if the incident is ongoing. Please provide links to or transcripts of the publicly available records (e.g. a mailing list archive or a public IRC logger), so that we can review it. 44 | * Any additional information that may be helpful to achieve resolution. 45 | 46 | After filing a report, a representative will contact you directly to review the incident and ask additional questions. If a member of the Oath Response Team is named in an incident report, that member will be recused from handling your incident. If the complaint originates from a member of the Response Team, it will be addressed by a different member of the Response Team. We will consider reports to be confidential for the purpose of protecting victims of abuse. 47 | 48 | ### Scope 49 | Oath will assign a Response Team member with admin rights on the project and legal rights on the project copyright. The Response Team is empowered to restrict some privileges to the project as needed. Since this project is governed by an open source license, any participant may fork the code under the terms of the project license. The Response Team’s goal is to preserve the project if possible, and will restrict or remove participation from those who disrupt the project. 50 | 51 | This code does not replace the terms of service or acceptable use policies that are provided by the websites used to support this community. Nor does this code apply to communications or actions that take place outside of the context of this community. Many participants in this project are also subject to codes of conduct based on their employment. This code is a social-contract that informs participants of our social expectations. It is not a terms of service or legal contract. 52 | 53 | ## License and Acknowledgment. 54 | This text is shared under the [CC-BY-4.0 license](https://creativecommons.org/licenses/by/4.0/). This code is based on a study conducted by the [TODO Group](https://todogroup.org/) of many codes used in the open source community. If you have feedback about this code, contact our Response Team at the address listed above. 55 | -------------------------------------------------------------------------------- /ironic_secureboot_driver/driver.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018, Oath Inc 2 | # Licensed under the terms of the Apache 2.0 license. See LICENSE file in 3 | # https://github.com/yahoo/ironic-secureboot-driver 4 | 5 | import base64 6 | import json 7 | import os 8 | 9 | from oslo_utils import fileutils 10 | import requests 11 | 12 | from ironic.common import boot_devices 13 | from ironic.common import exception as ironic_exc 14 | from ironic.common import states 15 | from ironic.common import utils 16 | from ironic.conductor import utils as manager_utils 17 | from ironic.conf import CONF 18 | from ironic.drivers import base 19 | from ironic.drivers import ipmi 20 | from ironic.drivers.modules import pxe 21 | from ironic.drivers.modules import iscsi_deploy 22 | 23 | 24 | class SecurebootIPMIHardware(ipmi.IPMIHardware): 25 | @property 26 | def supported_boot_interfaces(self): 27 | return [Secureboot, pxe.PXEBoot] 28 | 29 | @property 30 | def supported_deploy_interfaces(self): 31 | return [pxe.PXERamdiskDeploy, iscsi_deploy.ISCSIDeploy] 32 | 33 | @property 34 | def supported_power_interfaces(self): 35 | interfaces = super(SecurebootIPMIHardware, 36 | self).supported_power_interfaces 37 | return interfaces + [HttpmiPower] 38 | 39 | @property 40 | def supported_management_interfaces(self): 41 | interfaces = super(SecurebootIPMIHardware, 42 | self).supported_management_interfaces 43 | return interfaces + [HttpmiManagement] 44 | 45 | 46 | SECUREBOOT_PROPERTIES = { 47 | 'secureboot_key': ('PEM-wrapped encrypted private key for mutual TLS ' 48 | 'authentication to image server. Required.'), 49 | 'secureboot_key_dat': ('Encrypted private key for mutual TLS ' 50 | 'authentication to image server, ' 51 | 'base64-encoded. Required.'), 52 | 'secureboot_certificate': ('Client certificate for mutual TLS ' 53 | 'authentication to image server. Required.'), 54 | } 55 | 56 | 57 | # TODO(jroll) make this a config? 58 | IMAGES_PATH = '/images' 59 | 60 | 61 | def _secure_http_root(node_uuid): 62 | return os.path.join( 63 | CONF.deploy.http_root, 64 | 'secure', 65 | node_uuid) 66 | 67 | 68 | def _insecure_http_root(node_uuid): 69 | return os.path.join( 70 | CONF.deploy.http_root, 71 | 'insecure', 72 | node_uuid) 73 | 74 | 75 | def _link_images(node): 76 | http_root = _secure_http_root(node.uuid) 77 | fileutils.ensure_tree(http_root) 78 | for key in ('kernel', 'ramdisk', 'squash'): 79 | source = os.path.join(IMAGES_PATH, 80 | node.instance_info[key]) 81 | image_dest = os.path.join(http_root, key) 82 | os.symlink(source, image_dest) 83 | 84 | 85 | def _write_key_and_cert(node): 86 | http_root = _insecure_http_root(node.uuid) 87 | fileutils.ensure_tree(http_root) 88 | 89 | def _write(data, filename): 90 | dest = os.path.join(http_root, filename) 91 | with open(dest, 'wb') as f: 92 | f.write(data) 93 | 94 | _write(node.driver_info['secureboot_key'], 'key') 95 | _write(node.driver_info['secureboot_certificate'], 'certificate') 96 | key_data = base64.b64decode(node.driver_info['secureboot_key_dat']) 97 | _write(key_data, 'key.dat') 98 | 99 | 100 | class Secureboot(base.BootInterface): 101 | 102 | capabilities = ['ramdisk_boot'] 103 | 104 | def get_properties(self): 105 | return SECUREBOOT_PROPERTIES 106 | 107 | def validate(self, task): 108 | # TODO(jroll) validate we can put images in /httpboot? 109 | # validate image, kernel, ramdisk as UUID 110 | node = task.node 111 | 112 | missing_keys = [] 113 | for key in SECUREBOOT_PROPERTIES: 114 | if not node.driver_info.get(key): 115 | missing_keys.append(key) 116 | 117 | if missing_keys: 118 | raise ironic_exc.MissingParameterValue( 119 | 'Node %s is missing secureboot configuration data %s' % 120 | (node.uuid, missing_keys)) 121 | 122 | def prepare_ramdisk(self, task, ramdisk_params): 123 | # no ramdisk involved here 124 | pass 125 | 126 | def clean_up_ramdisk(self, task): 127 | # no ramdisk involved here 128 | pass 129 | 130 | def prepare_instance(self, task): 131 | # set boot dev to disk 132 | node = task.node 133 | 134 | # TODO(jroll) clean up if any of this fails? 135 | # or does ironic handle this? 136 | # TODO(jroll) do we want some way to be able to do this, 137 | # without needing the images in the right place on disk? 138 | # e.g. downloading from glance, etc 139 | _link_images(node) 140 | _write_key_and_cert(node) 141 | manager_utils.node_set_boot_device(task, boot_devices.DISK, 142 | persistent=True) 143 | 144 | def clean_up_instance(self, task): 145 | node = task.node 146 | 147 | # TODO(jroll) okay to not raise an exception here? 148 | utils.rmtree_without_raise(_insecure_http_root(node.uuid)) 149 | utils.rmtree_without_raise(_secure_http_root(node.uuid)) 150 | 151 | 152 | def _get_httpmi_credentials(node): 153 | driver_info = node.driver_info 154 | 155 | credentials = { 156 | 'user': driver_info['ipmi_username'], 157 | 'password': driver_info['ipmi_password'], 158 | 'bmc': driver_info['ipmi_address'], 159 | } 160 | 161 | port = driver_info.get('ipmi_port') 162 | if port: 163 | credentials['port'] = port 164 | 165 | return credentials 166 | 167 | 168 | def _call_httpmi(node, method, path, **kwargs): 169 | url = node.driver_info['httpmi_url'] 170 | url += path 171 | payload = _get_httpmi_credentials(node) 172 | payload.update(kwargs) 173 | res = getattr(requests, method)(url, data=payload) 174 | if res.status_code != 200: 175 | # TODO log some stuff here 176 | # TODO add some retries 177 | raise ironic_exc.IPMIFailure(cmd='httpmi call to to %(url)s ' 178 | 'with args %(kwargs)s' % { 179 | 'url': url, 'kwargs': kwargs}) 180 | return res.json() 181 | 182 | 183 | class HttpmiPower(base.PowerInterface): 184 | def get_properties(self): 185 | return {} 186 | 187 | def validate(self, task): 188 | pass 189 | 190 | def get_power_state(self, task): 191 | data = _call_httpmi(task.node, 'get', '/power') 192 | return data['state'] 193 | 194 | def set_power_state(self, task, power_state, timeout=None): 195 | _call_httpmi(task.node, 'post', '/power', state=power_state) 196 | 197 | def reboot(self, task, timeout=None): 198 | _call_httpmi(task.node, 'post', '/power', state=states.POWER_OFF) 199 | _call_httpmi(task.node, 'post', '/power', state=states.POWER_ON) 200 | 201 | 202 | class HttpmiManagement(base.ManagementInterface): 203 | def get_properties(self): 204 | return {} 205 | 206 | def validate(self, task): 207 | pass 208 | 209 | def get_supported_boot_devices(self, task): 210 | return [boot_devices.PXE, boot_devices.DISK] 211 | 212 | def set_boot_device(self, task, device, persistent=False): 213 | if device == boot_devices.DISK: 214 | device = 'hd' 215 | _call_httpmi(task.node, 'post', '/boot-device', device=device) 216 | 217 | def get_boot_device(self, task): 218 | res = _call_httpmi(task.node, 'get', '/boot-device') 219 | return res['device'] 220 | 221 | def get_sensors_data(self, task): 222 | return {} 223 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | --------------------------------------------------------------------------------