액세스 제어
Control access to Unity Gaming Services by creating rules to restrict service APIs.
읽는 시간 2분최근 업데이트: 12시간 전
액세스 제어 서비스를 통해 Cloud Code를 비롯한 Unity Gaming Services(UGS)에 대한 액세스를 제어할 수 있습니다. 액세스 제어를 사용하면 서비스 API에 대한 플레이어의 액세스를 제한하는 규칙을 만들 수 있습니다.
Cloud Code 모듈에 대한 플레이어 액세스를 제어하는 예시
아래 예시에서는 Cloud Code 서비스 API에 대한 액세스를 거부하는 프로젝트 기반 정책을 생성하는 방법을 보여 줍니다. Cloud Code C# 모듈을 트리거에 연결하면 플레이어의 직접 요청을 거부하는 동시에 게임의 보안을 강화할 수 있습니다. UGS CLI 툴을 사용하여 액세스 정책을 생성할 수 있습니다.필수 조건
먼저, 필수 액세스 역할로 서비스 계정을 생성하고 UGS CLI를 구성해야 합니다.서비스 계정을 사용하여 인증
Scheduling 및 Triggers 서비스를 호출하려면 먼저 서비스 계정을 사용하여 인증해야 합니다.- Unity Cloud Dashboard로 이동합니다.
- Administration > Service Accounts를 선택합니다.
- New 버튼을 선택하고 서비스 계정의 이름과 설명을 입력합니다.
- Create를 선택합니다.
- Manage product roles를 선택합니다.
- 다음 역할을 서비스 계정에 추가합니다.
- LiveOps 드롭다운에서 Triggers Configuration Editor, Triggers Configuration Viewer, Scheduler Configuration Editor, Scheduler Configuration Viewer를 선택합니다.
- Admin 드롭다운에서 Unity Environments Viewer, Project Resource Policy Editor, Project Resource Policy Reader를 선택합니다.
- Save를 선택합니다.
- Add Key를 선택합니다.
- base64 인코딩을 사용하여 Key ID와 Secret key를 인코딩합니다. 포맷은 ‘key_id:secret_key’입니다. 이 값을 기록해 둡니다.
UGS CLI 구성
다음 단계를 따라 UGS CLI를 시작합니다.- UGS CLI를 설치합니다.
-
다음을 사용하여 프로젝트 ID와 환경을 구성합니다.
ugs config set project-id <your-project-id>
ugs config set environment-name <your-environment-name> - 이전에 생성한 서비스 계정을 사용하여 인증합니다. 자세한 내용은 인증 받기를 참고하십시오.
모듈 엔드포인트 생성
프로젝트에서 연결된 모든 플레이어에게 메시지를 브로드캐스트하는 Cloud Code 모듈을 생성합니다. 자세한 내용은 푸시 메시지 전송을 참고하십시오.모듈을 배포합니다. 모듈을 배포하는 방법을 알아보려면 Hello World 배포를 참고하십시오.using Microsoft.Extensions.DependencyInjection;using Unity.Services.CloudCode.Core;using Unity.Services.CloudCode.Apis;namespace HelloWorld{ public class HelloWorld { [CloudCodeFunction("SendProjectMessage")] public async Task SendProjectMessage(IExecutionContext context, PushClient pushClient, string message, string messageType) { await pushClient.SendProjectMessageAsync(context, message, messageType); } } public class ModuleConfig : ICloudCodeSetup { public void Setup(ICloudCodeConfig config) { config.Dependencies.AddSingleton(PushClient.Create()); } }}
액세스를 제한하는 액세스 제어 프로젝트 정책 생성
다음과 같은 내용으로project-policy.jsonUGS CLI 툴을 사용하여 이 정책을 프로젝트에 적용합니다.{ "statements": [ { "Sid": "DenyPlayerAccessForSendingMessageToProject", "Resource": "urn:ugs:cloud-code:/v1/projects/*/modules/HelloWorld/SendProjectMessage", "Principal": "Player", "Action": ["*"], "Effect": "Deny" } ]}
ugs access upsert-project-policy project-policy.jsonSendProjectMessage정책이 적용되면 이 요청은curl 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/players/<PLAYER_ID>/modules/HelloWorld/SendProjectMessage' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer <BEARER_TOKEN>' \--data '{"params": {"message": "hello"}}'
403동일한 요청에서 서비스 계정을 사용하여 인증되었을 때 Cloud Code 모듈을 실행할 수 있는지 테스트합니다. 계속하려면 상태 비보존 토큰을 획득하여 요청의 bearer 토큰으로 사용해야 합니다. 자세한 내용은 Cloud Code 클라이언트 API bearer 인증을 참고하십시오.{ "status": 403, "title": "Forbidden", "type": "https://services.docs.unity.com/docs/errors/#56", "requestId": "b815d154-91f5-470e-a8ef-76c3c8ec7c13", "detail": "Access has been restricted", "code": 56}
요청이 성공하면 Cloud Code는curl 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/modules/HelloWorld/SendProjectMessage' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer <BEARER_TOKEN>' \--data '{"params": {"message": "hello"}}'
200{ "output":null}
Scheduling 및 Triggers 설정
일정과 트리거를 설정하여SendProjectMessage일정 구성을 만듭니다
new-file다음 구성을 사용하여ugs scheduler new-file schedule-config
schedule-config.sched{ "$schema": "https://ugs-config-schemas.unity3d.com/v1/schedules.schema.json", "Configs": { "send-project-message": { "EventName": "announcement", "Type": "one-time", "Schedule": "2024-08-28T00:00:00Z", "PayloadVersion": 1, "Payload": "{\"message\": \"hello\"}" } }}
트리거 구성을 만듭니다
new-fileugs triggers new-file triggers-config
SendProjectMessageannouncementtriggers-config.tr{ "$schema": "https://ugs-config-schemas.unity3d.com/v1/triggers.schema.json", "Configs": [ { "Name": "announcement-trigger", "EventType": "com.unity.services.scheduler.announcement.v1", "ActionUrn": "urn:ugs:cloud-code:HelloWorld/SendProjectMessage", "ActionType": "cloud-code" } ]}
구성 배포
다음과 같이 UGS CLI 툴을 사용하여 파일을 배포합니다.올바르게 구성된 경우, 트리거는ugs deploy <path-to-config-files>
announcementSendProjectMessage