주:

AWS Secrets Manager에서 Oracle Cloud Infrastructure Secrets in Vault로 암호 마이그레이션

소개

AWS(Amazon Web Services)에서 OCI(Oracle Cloud Infrastructure)로 암호를 마이그레이션할 때의 이점:

OCI 저장소에서 지원되는 암호 유형

목표

필요 조건

AWS에서 OCI로 암호 마이그레이션

  1. AWS 암호를 검색하고 확인합니다. AWS에서 암호를 마이그레이션하려면 먼저 전송할 암호 목록이 있는지 확인하십시오. 이 예에서는 awssecret4awssecret5의 두 암호를 마이그레이션합니다.

    편집 버튼

    다음 스크린샷은 마이그레이션 전 AWS Secrets Manager의 암호를 보여줍니다.

    편집 버튼

    편집 버튼

  2. OCI에서 저장소 및 암호화 키를 생성합니다. 암호 암호 암호화를 위해 OCI 저장소 및 키를 설정하려면 Creating a Master Encryption Key를 참조하십시오.

    편집 버튼

    편집 버튼

  3. Python 스크립트를 사용하여 암호를 마이그레이션합니다. 다음 Python 스크립트를 다운로드하여 aws_to_oci_secret_migration.py으로 저장합니다. 이 스크립트는 AWS 암호를 검색하고 OCI Vault에 저장하는 프로세스를 자동화합니다.

    주: 위치 표시자(예: your_aws_secret1, your_aws_region, your_oci_vault_id 등)를 실제 값으로 바꿉니다. 지정된 접두어는 저장소에 암호를 만드는 데 사용되므로 스크립트를 사용하여 암호 만들기를 격리할 수 있습니다.

    Script:

    import boto3  # AWS SDK to interact with AWS services
    import oci  # OCI SDK to interact with Oracle Cloud
    import base64  # To handle base64 encoding
    from botocore.exceptions import ClientError  # For handling errors with AWS
    
    # AWS configuration
    AWS_SECRET_NAMES = ["your_aws_secret1", "your_aws_secret2"]  # List of AWS secrets to migrate
    AWS_REGION = "your_aws_region"  # AWS region where the secrets are stored
    
    # OCI configuration
    VAULT_ID = "your_oci_vault_id"  # OCI Vault ID
    COMPARTMENT_ID = "your_oci_compartment_id"  # OCI Compartment ID
    KEY_ID = "your_oci_key_id"  # OCI Key ID
    OCI_SECRET_NAME_PREFIX = "your_prefix"  # Prefix for the secret names in OCI Vault
    
    def get_aws_secret(secret_name):
        """Retrieve the secret value from AWS Secrets Manager."""
        session = boto3.session.Session()  # Create a session with AWS
        client = session.client(service_name='secretsmanager', region_name=AWS_REGION)  # Create a Secrets Manager client
    
        try:
            # Get the secret value
            get_secret_value_response = client.get_secret_value(SecretId=secret_name)
            secret = get_secret_value_response['SecretString']  # This is the actual secret data
            return secret
        except ClientError as e:
            print(f"Error retrieving secret from AWS: {e}")  # In case something goes wrong
            return None
    
    def create_oci_secret(secret_content, secret_name):
        """Create a new secret in OCI Vault."""
        config = oci.config.from_file()  # This loads your OCI configuration from ~/.oci/config
        vaults_client = oci.vault.VaultsClient(config)  # Use the VaultsClient to create a secret in OCI Vault
    
        # Encode secret content to Base64 format
        secret_content_base64 = base64.b64encode(secret_content.encode('utf-8')).decode('utf-8')  # Proper base64 encoding
    
        try:
            # Creating a new secret in OCI Vault
            create_secret_response = vaults_client.create_secret(
                create_secret_details=oci.vault.models.CreateSecretDetails(
                    vault_id=VAULT_ID,
                    compartment_id=COMPARTMENT_ID,
                    secret_name=secret_name,
                    key_id=KEY_ID,
                    secret_content=oci.vault.models.Base64SecretContentDetails(
                        content=secret_content_base64,  # Base64 encoded content
                        content_type="BASE64"  # Specifying the content type as BASE64
                    ),
                    description="Migrated from AWS Secrets Manager"  # A brief description
                )
            )
            print(f"Secret '{secret_name}' successfully created in OCI Vault.")
        except oci.exceptions.ServiceError as e:
            print(f"Error creating secret in OCI Vault: {e}")  # If something goes wrong
    
    def main():
        # Step 1: Retrieve and migrate secrets from AWS Secrets Manager
        for aws_secret_name in AWS_SECRET_NAMES:
            aws_secret_content = get_aws_secret(aws_secret_name)
    
            if aws_secret_content:
                # Generate OCI secret name based on AWS secret name
                oci_secret_name = f"{OCI_SECRET_NAME_PREFIX}_{aws_secret_name}"
                # Step 2: Create the secret in OCI Vault
                create_oci_secret(aws_secret_content, oci_secret_name)
    
    if __name__ == "__main__":
        main()
    
  4. 스크립트를 저장한 후 다음 명령을 사용하여 실행합니다.

    python3 aws_to_oci_secret_migration.py
    

    편집 버튼

  5. 스크립트를 성공적으로 실행한 후 OCI Vault에서 새로 생성된 암호를 확인할 수 있습니다.

    편집 버튼

    편집 버튼

다음 단계

AWS에서 OCI로 비밀을 마이그레이션하면 특히 나머지 클라우드 인프라에 OCI를 활용하는 경우 운영을 간소화할 수 있습니다. Python 자동화를 사용하면 암호를 효율적으로 전송하여 안전하게 저장하고 OCI의 암호화 표준을 준수할 수 있습니다.

확인

추가 학습 자원

docs.oracle.com/learn에서 다른 실습을 탐색하거나 Oracle Learning YouTube 채널에서 더 많은 무료 학습 콘텐츠에 액세스하세요. 또한 Oracle Learning Explorer가 되려면 education.oracle.com/learning-explorer을 방문하십시오.

제품 설명서는 Oracle Help Center를 참조하십시오.