翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
AWS KMS API と AWS SDK for PHP バージョン 3 を使用した許可の使用
許可は、アクセス許可を付与するための別のメカニズムです。キーポリシーに代わるものです。権限を使用して、プリン AWS シパルが AWS Key Management Service (AWS KMS) カスタマー管理の を使用できるようにする長期的なアクセスを許可できますAWS KMS keys。詳細については、AWS Key Management Service デベロッパーガイドの「AWS KMSに付与する」を参照してください。
以下の例では、次の方法を示しています。
-
CreateGrant を使用して KMS キーに対するグラントを作成する。
-
ListGrants を使用して KMS キーの許可を表示する。
-
RetireGrant を使用して KMS キーの許可を無効にする。
-
RevokeGrant を使用して KMS キーの許可を取り消す。
のすべてのサンプルコード AWS SDK for PHP はGitHub で入手できます
認証情報
サンプルコードを実行する前に、「」の説明に従って AWS 認証情報を設定しますAWS SDK for PHP バージョン 3 AWS を使用した での認証。次に AWS SDK for PHP、「」の説明に従って をインポートしますAWS SDK for PHP バージョン 3 のインストール。
AWS Key Management Service (AWS KMS) の使用の詳細については、「 AWS KMS デベロッパーガイド」を参照してください。
許可を作成する
の許可を作成するには AWS KMS key、CreateGrant オペレーションを使用します。
インポート
require 'vendor/autoload.php'; use Aws\Exception\AwsException;
サンプルコード
$KmsClient = new Aws\Kms\KmsClient([ 'profile' => 'default', 'version' => '2014-11-01', 'region' => 'us-east-2' ]); $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; $granteePrincipal = "arn:aws:iam::111122223333:user/Alice"; $operation = ['Encrypt', 'Decrypt']; // A list of operations that the grant allows. try { $result = $KmsClient->createGrant([ 'GranteePrincipal' => $granteePrincipal, 'KeyId' => $keyId, 'Operations' => $operation ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }
許可を表示する
の許可に関する詳細情報を取得するには AWS KMS key、ListGrants オペレーションを使用します。
インポート
require 'vendor/autoload.php'; use Aws\Exception\AwsException;
サンプルコード
$KmsClient = new Aws\Kms\KmsClient([ 'profile' => 'default', 'version' => '2014-11-01', 'region' => 'us-east-2' ]); $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; $limit = 10; try { $result = $KmsClient->listGrants([ 'KeyId' => $keyId, 'Limit' => $limit, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }
許可を無効にする
の許可を廃止するには AWS KMS key、RetireGrant オペレーションを使用します。許可の使用が完了した後でクリーンアップを実行する場合に、許可を無効にします。
インポート
require 'vendor/autoload.php'; use Aws\Exception\AwsException;
サンプルコード
$KmsClient = new Aws\Kms\KmsClient([ 'profile' => 'default', 'version' => '2014-11-01', 'region' => 'us-east-2' ]); $grantToken = 'Place your grant token here'; try { $result = $KmsClient->retireGrant([ 'GrantToken' => $grantToken, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; } //Can also identify grant to retire by a combination of the grant ID //and the Amazon Resource Name (ARN) of the customer master key (CMK) $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; $grantId = 'Unique identifier of the grant returned during CreateGrant operation'; try { $result = $KmsClient->retireGrant([ 'GrantId' => $grantToken, 'KeyId' => $keyId, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }
許可を取り消す
に対する許可を取り消すには AWS KMS key、RevokeGrant オペレーションを使用します。許可を取り消して、許可に依存しているオペレーションを明示的に拒否することができます。
インポート
require 'vendor/autoload.php'; use Aws\Exception\AwsException;
サンプルコード
$KmsClient = new Aws\Kms\KmsClient([ 'profile' => 'default', 'version' => '2014-11-01', 'region' => 'us-east-2' ]); $keyId = 'arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'; $grantId = "grant1"; try { $result = $KmsClient->revokeGrant([ 'KeyId' => $keyId, 'GrantId' => $grantId, ]); var_dump($result); } catch (AwsException $e) { // output error message if fails echo $e->getMessage(); echo "\n"; }