Skip to content

Commit 18a2517

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 18a2517

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

services/artifacts/src/oci_cli_artifacts/artifacts_cli_extended.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from oci_cli.aliasing import CommandGroupWithAlias
1111
from oci_cli import custom_types # noqa: F401
1212

13+
1314
import re
1415
import json
1516
import base64
@@ -559,6 +560,7 @@ def list_container_images_extended(ctx, from_json, all_pages, page_size, compart
559560
@cli_util.option('--image-id', required=True, help=u"""The [OCID] of the container image.""")
560561
@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" """)
561562
@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\"}" """)
563+
@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'")
562564
@json_skeleton_utils.get_cli_json_input_option({})
563565
@cli_util.help_option
564566
@click.pass_context
@@ -567,7 +569,7 @@ def list_container_images_extended(ctx, from_json, all_pages, page_size, compart
567569
def sign_and_upload_container_image_signature_metadata(ctx, from_json, kms_key_id, kms_key_version_id,
568570
signing_algorithm,
569571
compartment_id, image_id,
570-
description, metadata):
572+
description, metadata, base_domain_overwrite):
571573
"""
572574
SignAndUploadContainerImageSignatureMetadata calls KMS to sign the message then calls OCIR to upload the returned signature
573575
@@ -583,6 +585,7 @@ def sign_and_upload_container_image_signature_metadata(ctx, from_json, kms_key_i
583585
:param image_id: The OCID of the container image. eg) ocid1.containerimage.oc1..exampleuniqueID. Max length: 255, Min length:1
584586
:param description: An user inputted message.
585587
:param metadata: An user defined information about the container image in JSON format eg) {"buildNumber":"123"}
588+
: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
586589
restriction:
587590
- should only contains alphanumeric key strings.
588591
- should be alphabetically sorted.
@@ -607,7 +610,7 @@ def sign_and_upload_container_image_signature_metadata(ctx, from_json, kms_key_i
607610
region_name = get_region_from_config(ctx)
608611

609612
# Create KMS client
610-
kms_crypto_client = build_vault_crypto_client(ctx, kms_key_id, region_name)
613+
kms_crypto_client = build_vault_crypto_client(ctx, kms_key_id, region_name, base_domain_overwrite)
611614

612615
# Get container image metadata
613616
click.echo("Obtaining container image metadata by the image ID")
@@ -741,13 +744,16 @@ def upload_signature_metadata(ctx, artifacts_client, compartment_id, image_id, k
741744

742745

743746
# Build the KmsCryptoClient based on the vault extension OCID in the keyId
744-
def build_vault_crypto_client(ctx, key_id, region):
747+
def build_vault_crypto_client(ctx, key_id, region, base_domain_overwrite):
745748
split_list = re.split("ocid1\\.key\\.([\\w-]+)\\.([\\w-]+)\\.([\\w-]+)\\.([\\w]){60}", key_id)
746749
if len(split_list) < 4:
747750
raise click.ClickException("Failed to split key ocid. Please check the kms_key_id is correct.")
748751
vault_ext = split_list[3]
749-
realm = oci.regions.REGION_REALMS.get(region)
750-
second_level_domain = oci.regions.REALMS[realm]
752+
if base_domain_overwrite is not None:
753+
second_level_domain = base_domain_overwrite
754+
else:
755+
realm = oci.regions.REGION_REALMS.get(region)
756+
second_level_domain = oci.regions.REALMS[realm]
751757
# region example: us-phoenix-1
752758
crypto_endpoint = "https://" + vault_ext + "-crypto.kms." + region + "." + second_level_domain
753759
ctx.obj['endpoint'] = crypto_endpoint
@@ -788,10 +794,10 @@ def filter_item_by_trusted_keys(items, trusted_keys):
788794
return ret
789795

790796

791-
def verify_signatures(ctx, container_image_signature_summary, region_name):
797+
def verify_signatures(ctx, container_image_signature_summary, region_name, base_domain_overwrite):
792798
verified = None
793799
for signature_summary in container_image_signature_summary:
794-
vault_crypto_client = build_vault_crypto_client(ctx, signature_summary.kms_key_id, region_name)
800+
vault_crypto_client = build_vault_crypto_client(ctx, signature_summary.kms_key_id, region_name, base_domain_overwrite)
795801
algo = signature_summary.signing_algorithm
796802
signing_algo_list = [
797803
"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)