-
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e322b4e
Feat: Support to accept the response of signing result from RADAS
yma955 07e43f3
Format Code and fix typo
yma955 42dbb01
Rename radas_sign_timeout_retry_count and radas_sign_timeout_retry_in…
yma955 89be82f
Use oras registry_config and registry url parse to finalize login
yma955 d4eee68
Change sign_result_loc to cmd flag both for sign request and maven up…
yma955 d2e86c9
Update quay_radas_registry_config to default None since it's not nece…
yma955 75740e5
Use radas_config validate instead of is_radas_config_enable option
yma955 947f23c
Ignore the registry config if the provided config path is not valid t…
yma955 da803dd
Add is_radas_enabled unified method to check radas enablement
yma955 f784b16
Change on_message process method without using threads
yma955 83a92f9
Remove timeout retry handling for sign result fetch from maven upload
yma955 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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,18 @@ 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", None) | ||
| 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 +63,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 +88,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 +97,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,9 +122,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__: Optional[RadasConfig] = None | ||
| radas_config: Dict = data.get("radas", None) | ||
| if radas_config: | ||
| self.__radas_config__: RadasConfig = RadasConfig(radas_config) | ||
| self.__radas_config__ = RadasConfig(radas_config) | ||
|
|
||
| def get_ignore_patterns(self) -> List[str]: | ||
| return self.__ignore_patterns | ||
|
|
@@ -133,22 +154,20 @@ 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 get_radas_config(self) -> RadasConfig: | ||
| def get_radas_config(self) -> Optional[RadasConfig]: | ||
| return self.__radas_config__ | ||
|
|
||
|
|
||
| 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() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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