명시적 프록시 서버에서 CodeBuild 실행 - AWS CodeBuild

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

명시적 프록시 서버에서 CodeBuild 실행

명시적 프록시 서버에서 AWS CodeBuild를 실행하려면 프록시 서버가 외부 사이트와의 트래픽을 허용 또는 거부하도록 구성한 다음, HTTP_PROXYHTTPS_PROXY 환경 변수를 구성해야 합니다.

Squid를 명시적 프록시 서버로 구성

Squid를 명시적 프록시 서버로 구성하려면 다음과 같이 /etc/squid/squid.conf 파일을 수정해야 합니다.

  • 다음 기본 ACL(액세스 제어 목록) 규칙을 제거합니다.

    acl localnet src 10.0.0.0/8 acl localnet src 172.16.0.0/12 acl localnet src 192.168.0.0/16 acl localnet src fc00::/7 acl localnet src fe80::/10

    제거한 기본 ACL 규칙 대신 다음 규칙을 추가합니다. 첫 번째 줄은 VPC의 요청을 허용합니다. 다음 두 줄은 프록시 서버에 AWS CodeBuild가 사용할 수 있는 대상 URL에 대한 액세스 권한을 부여합니다. 마지막 줄의 정규식을 편집하여 AWS 리전의 S3 버킷 또는 CodeCommit 리포지토리를 지정합니다. 예:

    • 소스가 Amazon S3일 경우 acl download_src dstdom_regex .*s3\.us-west-1\.amazonaws\.com 명령을 사용하여 us-west-1 리전 내 S3 버킷에 대한 액세스 권한을 부여합니다.

    • 소스가 AWS CodeCommit인 경우 git-codecommit.<your-region>.amazonaws.com을 사용하여 허용 목록에 AWS 리전을 추가합니다.

    acl localnet src 10.1.0.0/16 #Only allow requests from within the VPC acl allowed_sites dstdomain .github.com #Allows to download source from GitHub acl allowed_sites dstdomain .bitbucket.com #Allows to download source from Bitbucket acl download_src dstdom_regex .*\.amazonaws\.com #Allows to download source from Amazon S3 or CodeCommit
  • http_access allow localnet을 다음으로 바꿉니다.

    http_access allow localnet allowed_sites http_access allow localnet download_src
  • 빌드가 로그 및 아티팩트를 업로드하도록 하려면 다음 중 하나를 수행하십시오.

    1. http_access deny all 문 앞에 다음 문을 삽입합니다. 이를 통해 CodeBuild는 CloudWatch와 Amazon S3에 액세스할 수 있습니다. CodeBuild에서 CloudWatch Logs를 생성하려면 CloudWatch에 대한 액세스 권한이 필요합니다. Amazon S3에 대한 액세스는 아티팩트 및 Amazon S3 캐싱을 업로드하기 위해 필요합니다.

      • https_port 3130 cert=/etc/squid/ssl/squid.pem ssl-bump intercept acl SSL_port port 443 http_access allow SSL_port acl allowed_https_sites ssl::server_name .amazonaws.com acl step1 at_step SslBump1 acl step2 at_step SslBump2 acl step3 at_step SslBump3 ssl_bump peek step1 all ssl_bump peek step2 allowed_https_sites ssl_bump splice step3 allowed_https_sites ssl_bump terminate step2 all
      • squid.conf를 저장한 후 다음 명령을 실행합니다.

        sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 3130 sudo service squid restart
    2. buildspec 파일에 proxy를 추가합니다. 자세한 내용은 buildspec 구문 단원을 참조하십시오.

      version: 0.2 proxy: upload-artifacts: yes logs: yes phases: build: commands: - command
참고

RequestError 시간 초과 오류가 발생할 경우 프록시 서버에서 CodeBuild를 실행할 때 RequestError 시간 초과 오류 단원을 참조하십시오.

자세한 내용은 본 주제의 후반부에서 명시적 프록시 서버 샘플 squid.conf 파일을 참조하세요.

CodeBuild 프로젝트 생성

명시적 프록시 서버에서 AWS CodeBuild를 실행하려면 프로젝트 수준에서 HTTP_PROXYHTTPS_PROXY 환경 변수를 프록시 서버용으로 생성한 EC2 인스턴스의 프라이빗 IP 주소와 포트 3128로 설정합니다. 프라이빗 IP 주소는 http://your-ec2-private-ip-address:3128과 비슷합니다. 자세한 내용은 에서 빌드 프로젝트 생성 AWS CodeBuild에서 빌드 프로젝트 설정 변경 AWS CodeBuild 단원을 참조하세요.

다음 명령을 사용하여 Squid 프록시 액세스 로그를 확인합니다.

sudo tail -f /var/log/squid/access.log

명시적 프록시 서버 샘플 squid.conf 파일

다음은 명시적 프록시 서버용으로 구성된 squid.conf 파일의 예입니다.

acl localnet src 10.0.0.0/16 #Only allow requests from within the VPC # add all URLS to be whitelisted for download source and commands to be run in build environment acl allowed_sites dstdomain .github.com #Allows to download source from github acl allowed_sites dstdomain .bitbucket.com #Allows to download source from bitbucket acl allowed_sites dstdomain ppa.launchpad.net #Allows to run apt-get in build environment acl download_src dstdom_regex .*\.amazonaws\.com #Allows to download source from S3 or CodeCommit acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl Safe_ports port 70 # gopher acl Safe_ports port 210 # wais acl Safe_ports port 1025-65535 # unregistered ports acl Safe_ports port 280 # http-mgmt acl Safe_ports port 488 # gss-http acl Safe_ports port 591 # filemaker acl Safe_ports port 777 # multiling http acl CONNECT method CONNECT # # Recommended minimum Access Permission configuration: # # Deny requests to certain unsafe ports http_access deny !Safe_ports # Deny CONNECT to other than secure SSL ports http_access deny CONNECT !SSL_ports # Only allow cachemgr access from localhost http_access allow localhost manager http_access deny manager # We strongly recommend the following be uncommented to protect innocent # web applications running on the proxy server who think the only # one who can access services on "localhost" is a local user #http_access deny to_localhost # # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS # # Example rule allowing access from your local networks. # Adapt localnet in the ACL section to list your (internal) IP networks # from where browsing should be allowed http_access allow localnet allowed_sites http_access allow localnet download_src http_access allow localhost # Add this for CodeBuild to access CWL end point, caching and upload artifacts S3 bucket end point https_port 3130 cert=/etc/squid/ssl/squid.pem ssl-bump intercept acl SSL_port port 443 http_access allow SSL_port acl allowed_https_sites ssl::server_name .amazonaws.com acl step1 at_step SslBump1 acl step2 at_step SslBump2 acl step3 at_step SslBump3 ssl_bump peek step1 all ssl_bump peek step2 allowed_https_sites ssl_bump splice step3 allowed_https_sites ssl_bump terminate step2 all # And finally deny all other access to this proxy http_access deny all # Squid normally listens to port 3128 http_port 3128 # Uncomment and adjust the following to add a disk cache directory. #cache_dir ufs /var/spool/squid 100 16 256 # Leave coredumps in the first cache dir coredump_dir /var/spool/squid # # Add any of your own refresh_pattern entries above these. # refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 refresh_pattern . 0 20% 4320