Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions kiwi/runtime_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,37 @@ def get_disabled_runtime_checks(self):
)
return disabled_checks or ''

def get_custom_ca_cert(self):
"""
Returns a custom CA certificate to be injected to the chroot.
The value is certificate itself:

custom_certificates:
- ca: |
-----BEGIN CERTIFICATE-----
MIICGzCCAaGgAwIBAgIQQdKd0XLq7qeAwSxs6S+HUjAKBggqhkjOPQQDAzBPMQsw
CQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJuZXQgU2VjdXJpdHkgUmVzZWFyY2gg
R3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBYMjAeFw0yMDA5MDQwMDAwMDBaFw00
MDA5MTcxNjAwMDBaME8xCzAJBgNVBAYTAlVTMSkwJwYDVQQKEyBJbnRlcm5ldCBT
ZWN1cml0eSBSZXNlYXJjaCBHcm91cDEVMBMGA1UEAxMMSVNSRyBSb290IFgyMHYw
EAYHKoZIzj0CAQYFK4EEACIDYgAEzZvVn4CDCuwJSvMWSj5cz3es3mcFDR0HttwW
+1qLFNvicWDEukWVEYmO6gbf9yoWHKS5xcUy4APgHoIYOIvXRdgKam7mAHf7AlF9
ItgKbppbd9/w+kHsOdx1ymgHDB/qo0IwQDAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0T
AQH/BAUwAwEB/zAdBgNVHQ4EFgQUfEKWrt5LSDv6kviejM9ti6lyN5UwCgYIKoZI
zj0EAwMDaAAwZQIwe3lORlCEwkSHRhtFcP9Ymd70/aTSVaYgLXTWNLxBo1BfASdW
tL4ndQavEi51mI38AjEAi/V3bNTIZargCyzuFJ0nN6T5U6VR5CmD1/iQMVtCnwr1
/q4AaOeMSQ+2b1tbFfLn
-----END CERTIFICATE-----

:return: A certificate data

:rtype: str
"""
custom_ca = self._get_attribute(
element='custom_certificates', attribute='ca'
)
return custom_ca or None

def _get_attribute(self, element, attribute):
if RUNTIME_CONFIG:
try:
Expand Down
16 changes: 16 additions & 0 deletions kiwi/system/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,22 @@ def setup_plymouth_splash(self) -> None:
['chroot', self.root_dir, theme_setup, splash_theme]
)

def setup_ca_certificate(self, cacert: str) -> None:
"""
Setup CA certificate to the chroot and call update-ca-certificates

This is to be used when repositories in later stage require custom CA
certificate
"""
log.info('--> Setting up custom CA certificate')
ca_file_path = self.root_dir + '/etc/pki/trust/anchors/custom_ca.crt'
with open(ca_file_path, 'w') as cafile:
cafile.write(cacert)

Command.run(
['chroot', self.root_dir, 'update-ca-certificates']
)

def import_image_identifier(self) -> None:
"""
Create etc/ImageID identifier file
Expand Down
4 changes: 4 additions & 0 deletions kiwi/tasks/system_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ def process(self):
# call post_bootstrap.sh script if present
setup.call_post_bootstrap_script()

custom_ca = self.runtime_config.get_custom_ca_cert()
if custom_ca is not None:
setup.setup_ca_certificate(custom_ca)

system.install_system(
manager
)
Expand Down
Loading