키 정책 작업 - AWS Key Management Service

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

키 정책 작업

이 주제의 예제들은 AWS KMS API를 사용하여 AWS KMS keys의 키 정책을 확인하고 변경합니다.

키 정책, IAM 정책 및 권한 부여를 사용하여 KMS 키에 대한 액세스를 관리하는 방법에 대한 세부 정보는 AWS KMS에 대한 인증 및 액세스 제어 단원을 참조하십시오. JSON 정책 문서 작성 및 형식 지정에 대한 도움말은 IAM 사용 설명서IAM JSON 정책 참조를 참조하십시오.

키 정책 이름 나열

의 키 정책 이름을 가져오려면 ListKeyPolicies작업을 사용하십시오. AWS KMS key 현재 반환되는 유일한 키 정책 이름은 기본입니다.

클라이언트 객체가 필요한 언어의 경우 이러한 예제에서는 클라이언트 만들기에서 생성한 AWS KMS 클라이언트 객체를 사용합니다.

Java

Java 구현에 대한 자세한 내용은 AWS SDK for JavaAPI 참조의 listKeyPolicies 메서드를 참조하십시오.

// List key policies // // Replace the following example key ARN with a valid key ID or key ARN String keyId = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"; ListKeyPoliciesRequest req = new ListKeyPoliciesRequest().withKeyId(keyId); ListKeyPoliciesResult result = kmsClient.listKeyPolicies(req);
C#

자세한 내용은 AWS SDK for .NETListKeyPolicies 메서드를 참조하세요.

// List key policies // // Replace the following example key ARN with a valid key ID or key ARN String keyId = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"; ListKeyPoliciesRequest listKeyPoliciesRequest = new ListKeyPoliciesRequest() { KeyId = keyId }; ListKeyPoliciesResponse listKeyPoliciesResponse = kmsClient.ListKeyPolicies(listKeyPoliciesRequest);
Python

자세한 내용은 AWS SDK for Python (Boto3)의 list_key_policies 메서드를 참조하세요.

# List key policies # Replace the following example key ARN with a valid key ID or key ARN key_id = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' response = kms_client.list_key_policies( KeyId=key_id )
Ruby

자세한 내용은 AWS SDK for Rubylist_key_policies 인스턴스 메서드를 참조하세요.

# List key policies # Replace the following example key ARN with a valid key ID or key ARN key_id = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' response = kmsClient.list_key_policies({ key_id: key_id })
PHP

자세한 내용은 AWS SDK for PHPListKeyPolicies 메서드를 참조하세요.

// List key policies // // Replace the following example key ARN with a valid key ID or key ARN $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; $result = $KmsClient->listKeyPolicies([ 'KeyId' => $keyId ]);
Node.js

자세한 내용은 Node.js 용 AWS SDK의 listKeyPolicies 속성을 참조하십시오. JavaScript

// List key policies // // Replace the following example key ARN with a valid key ID or key ARN const KeyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; kmsClient.listKeyPolicies({ KeyId }, (err, data) => { ... });
PowerShell

기본 키 정책의 이름을 나열하려면 KeyPolicyListGet-KMS cmdlet을 사용하십시오.

# List key policies # Replace the following example key ARN with a valid key ID or key ARN $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' $response = Get-KMSKeyPolicyList -KeyId $keyId

AWS KMS PowerShell cmdlet을 사용하려면 AWS.tools를 설치하십시오. KeyManagementService모듈. 자세한 정보는 AWS Tools for Windows PowerShell 사용 설명서를 참조하세요.

키 정책 가져오기

의 키 정책을 가져오려면 GetKeyPolicy작업을 사용하십시오. AWS KMS key

GetKeyPolicy 정책 이름이 필요합니다. 유일하게 유효한 정책 이름은 기본입니다.

클라이언트 객체가 필요한 언어의 경우 이러한 예제에서는 클라이언트 만들기에서 생성한 AWS KMS 클라이언트 객체를 사용합니다.

Java

자세한 내용은 AWS SDK for JavaAPI 참조의 getKeyPolicy 메서드를 참조하십시오.

// Get the policy for a KMS key // // Replace the following example key ARN with a valid key ID or key ARN String keyId = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"; String policyName = "default"; GetKeyPolicyRequest req = new GetKeyPolicyRequest().withKeyId(keyId).withPolicyName(policyName); GetKeyPolicyResult result = kmsClient.getKeyPolicy(req);
C#

자세한 내용은 AWS SDK for .NETGetKeyPolicy 메서드를 참조하세요.

// Get the policy for a KMS key // // Replace the following example key ARN with a valid key ID or key ARN String keyId = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"; String policyName = "default"; GetKeyPolicyRequest getKeyPolicyRequest = new GetKeyPolicyRequest() { KeyId = keyId, PolicyName = policyName }; GetKeyPolicyResponse getKeyPolicyResponse = kmsClient.GetKeyPolicy(getKeyPolicyRequest);
Python

자세한 내용은 AWS SDK for Python (Boto3)의 get_key_policy 메서드를 참조하세요.

# Get the policy for a KMS key # Replace the following example key ARN with a valid key ID or key ARN key_id = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' policy_name = 'default' response = kms_client.get_key_policy( KeyId=key_id, PolicyName=policy_name )
Ruby

자세한 내용은 AWS SDK for Rubyget_key_policy 인스턴스 메서드를 참조하세요.

# Get the policy for a KMS key # Replace the following example key ARN with a valid key ID or key ARN key_id = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' policy_name = 'default' response = kmsClient.get_key_policy({ key_id: key_id, policy_name: policy_name })
PHP

자세한 내용은 AWS SDK for PHPGetKeyPolicy 메서드를 참조하세요.

// Get the policy for a KMS key // // Replace the following example key ARN with a valid key ID or key ARN $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; $policyName = "default"; $result = $KmsClient->getKeyPolicy([ 'KeyId' => $keyId, 'PolicyName' => $policyName ]);
Node.js

자세한 내용은 Node.js 용 AWS SDK의 getKeyPolicy 속성을 참조하십시오. JavaScript

// Get the policy for a KMS key // // Replace the following example key ARN with a valid key ID or key ARN const KeyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; const PolicyName = 'default'; kmsClient.getKeyPolicy({ KeyId, PolicyName }, (err, data) => { ... });
PowerShell

KMS 키의 키 정책을 가져오려면 KeyPolicyGet-KMS cmdlet을 사용하십시오. 이 cmdlet은 키 정책을 Write-KMS () 명령에 사용할 수 있는 문자열 (시스템.문자열) 로 반환합니다. KeyPolicy PutKeyPolicy JSON 문자열의 정책을 개체로 변환하려면 -JSON cmdlet을 사용합니다. PSCustomObject ConvertFrom

# Get the policy for a KMS key # Replace the following example key ARN with a valid key ID or key ARN $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' $policyName = 'default' $response = Get-KMSKeyPolicy -KeyId $keyId -PolicyName $policyName

AWS KMS PowerShell cmdlet을 사용하려면 AWS.tools를 설치하십시오. KeyManagementService모듈. 자세한 정보는 AWS Tools for Windows PowerShell 사용 설명서를 참조하세요.

키 정책 설정

KMS 키의 키 정책을 만들거나 바꾸려면 PutKeyPolicy작업을 사용하십시오.

PutKeyPolicy는 정책 이름을 요구합니다. 유일하게 유효한 정책 이름은 기본입니다.

클라이언트 객체가 필요한 언어의 경우 이러한 예제에서는 클라이언트 만들기에서 생성한 AWS KMS 클라이언트 객체를 사용합니다.

Java

자세한 내용은 AWS SDK for JavaAPI 참조의 putKeyPolicy 메서드를 참조하십시오.

// Set a key policy for a KMS key // // Replace the following example key ARN with a valid key ID or key ARN String keyId = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"; String policyName = "default"; String policy = "{" + " \"Version\": \"2012-10-17\"," + " \"Statement\": [{" + " \"Sid\": \"Allow access for ExampleRole\"," + " \"Effect\": \"Allow\"," + // Replace the following example user ARN with a valid one " \"Principal\": {\"AWS\": \"arn:aws:iam::111122223333:role/ExampleKeyUserRole\"}," + " \"Action\": [" + " \"kms:Encrypt\"," + " \"kms:GenerateDataKey*\"," + " \"kms:Decrypt\"," + " \"kms:DescribeKey\"," + " \"kms:ReEncrypt*\"" + " ]," + " \"Resource\": \"*\"" + " }]" + "}"; PutKeyPolicyRequest req = new PutKeyPolicyRequest().withKeyId(keyId).withPolicy(policy).withPolicyName(policyName); kmsClient.putKeyPolicy(req);
C#

자세한 내용은 AWS SDK for .NETPutKeyPolicy 메서드를 참조하세요.

// Set a key policy for a KMS key // // Replace the following example key ARN with a valid key ID or key ARN String keyId = "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"; String policyName = "default"; String policy = "{" + " \"Version\": \"2012-10-17\"," + " \"Statement\": [{" + " \"Sid\": \"Allow access for ExampleUser\"," + " \"Effect\": \"Allow\"," + // Replace the following example user ARN with a valid one " \"Principal\": {\"AWS\": \"arn:aws:iam::111122223333:role/ExampleKeyUserRole\"}," + " \"Action\": [" + " \"kms:Encrypt\"," + " \"kms:GenerateDataKey*\"," + " \"kms:Decrypt\"," + " \"kms:DescribeKey\"," + " \"kms:ReEncrypt*\"" + " ]," + " \"Resource\": \"*\"" + " }]" + "}"; PutKeyPolicyRequest putKeyPolicyRequest = new PutKeyPolicyRequest() { KeyId = keyId, Policy = policy, PolicyName = policyName }; kmsClient.PutKeyPolicy(putKeyPolicyRequest);
Python

자세한 내용은 AWS SDK for Python (Boto3)의 put_key_policy 메서드를 참조하세요.

# Set a key policy for a KMS key # Replace the following example key ARN with a valid key ID or key ARN key_id = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' policy_name = 'default' policy = """ { "Version": "2012-10-17", "Statement": [{ "Sid": "Allow access for ExampleUser", "Effect": "Allow", "Principal": {"AWS": "arn:aws:iam::111122223333:role/ExampleKeyUserRole"}, "Action": [ "kms:Encrypt", "kms:GenerateDataKey*", "kms:Decrypt", "kms:DescribeKey", "kms:ReEncrypt*" ], "Resource": "*" }] }""" response = kms_client.put_key_policy( KeyId=key_id, Policy=policy, PolicyName=policy_name )
Ruby

자세한 내용은 AWS SDK for Rubyput_key_policy 인스턴스 메서드를 참조하세요.

# Set a key policy for a KMS key # Replace the following example key ARN with a valid key ID or key ARN key_id = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' policy_name = 'default' policy = "{" + " \"Version\": \"2012-10-17\"," + " \"Statement\": [{" + " \"Sid\": \"Allow access for ExampleUser\"," + " \"Effect\": \"Allow\"," + # Replace the following example user ARN with a valid one " \"Principal\": {\"AWS\": \"arn:aws:iam::111122223333:role/ExampleKeyUserRole\"}," + " \"Action\": [" + " \"kms:Encrypt\"," + " \"kms:GenerateDataKey*\"," + " \"kms:Decrypt\"," + " \"kms:DescribeKey\"," + " \"kms:ReEncrypt*\"" + " ]," + " \"Resource\": \"*\"" + " }]" + "}" response = kmsClient.put_key_policy({ key_id: key_id, policy: policy, policy_name: policy_name })
PHP

자세한 내용은 AWS SDK for PHPPutKeyPolicy 메서드를 참조하세요.

// Set a key policy for a KMS key // // Replace the following example key ARN with a valid key ID or key ARN $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; $policyName = "default"; $result = $KmsClient->putKeyPolicy([ 'KeyId' => $keyId, 'PolicyName' => $policyName, 'Policy' => '{ "Version": "2012-10-17", "Id": "custom-policy-2016-12-07", "Statement": [ { "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:user/root" }, "Action": [ "kms:*" ], "Resource": "*" }, { "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:role/ExampleKeyUserRole" }, "Action": [ "kms:Encrypt*", "kms:GenerateDataKey*", "kms:Decrypt*", "kms:DescribeKey*", "kms:ReEncrypt*" ], "Resource": "*" } ] } ' ]);
Node.js

자세한 내용은 Node.js 용 AWS SDK의 putKeyPolicy 속성을 참조하십시오. JavaScript

// Set a key policy for a KMS key // // Replace the following example key ARN with a valid key ID or key ARN const KeyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; const PolicyName = 'default'; const Policy = `{ "Version": "2012-10-17", "Id": "custom-policy-2016-12-07", "Statement": [ { "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:root" }, "Action": "kms:*", "Resource": "*" }, { "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:role/ExampleKeyUserRole" }, "Action": [ "kms:Encrypt*", "kms:GenerateDataKey*", "kms:Decrypt*", "kms:DescribeKey*", "kms:ReEncrypt*" ], "Resource": "*" } ] }`; // The key policy document kmsClient.putKeyPolicy({ KeyId, Policy, PolicyName }, (err, data) => { ... });
PowerShell

KMS 키에 대한 키 정책을 설정하려면 KeyPolicyWrite-KMS cmdlet을 사용하십시오. 이 cmdlet는 출력을 반환하지 않습니다. 명령이 효과적인지 확인하려면 Get-KMS cmdlet을 사용하십시오. KeyPolicy

Policy 파라미터는 문자열을 사용합니다. 문자열을 작은따옴표로 묶어 리터럴 문자열로 만듭니다. 리터럴 문자열에서는 연속 문자나 이스케이프 문자를 사용할 필요가 없습니다.

# Set a key policy for a KMS key # Replace the following example key ARN with a valid key ID or key ARN $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' $policyName = 'default' $policy = '{ "Version": "2012-10-17", "Statement": [ { "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:root" }, "Action": "kms:*", "Resource": "*" }, { "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::111122223333:role/ExampleKeyUserRole" }, "Action": [ "kms:Encrypt*", "kms:GenerateDataKey*", "kms:Decrypt*", "kms:DescribeKey*", "kms:ReEncrypt*" ], "Resource": "*" }] }' Write-KMSKeyPolicy -KeyId $keyId -PolicyName $policyName -Policy $policy

AWS KMS PowerShell cmdlet을 사용하려면 AWS.tools를 설치하십시오. KeyManagementService모듈. 자세한 내용은 AWS Tools for Windows PowerShell 사용 설명서를 참조하세요.