

# Git 동기화를 사용하여 스택을 Git 리포지토리에 동기화하기 위한 사전 요구 사항
<a name="git-sync-prereq"></a>

CloudFormation 스택을 Git 리포지토리에 동기화하기 전에 다음 요구 사항이 충족되는지 확인하세요.

**Topics**
+ [Git 리포지토리](#git-sync-prereq-repo)
+ [CloudFormation 템플릿](#git-sync-prereq-template)
+ [Git 동기화 서비스 역할](#git-sync-prereq-iam)
+ [콘솔 사용자의 IAM 권한](#git-sync-prereq-user-permissions)

## Git 리포지토리
<a name="git-sync-prereq-repo"></a>

다음 플랫폼 중 하나에 호스팅되는 Git 리포지토리가 있어야 합니다.
+ [GitHub](https://github.com/)
+ [GitHub Enterprise](https://github.com/enterprise)
+ [GitLab](https://about.gitlab.com/)
+ [Bitbucket](https://bitbucket.org)
+ [GitLab 자체 관리형](https://docs.gitlab.com/subscriptions/self_managed/)

리포지토리는 퍼블릭 또는 프라이빗일 수 있습니다. [Connections 콘솔](https://console.aws.amazon.com/codesuite/settings/connections)을 통해 Git 리포지토리를 CloudFormation에 연결해야 합니다.

## CloudFormation 템플릿
<a name="git-sync-prereq-template"></a>

Git 동기화와 연결하려는 브랜치에 체크인된 [CloudFormation 템플릿 파일](git-sync-concepts-terms.md#git-sync-concepts-terms-template-file)이 Git 리포지토리에 포함되어 있어야 합니다. 이 템플릿은 [스택 배포 파일](git-sync-concepts-terms.md#git-sync-concepts-terms-depoyment-file)에서 참조합니다.

## Git 동기화 서비스 역할
<a name="git-sync-prereq-iam"></a>

Git 동기화에는 IAM 역할이 필요합니다. Git 동기화를 구성할 때 스택에 대해 IAM 역할을 생성하도록 선택하거나 기존 역할을 사용할 수 있습니다.

**참고**  
자동으로 생성된 IAM 역할은 역할이 생성된 스택에만 권한을 적용합니다. 자동으로 생성된 IAM 역할을 재사용하려면 새 스택용으로 역할을 편집해야 합니다.

### Git 동기화 서비스 역할에 필요한 권한
<a name="git-sync-prereq-permissions"></a>

Git 동기화에 제공하는 IAM 역할에는 다음 권한이 필요합니다.
+ `cloudformation:CreateChangeSet`
+ `cloudformation:DeleteChangeSet`
+ `cloudformation:DescribeChangeSet`
+ `cloudformation:DescribeStackEvents`
+ `cloudformation:DescribeStacks`
+ `cloudformation:ExecuteChangeSet`
+ `cloudformation:ListChangeSets`
+ `cloudformation:ValidateTemplate`
+ `events:PutRule`
+ `events:PutTargets`

**참고**  
위의 필수 권한은 Git 동기화에서 생성하는 IAM 역할에 자동으로 추가됩니다.

다음 IAM 역할 예시에는 Git 동기화에 대한 사전 필수 권한이 포함되어 있습니다.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "SyncToCloudFormation",
            "Effect": "Allow",
            "Action": [
                "cloudformation:CreateChangeSet",
                "cloudformation:DeleteChangeSet",
                "cloudformation:DescribeChangeSet",
                "cloudformation:DescribeStackEvents",
                "cloudformation:DescribeStacks",
                "cloudformation:ExecuteChangeSet",
                "cloudformation:GetTemplate",
                "cloudformation:ListChangeSets",
                "cloudformation:ListStacks",
                "cloudformation:ValidateTemplate"
            ],
            "Resource": "*"
        },
        {
            "Sid": "PolicyForManagedRules",
            "Effect": "Allow",
            "Action": [
                "events:PutRule",
                "events:PutTargets"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                "events:ManagedBy": ["cloudformation.sync.codeconnections.amazonaws.com"]
                }
            }
        },
        {
            "Sid": "PolicyForDescribingRule",
            "Effect": "Allow",
            "Action": "events:DescribeRule",
            "Resource": "*"
        }
    ]
}
```

------

#### 신뢰 정책
<a name="git-sync-prereq-trust-policy"></a>

신뢰 관계를 정의하기 위해서는 역할을 생성할 때 다음과 같은 신뢰 정책을 제공해야 합니다.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "CfnGitSyncTrustPolicy",
      "Effect": "Allow",
      "Principal": {
        "Service": "cloudformation.sync.codeconnections.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
```

------

대리인 혼동 문제로부터 스스로를 보호하려면 `aws:SourceArn` 및 `aws:SourceAccount` 조건 키를 사용할 것을 권장합니다. 소스 계정은 계정 ID이고 소스 ARN은 CloudFormation이 Git 리포지토리에 연결할 수 있도록 허용하는 [CodeConnections](https://docs.aws.amazon.com/codeconnections/latest/APIReference/Welcome.html) 서비스 연결의 ARN입니다.

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "CfnGitSyncTrustPolicy",
      "Effect": "Allow",
      "Principal": {
        "Service": "cloudformation.sync.codeconnections.amazonaws.com"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": {
          "aws:SourceAccount": "123456789012"
        },
        "ArnLike": {
          "aws:SourceArn": "arn:aws:codeconnections:us-east-1:123456789012:connection/EXAMPLE64-8aad-4d5d-8878-dfcab0bc441f"
        }
      }
    }
  ]
}
```

------

혼동된 대리자 문제에 대한 자세한 내용은 [교차 서비스 혼동된 대리인 방지](cross-service-confused-deputy-prevention.md)를 참조하세요.

## 콘솔 사용자의 IAM 권한
<a name="git-sync-prereq-user-permissions"></a>

CloudFormation 콘솔을 통해 Git 동기화를 성공적으로 설정하려면 최종 사용자에게 IAM을 통한 권한도 부여해야 합니다.

Git 리포지토리에 대한 연결을 생성하고 관리하려면 다음 `codeconnections` 권한이 필요합니다.
+ `codeconnections:CreateRepositoryLink`
+ `codeconnections:CreateSyncConfiguration`
+ `codeconnections:DeleteRepositoryLink`
+ `codeconnections:DeleteSyncConfiguration`
+ `codeconnections:GetRepositoryLink`
+ `codeconnections:GetSyncConfiguration`
+ `codeconnections:ListRepositoryLinks`
+ `codeconnections:ListSyncConfigurations`
+ `codeconnections:ListTagsForResource`
+ `codeconnections:TagResource`
+ `codeconnections:UntagResource`
+ `codeconnections:UpdateRepositoryLink`
+ `codeconnections:UpdateSyncBlocker`
+ `codeconnections:UpdateSyncConfiguration`
+ `codeconnections:UseConnection`

또한 콘솔 사용자는 Git 동기화 설정 프로세스 중에 스택을 보고 관리할 수 있는 다음과 같은 `cloudformation` 권한이 있어야 합니다.
+ `cloudformation:CreateChangeSet`
+ `cloudformation:DeleteChangeSet`
+ `cloudformation:DescribeChangeSet`
+ `cloudformation:DescribeStackEvents`
+ `cloudformation:DescribeStacks`
+ `cloudformation:ExecuteChangeSet`
+ `cloudformation:GetTemplate`
+ `cloudformation:ListChangeSets`
+ `cloudformation:ListStacks`
+ `cloudformation:ValidateTemplate`

**참고**  
콘솔 전용 사용에 변경 세트 권한(`cloudformation:CreateChangeSet`, `cloudformation:DeleteChangeSet`, `cloudformation:DescribeChangeSet`, `cloudformation:ExecuteChangeSet`)이 반드시 필요한 것은 아니지만 전체 스택 검사 및 관리 기능을 활성화하는 것이 좋습니다.

다음 예제 IAM 정책에는 콘솔을 통해 Git 동기화를 설정하는 데 필요한 사용자 권한이 포함되어 있습니다.

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "CodeConnectionsPermissions",
            "Effect": "Allow",
            "Action": [
                "codeconnections:CreateRepositoryLink",
                "codeconnections:CreateSyncConfiguration",
                "codeconnections:DeleteRepositoryLink",
                "codeconnections:DeleteSyncConfiguration",
                "codeconnections:GetRepositoryLink",
                "codeconnections:GetSyncConfiguration",
                "codeconnections:ListRepositoryLinks",
                "codeconnections:ListSyncConfigurations",
                "codeconnections:ListTagsForResource",
                "codeconnections:TagResource",
                "codeconnections:UntagResource",
                "codeconnections:UpdateRepositoryLink",
                "codeconnections:UpdateSyncBlocker",
                "codeconnections:UpdateSyncConfiguration",
                "codeconnections:UseConnection",
                "codeconnections:CreateForcedTargetSync",
                "codeconnections:CreatePullRequestForResource"
            ],
            "Resource": "*"
        },
        {
            "Sid": "CloudFormationConsolePermissions",
            "Effect": "Allow",
            "Action": [
                "cloudformation:CreateChangeSet",
                "cloudformation:DeleteChangeSet",
                "cloudformation:DescribeChangeSet",
                "cloudformation:DescribeStackEvents",
                "cloudformation:DescribeStacks",
                "cloudformation:ExecuteChangeSet",
                "cloudformation:GetTemplate",
                "cloudformation:ListChangeSets",
                "cloudformation:ListStacks",
                "cloudformation:ValidateTemplate"
            ],
            "Resource": "*"
        }
    ]
}
```

------

**참고**  
`codeconnections:CreateForcedTargetSync` 및 `codeconnections:CreatePullRequestForResource` 권한이 포함된 IAM 정책을 생성할 때 IAM 콘솔에 이러한 작업이 존재하지 않는다는 경고가 표시될수 있습니다. 이 경고를 무시해도 정책이 성공적으로 생성됩니다. 이러한 권한은 IAM 콘솔에서 인식되지 않더라도 특정 Git 동기화 작업에 필요합니다.