Skip to content

Commit 7b491ee

Browse files
committed
Add --base-domain-overwrite option to container image signing functions
Dear OCI Team, When attempting to sign images using OCI CLI, the request times out as the URL returned by OCI CLI is incorrect. The correct URL is https://<redacted>-crypto.kms.me-riyadh-1.oci.oraclecloud.com but the one the OCI CLI attempts to use is https://<redacted>-crypto.kms.me-riyadh-1.oraclecloud.com without ".oci." - as a result the image signing fails. The command that is used to sign images with full administrative permissions is as follows: ``` oci artifacts container image-signature sign-upload --compartment-id ocid1.compartment.oc1...<redacted> --image-id ocid1.containerimage.oc1.me-riyadh-1.0.<redacted> --kms-key-id ocid1.key.oc1.me-riyadh-1.<redacted> --kms-key-version-id ocid1.keyversion.oc1.me-riyadh-1.<redacted> --signing-algorithm SHA_<redacted>_RSA_PKCS_PSS --debug ``` The error that is returned is as follows: File "<redacted>/site-packages/oci/base_client.py", line 694, in request raise exceptions.RequestException(e) oci.exceptions.RequestException: (MaxRetryError("OCIConnectionPool(host='<redacted>-crypto.kms.me-riyadh-1.oraclecloud.com', port=443): Max retries exceeded with url: /<redacted>/sign (Caused by NewConnectionError('< oci.base_client.OCIConnection object at 0x1123f34d0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))"), 'Request Endpoint: POST https://<redacted>-crypto.kms.me-riyadh-1.oraclecloud.com/<redacted>/sign See https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdk_troubleshooting.htm for help troubleshooting this error, or contact support and provide this full error message.') After further investigation and chat with kind OCI Support team, it became apparent that this issue is related to a change of endpoint format and may affect multiple regions including me-riyadh-1. The following is from comments in this repository: Please, accept this PR which will allow flexibility for overwriting the Cryptographic Endpoint to 'oraclecloud.com' or 'oci.oraclecloud.com' or 'oracleiaas.com' etc. as below: ``` oci artifacts container image-signature sign-upload .... --base-domain-overwrite oci.oraclecloud.com ```
1 parent 8aa0345 commit 7b491ee

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

services/artifacts/src/oci_cli_artifacts/artifacts_cli_extended.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ def list_container_images_extended(ctx, from_json, all_pages, page_size, compart
559559
@cli_util.option('--image-id', required=True, help=u"""The [OCID] of the container image.""")
560560
@cli_util.option('--description', help="""The optional text of your choice to describe the image. The description is included as part of the signature, and is shown in the Console. For example, --description "Image for UAT testing" """)
561561
@cli_util.option('--metadata', help="""The optional information of your choice about the image, in a valid JSON format (alphanumeric characters only, with no whitespace or escape characters). For example, --metadata "{\"buildNumber\":\"123\"}" """)
562+
@cli_util.option('--base-domain-overwrite', help="Overwrite the base domain for the Cryptographic Endpoint, e.g. to overwrite 'oraclecloud.com' with 'oci.oraclecloud.com'. Usage: --base-domain-overwrite 'oci.oraclecloud.com'")
562563
@json_skeleton_utils.get_cli_json_input_option({})
563564
@cli_util.help_option
564565
@click.pass_context
@@ -567,7 +568,7 @@ def list_container_images_extended(ctx, from_json, all_pages, page_size, compart
567568
def sign_and_upload_container_image_signature_metadata(ctx, from_json, kms_key_id, kms_key_version_id,
568569
signing_algorithm,
569570
compartment_id, image_id,
570-
description, metadata):
571+
description, metadata, base_domain_overwrite):
571572
"""
572573
SignAndUploadContainerImageSignatureMetadata calls KMS to sign the message then calls OCIR to upload the returned signature
573574
@@ -583,6 +584,7 @@ def sign_and_upload_container_image_signature_metadata(ctx, from_json, kms_key_i
583584
:param image_id: The OCID of the container image. eg) ocid1.containerimage.oc1..exampleuniqueID. Max length: 255, Min length:1
584585
:param description: An user inputted message.
585586
:param metadata: An user defined information about the container image in JSON format eg) {"buildNumber":"123"}
587+
:param base_domain_overwrite: Overwrite the base domain for the Cryptographic Endpoint. e.g. if the base domain is 'oraclecloud.com' instead of 'oci.oraclecloud.com' which happens in me-riyadh-1 and potentially other regions
586588
restriction:
587589
- should only contains alphanumeric key strings.
588590
- should be alphabetically sorted.
@@ -607,7 +609,7 @@ def sign_and_upload_container_image_signature_metadata(ctx, from_json, kms_key_i
607609
region_name = get_region_from_config(ctx)
608610

609611
# Create KMS client
610-
kms_crypto_client = build_vault_crypto_client(ctx, kms_key_id, region_name)
612+
kms_crypto_client = build_vault_crypto_client(ctx, kms_key_id, region_name, base_domain_overwrite)
611613

612614
# Get container image metadata
613615
click.echo("Obtaining container image metadata by the image ID")
@@ -741,13 +743,16 @@ def upload_signature_metadata(ctx, artifacts_client, compartment_id, image_id, k
741743

742744

743745
# Build the KmsCryptoClient based on the vault extension OCID in the keyId
744-
def build_vault_crypto_client(ctx, key_id, region):
746+
def build_vault_crypto_client(ctx, key_id, region, base_domain_overwrite):
745747
split_list = re.split("ocid1\\.key\\.([\\w-]+)\\.([\\w-]+)\\.([\\w-]+)\\.([\\w]){60}", key_id)
746748
if len(split_list) < 4:
747749
raise click.ClickException("Failed to split key ocid. Please check the kms_key_id is correct.")
748750
vault_ext = split_list[3]
749-
realm = oci.regions.REGION_REALMS.get(region)
750-
second_level_domain = oci.regions.REALMS[realm]
751+
if base_domain_overwrite is not None:
752+
second_level_domain = base_domain_overwrite
753+
else:
754+
realm = oci.regions.REGION_REALMS.get(region)
755+
second_level_domain = oci.regions.REALMS[realm]
751756
# region example: us-phoenix-1
752757
crypto_endpoint = "https://" + vault_ext + "-crypto.kms." + region + "." + second_level_domain
753758
ctx.obj['endpoint'] = crypto_endpoint
@@ -788,10 +793,10 @@ def filter_item_by_trusted_keys(items, trusted_keys):
788793
return ret
789794

790795

791-
def verify_signatures(ctx, container_image_signature_summary, region_name):
796+
def verify_signatures(ctx, container_image_signature_summary, region_name, base_domain_overwrite):
792797
verified = None
793798
for signature_summary in container_image_signature_summary:
794-
vault_crypto_client = build_vault_crypto_client(ctx, signature_summary.kms_key_id, region_name)
799+
vault_crypto_client = build_vault_crypto_client(ctx, signature_summary.kms_key_id, region_name, base_domain_overwrite)
795800
algo = signature_summary.signing_algorithm
796801
signing_algo_list = [
797802
"SHA_224_RSA_PKCS_PSS", "SHA_256_RSA_PKCS_PSS", "SHA_384_RSA_PKCS_PSS", "SHA_512_RSA_PKCS_PSS"

0 commit comments

Comments
 (0)