기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
다음과 CreateGrant
함께 사용하십시오. AWS SDK또는 CLI
다음 코드 예제는 CreateGrant
의 사용 방법을 보여 줍니다.
- .NET
-
- AWS SDK for .NET
-
참고
더 많은 정보가 있습니다 GitHub. 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리
. public static async Task Main() { var client = new AmazonKeyManagementServiceClient(); // The identity that is given permission to perform the operations // specified in the grant. var grantee = "arn:aws:iam::111122223333:role/ExampleRole"; // The identifier of the AWS KMS key to which the grant applies. You // can use the key ID or the Amazon Resource Name (ARN) of the KMS key. var keyId = "7c9eccc2-38cb-4c4f-9db3-766ee8dd3ad4"; var request = new CreateGrantRequest { GranteePrincipal = grantee, KeyId = keyId, // A list of operations that the grant allows. Operations = new List<string> { "Encrypt", "Decrypt", }, }; var response = await client.CreateGrantAsync(request); string grantId = response.GrantId; // The unique identifier of the grant. string grantToken = response.GrantToken; // The grant token. Console.WriteLine($"Id: {grantId}, Token: {grantToken}"); } }
-
자세한 API 내용은 CreateGrant을 참조하십시오. AWS SDK for .NET API참조.
-
- CLI
-
- AWS CLI
-
권한 부여를 생성하는 방법
다음
create-grant
예제는exampleUser
사용자가1234abcd-12ab-34cd-56ef-1234567890ab
예제 KMS 키에서decrypt
명령을 사용할 수 있는 권한을 생성합니다. 사용 중지하는 보안 주체는adminRole
역할입니다. 이 권한 부여는decrypt
요청의 암호화 컨텍스트에"Department": "IT"
키-값 페어가 포함된 경우에만 이 권한을 허용하도록EncryptionContextSubset
권한 부여 제약 조건을 사용합니다.aws kms create-grant \ --key-id
1234abcd-12ab-34cd-56ef-1234567890ab
\ --grantee-principalarn:aws:iam::123456789012:user/exampleUser
\ --operationsDecrypt
\ --constraintsEncryptionContextSubset={Department=IT}
\ --retiring-principalarn:aws:iam::123456789012:role/adminRole
출력:
{ "GrantId": "1a2b3c4d2f5e69f440bae30eaec9570bb1fb7358824f9ddfa1aa5a0dab1a59b2", "GrantToken": "<grant token here>" }
권한 부여에 대한 자세한 정보를 보려면
list-grants
명령을 사용하세요.자세한 내용은 Grants (권한 부여) 를 참조하십시오. AWS KMS에서 AWS 키 관리 서비스 개발자 가이드.
-
자세한 API 내용은 CreateGrant
을 참조하십시오. AWS CLI 명령 레퍼런스.
-
- Java
-
- SDK자바 2.x의 경우
-
참고
더 많은 내용이 있습니다. GitHub 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리
. /** * Grants permissions to a specified principal on a customer master key (CMK) asynchronously. * * @param keyId The unique identifier for the customer master key (CMK) that the grant applies to. * @param granteePrincipal The principal that is given permission to perform the operations that the grant permits on the CMK. * @return A {@link CompletableFuture} that, when completed, contains the ID of the created grant. * @throws RuntimeException If an error occurs during the grant creation process. */ public CompletableFuture<String> grantKeyAsync(String keyId, String granteePrincipal) { List<GrantOperation> grantPermissions = List.of( GrantOperation.ENCRYPT, GrantOperation.DECRYPT, GrantOperation.DESCRIBE_KEY ); CreateGrantRequest grantRequest = CreateGrantRequest.builder() .keyId(keyId) .name("grant1") .granteePrincipal(granteePrincipal) .operations(grantPermissions) .build(); CompletableFuture<CreateGrantResponse> responseFuture = getAsyncClient().createGrant(grantRequest); responseFuture.whenComplete((response, ex) -> { if (ex == null) { logger.info("Grant created successfully with ID: " + response.grantId()); } else { if (ex instanceof KmsException kmsEx) { throw new RuntimeException("Failed to create grant: " + kmsEx.getMessage(), kmsEx); } else { throw new RuntimeException("An unexpected error occurred: " + ex.getMessage(), ex); } } }); return responseFuture.thenApply(CreateGrantResponse::grantId); }
-
자세한 API 내용은 CreateGrant을 참조하십시오. AWS SDK for Java 2.x API참조.
-
- Kotlin
-
- SDK코틀린의 경우
-
참고
더 많은 정보가 있습니다. GitHub 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리
. suspend fun createNewGrant( keyIdVal: String?, granteePrincipalVal: String?, operation: String, ): String? { val operationOb = GrantOperation.fromValue(operation) val grantOperationList = ArrayList<GrantOperation>() grantOperationList.add(operationOb) val request = CreateGrantRequest { keyId = keyIdVal granteePrincipal = granteePrincipalVal operations = grantOperationList } KmsClient { region = "us-west-2" }.use { kmsClient -> val response = kmsClient.createGrant(request) return response.grantId } }
-
자세한 API 내용은 CreateGrant
을 참조하십시오. AWS SDKKotlin API 레퍼런스는 여기를 참조하세요.
-
- Python
-
- SDK파이썬용 (보토3)
-
참고
더 많은 정보가 있습니다. GitHub 전체 예제를 찾아 설치 및 실행 방법을 알아보십시오. AWS 코드 예제 리포지토리
. class GrantManager: def __init__(self, kms_client): self.kms_client = kms_client def create_grant(self, key_id): """ Creates a grant for a key that lets a principal generate a symmetric data encryption key. :param key_id: The ARN or ID of the key. :return: The grant that is created. """ principal = input( f"Enter the ARN of a principal, such as an IAM role, to grant that role " f"GenerateDataKey permissions on key {key_id}: " ) if principal != "": try: grant = self.kms_client.create_grant( KeyId=key_id, GranteePrincipal=principal, Operations=["GenerateDataKey"], ) except ClientError as err: logger.error( "Couldn't create a grant on key %s. Here's why: %s", key_id, err.response["Error"]["Message"], ) else: print(f"Grant created on key {key_id}.") return grant else: print("Skipping grant creation.")
-
자세한 API 내용은 CreateGrant을 참조하십시오. AWS SDK파이썬 (Boto3) API 참조용.
-
전체 목록은 다음과 같습니다. AWS SDK개발자 가이드 및 코드 예제는 을 참조하십시오사용 AWS KMS 와 함께 AWS SDK. 이 항목에는 시작에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.