-
Notifications
You must be signed in to change notification settings - Fork 11
Feat: Support to accept the response of signing result from RADAS #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
e322b4e
07e43f3
42dbb01
89be82f
d4eee68
d2e86c9
75740e5
947f23c
da803dd
f784b16
83a92f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| """ | ||
|
|
||
| import logging | ||
| import os | ||
| from typing import Dict, List, Optional | ||
|
|
@@ -34,13 +35,20 @@ def __init__(self, data: Dict): | |
| self.__client_key: str = data.get("client_key", None) | ||
| self.__client_key_pass_file: str = data.get("client_key_pass_file", None) | ||
| self.__root_ca: str = data.get("root_ca", "/etc/pki/tls/certs/ca-bundle.crt") | ||
| self.__quay_radas_registry_config: str = data.get( | ||
| "quay_radas_registry_config", os.path.join(os.getenv("HOME", ""), ".oras/config.json") | ||
| ) | ||
| self.__radas_sign_timeout_retry_count: int = data.get("radas_sign_timeout_retry_count", 10) | ||
| self.__radas_sign_timeout_retry_interval: int = data.get( | ||
| "radas_sign_timeout_retry_interval", 60 | ||
| ) | ||
|
|
||
| def validate(self) -> bool: | ||
| if not self.__umb_host: | ||
| logger.error("Missing host name setting for UMB!") | ||
| return False | ||
| if not self.__result_queue: | ||
| logger.error("Missing the queue setting to receive siging result in UMB!") | ||
| logger.error("Missing the queue setting to receive signing result in UMB!") | ||
| return False | ||
| if not self.__request_queue: | ||
| logger.error("Missing the queue setting to send signing request in UMB!") | ||
|
|
@@ -57,10 +65,15 @@ def validate(self) -> bool: | |
| if self.__root_ca and not os.access(self.__root_ca, os.R_OK): | ||
| logger.error("The root ca file is not valid!") | ||
| return False | ||
| if self.__quay_radas_registry_config and not os.access( | ||
| self.__quay_radas_registry_config, os.R_OK | ||
| ): | ||
| logger.error("The quay registry config for oras is not valid!") | ||
| return False | ||
| return True | ||
|
|
||
| def umb_target(self) -> str: | ||
| return f'amqps://{self.__umb_host}:{self.__umb_host_port}' | ||
| return f"amqps://{self.__umb_host}:{self.__umb_host_port}" | ||
|
|
||
| def result_queue(self) -> str: | ||
| return self.__result_queue | ||
|
|
@@ -77,7 +90,7 @@ def client_key(self) -> str: | |
| def client_key_password(self) -> str: | ||
| pass_file = self.__client_key_pass_file | ||
| if os.access(pass_file, os.R_OK): | ||
| with open(pass_file, 'r') as f: | ||
| with open(pass_file, "r") as f: | ||
| return f.read() | ||
| elif pass_file: | ||
| logger.warning("The key password file is not accessible. Will ignore the password.") | ||
|
|
@@ -86,6 +99,15 @@ def client_key_password(self) -> str: | |
| def root_ca(self) -> str: | ||
| return self.__root_ca | ||
|
|
||
| def quay_radas_registry_config(self) -> str: | ||
| return self.__quay_radas_registry_config | ||
|
|
||
| def radas_sign_timeout_retry_count(self) -> int: | ||
| return self.__radas_sign_timeout_retry_count | ||
|
|
||
| def radas_sign_timeout_retry_interval(self) -> int: | ||
| return self.__radas_sign_timeout_retry_interval | ||
|
|
||
|
|
||
| class CharonConfig(object): | ||
| """CharonConfig is used to store all configurations for charon | ||
|
|
@@ -102,8 +124,10 @@ def __init__(self, data: Dict): | |
| self.__ignore_signature_suffix: Dict = data.get("ignore_signature_suffix", None) | ||
| self.__signature_command: str = data.get("detach_signature_command", None) | ||
| self.__aws_cf_enable: bool = data.get("aws_cf_enable", False) | ||
| self.__radas_config_enable: bool = data.get("radas_config_enable", False) | ||
|
||
| radas_config: Dict = data.get("radas", None) | ||
| if radas_config: | ||
| self.__radas_config_enable = True | ||
|
||
| self.__radas_config__: RadasConfig = RadasConfig(radas_config) | ||
|
|
||
| def get_ignore_patterns(self) -> List[str]: | ||
|
|
@@ -133,6 +157,9 @@ def get_detach_signature_command(self) -> str: | |
| def is_aws_cf_enable(self) -> bool: | ||
| return self.__aws_cf_enable | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking we should add a |
||
| def is_radas_config_enable(self) -> bool: | ||
| return self.__radas_config_enable | ||
|
||
|
|
||
| def get_radas_config(self) -> RadasConfig: | ||
| return self.__radas_config__ | ||
|
|
||
|
|
@@ -141,14 +168,12 @@ def get_config(cfgPath=None) -> CharonConfig: | |
| config_file_path = cfgPath | ||
| if not config_file_path or not os.path.isfile(config_file_path): | ||
| config_file_path = os.path.join(os.getenv("HOME", ""), ".charon", CONFIG_FILE) | ||
| data = read_yaml_from_file_path(config_file_path, 'schemas/charon.json') | ||
| data = read_yaml_from_file_path(config_file_path, "schemas/charon.json") | ||
| return CharonConfig(data) | ||
|
|
||
|
|
||
| def get_template(template_file: str) -> str: | ||
| template = os.path.join( | ||
| os.getenv("HOME", ''), ".charon/template", template_file | ||
| ) | ||
| template = os.path.join(os.getenv("HOME", ""), ".charon/template", template_file) | ||
| if os.path.isfile(template): | ||
| with open(template, encoding="utf-8") as file_: | ||
| return file_.read() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """ | ||
| Copyright (C) 2022 Red Hat, Inc. (https://github.com/Commonjava/charon) | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| """ | ||
|
|
||
| import oras.client | ||
| import logging | ||
| from charon.config import get_config | ||
| from typing import List | ||
| from urllib.parse import urlparse | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class OrasClient: | ||
| """ | ||
| Wrapper for oras‑py’s OrasClient, deciding whether to login based on config. | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| self.conf = get_config() | ||
| self.client = oras.client.OrasClient() | ||
|
|
||
| def login_if_needed(self, registry: str) -> None: | ||
| """ | ||
| If quay_radas_registry_config is provided, call login to authenticate. | ||
| """ | ||
| if not registry.startswith("http://") and not registry.startswith("https://"): | ||
| registry = "https://" + registry | ||
| registry = urlparse(registry).netloc | ||
|
|
||
| rconf = self.conf.get_radas_config() if self.conf else None | ||
| if rconf and rconf.quay_radas_registry_config(): | ||
| logger.info("Logging in to registry: %s", registry) | ||
| res = self.client.login( | ||
| hostname=registry, | ||
| config_path=rconf.quay_radas_registry_config(), | ||
| ) | ||
| logger.info(res) | ||
| else: | ||
| logger.info("Registry config is not provided, skip login.") | ||
|
|
||
| def pull(self, result_reference_url: str, sign_result_loc: str) -> List[str]: | ||
| """ | ||
| Call oras‑py’s pull method to pull the remote file to local. | ||
| Args: | ||
| result_reference_url (str): | ||
| Reference of the remote file (e.g. “quay.io/repository/signing/radas@hash”). | ||
| sign_result_loc (str): | ||
| Local save path (e.g. “/tmp/sign”). | ||
| """ | ||
| files = [] | ||
| try: | ||
| self.login_if_needed(registry=result_reference_url) | ||
| files = self.client.pull(target=result_reference_url, outdir=sign_result_loc) | ||
| logger.info("Pull file from %s to %s", result_reference_url, sign_result_loc) | ||
| except Exception as e: | ||
| logger.error( | ||
| "Failed to pull file from %s to %s: %s", result_reference_url, sign_result_loc, e | ||
| ) | ||
| return files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should not fail the radas config, but just give a warn message and leave this registry_config as None, which means we will consider it as a public registry without authentication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ligangty done, 947f23c