AWS CodeBuild 샌드박스 SSH 연결 문제 해결 - AWS CodeBuild

AWS CodeBuild 샌드박스 SSH 연결 문제 해결

이 주제의 정보를 활용하면 CodeBuild 샌드박스 SSH 연결 문제를 식별, 진단 및 해결하는 데 도움이 됩니다.

SSH가 CodeBuild 샌드박스 환경으로 전환될 때 StartSandboxConnectionInvalidInputException 오류 발생

문제: ssh codebuild-sandbox-ssh=<sandbox-arn> 명령을 사용하여 CodeBuild 샌드박스 환경에 연결하려고 하면 다음과 같은 InvalidInputException 오류가 발생할 수 있습니다.

An error occurred (InvalidInputException) when calling the StartSandboxConnection operation: Failed to start SSM session for {sandbox-arn} User: arn:aws:sts::<account-ID>:assumed-role/<service-role-name>/AWSCodeBuild-<UUID> is not authorized to perform: ssm:StartSession on resource.
An error occurred (InvalidInputException) when calling the StartSandboxConnection operation: Failed to start SSM session for sandbox <sandbox-arn>: codebuild:<UUID> is not connected.

가능한 원인:

  • Amazon EC2 Systems Manager Agent 누락: 빌드 이미지에 SSM 에이전트가 제대로 설치되거나 구성되지 않았습니다.

  • 권한 부족: CodeBuild 프로젝트 서비스 역할에 필요한 SSM 권한이 없습니다.

권장 솔루션: 빌드에 사용자 지정 이미지를 사용하는 경우 다음을 수행합니다.

  1. SSM Agent 설치 자세한 내용은 에서 Linux용 Amazon EC2 인스턴스에 수동으로 SSM Agent 설치 및 제거를 참조하세요. SSM Agent는 3.0.1295.0 이상 버전이어야 합니다.

  2. https://github.com/aws/aws-codebuild-docker-images/blob/master/ubuntu/standard/7.0/amazon-ssm-agent.json 파일을 이미지의 /etc/amazon/ssm/ 디렉터리에 복사합니다. 이렇게 하면 SSM Agent에서 컨테이너 모드가 활성화됩니다.

  3. CodeBuild 프로젝트의 서비스 역할에 다음 권한이 있는지 확인한 다음 샌드박스 환경을 다시 시작합니다.

    { "Effect": "Allow", "Action": [ "ssmmessages:CreateControlChannel", "ssmmessages:CreateDataChannel", "ssmmessages:OpenControlChannel", "ssmmessages:OpenDataChannel" ], "Resource": "*" }, { "Effect": "Allow", "Action": [ "ssm:StartSession" ], "Resource": [ "arn:aws:codebuild:region:account-id:build/*", "arn:aws:ssm:region::document/AWS-StartSSHSession" ] }

오류: SSH가 CodeBuild 샌드박스 환경으로 전환될 때 '자격 증명을 찾을 수 없음'

문제: ssh codebuild-sandbox-ssh=<sandbox-arn> 명령을 사용하여 CodeBuild 샌드박스 환경에 연결하려고 하면 다음과 같은 자격 증명 오류가 발생할 수 있습니다.

Unable to locate credentials. You can configure credentials by running "aws configure".

가능한 원인: 로컬 환경에서 AWS 자격 증명이 제대로 구성되지 않았습니다.

권장 솔루션: AWS 명령줄 인터페이스 사용 설명서 버전 2의 공식 문서: AWS CLI용 설정 구성을 따라 AWS CLI 자격 증명을 구성합니다.

SSH가 CodeBuild 샌드박스 환경으로 전환될 때 StartSandboxConnectionAccessDeniedException 오류 발생

문제: ssh codebuild-sandbox-ssh=<sandbox-arn> 명령을 사용하여 CodeBuild 샌드박스 환경에 연결하려고 하면 다음과 같은 권한 오류가 발생할 수 있습니다.

An error occurred (AccessDeniedException) when calling the StartSandboxConnection operation: User: arn:aws:sts::account-id:assumed-role/role-name is not authorized to perform: codebuild:StartSandboxConnection on resource: sandbox-arn because no identity-based policy allows the codebuild:StartSandboxConnection action

가능한 원인: AWS 자격 증명에 이 작업을 수행하는 데 필요한 CodeBuild 권한이 없습니다.

권장 솔루션: AWS CLI 자격 증명과 연결된 IAM 사용자 또는 역할에 다음 권한이 있는지 확인합니다.

{ "Effect": "Allow", "Action": [ "codebuild:StartSandboxConnection" ], "Resource": [ "arn:aws:codebuild:region:account-id:sandbox/*" ] }

오류: SSH가 CodeBuild 샌드박스 환경으로 전환될 때 'ssh: 호스트 이름을 확인할 수 없음'

문제: ssh codebuild-sandbox-ssh=<sandbox-arn> 명령을 사용하여 CodeBuild 샌드박스 환경에 연결하려고 하면 다음과 같은 호스트 이름 확인 오류가 발생합니다.

ssh: Could not resolve hostname

가능한 원인: 이 오류는 일반적으로 로컬 환경에서 필요한 CodeBuild 샌드박스 연결 스크립트가 제대로 실행되지 않은 경우에 발생합니다.

권장 솔루션

  1. CodeBuild 샌드박스 연결 스크립트를 다운로드합니다.

  2. 터미널에서 스크립트를 실행하여 필요한 SSH 구성을 설정합니다.

  3. 샌드박스 환경에 대한 SSH 연결을 다시 시도합니다.