Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzo delle concessioni
Gli esempi in questo argomento utilizzano l'API AWS KMS per creare, visualizzare, ritirare e revocare le concessioni su AWS KMS keys. Per ulteriori informazioni sull'utilizzo delle concessioni in AWS KMS, consulta Sovvenzioni in AWS KMS.
Creazione di una concessione
Per creare una sovvenzione per unAWS KMS key, usa l'CreateGrantoperazione. La risposta include solo l'ID e il token della concessione. Per ottenere informazioni dettagliate sulla sovvenzione, utilizzate l'ListGrantsoperazione, come illustrato inVisualizzazione di una concessione.
Questi esempi creano una concessione che consente agli utenti che possono assumere il ExampleKeyUser
ruolo di richiamare l'GenerateDataKeyoperazione sulla chiave KMS identificata dal KeyId
parametro.
Nelle lingue che richiedono un oggetto client, questi esempi utilizzano l'oggetto client AWS KMS creato in Creazione di un client.
- Java
-
Per ulteriori informazioni, consulta il metodo createGrant nella Documentazione di riferimento dell'API AWS SDK for Java.
// Create a grant
//
// 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 granteePrincipal = "arn:aws:iam::111122223333:role/ExampleKeyUser";
String operation = GrantOperation.GenerateDataKey.toString();
CreateGrantRequest request = new CreateGrantRequest()
.withKeyId(keyId)
.withGranteePrincipal(granteePrincipal)
.withOperations(operation);
CreateGrantResult result = kmsClient.createGrant(request);
- C#
-
Per maggiori dettagli, consultare il metodo CreateGrant in AWS SDK for .NET.
// Create a grant
//
// 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 granteePrincipal = "arn:aws:iam::111122223333:role/ExampleKeyUser";
String operation = GrantOperation.GenerateDataKey;
CreateGrantRequest createGrantRequest = new CreateGrantRequest()
{
KeyId = keyId,
GranteePrincipal = granteePrincipal,
Operations = new List<string>() { operation }
};
CreateGrantResponse createGrantResult = kmsClient.CreateGrant(createGrantRequest);
- Python
-
Per maggiori dettagli, consultare il metodo create_grant
in AWS SDK for Python (Boto3).
# Create a grant
# 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'
grantee_principal = 'arn:aws:iam::111122223333:role/ExampleKeyUser'
operation = ['GenerateDataKey']
response = kms_client.create_grant(
KeyId=key_id,
GranteePrincipal=grantee_principal,
Operations=operation
)
- Ruby
-
Per maggiori dettagli, consultare il metodo dell'istanza create_grant
in AWS SDK for Ruby.
# Create a grant
# 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'
grantee_principal = 'arn:aws:iam::111122223333:role/ExampleKeyUser'
operation = ['GenerateDataKey']
response = kmsClient.create_grant({
key_id: key_id,
grantee_principal: grantee_principal,
operations: operation
})
- PHP
-
Per maggiori dettagli, consultare il metodo CreateGrant in AWS SDK for PHP.
// Create a grant
//
// 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';
$granteePrincipal = "arn:aws:iam::111122223333:role/ExampleKeyUser";
$operation = ['GenerateDataKey']
$result = $KmsClient->createGrant([
'GranteePrincipal' => $granteePrincipal,
'KeyId' => $keyId,
'Operations' => $operation
]);
- Node.js
-
Per i dettagli, vedete la proprietà CreateGrant nell'SDK JavaScript per AWS Node.js.
// Create a grant
//
// 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 GranteePrincipal = 'arn:aws:iam::111122223333:role/ExampleKeyUser';
const Operations: ["GenerateDataKey"];
kmsClient.createGrant({ KeyId, GranteePrincipal, Operations }, (err, data) => {
...
});
- PowerShell
-
Per creare una concessione, utilizzare il cmdlet New-KMSGrant.
# Create a grant
# 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'
$granteePrincipal = 'arn:aws:iam::111122223333:role/ExampleKeyUser'
$operation = 'GenerateDataKey'
$response = New-KMSGrant -GranteePrincipal $granteePrincipal -KeyId $keyId -Operation $operation
Per utilizzare i AWS KMS PowerShell cmdlet, installa AWS.Tools. KeyManagementServicemodulo. Per ulteriori informazioni, consulta la AWS Tools for Windows PowerShellGuida per l'utente.
Visualizzazione di una concessione
Per ottenere informazioni dettagliate sulle sovvenzioni su una chiave KMS, usa l'ListGrantsoperazione.
Il campo GranteePrincipal
nella risposta ListGrants
contiene solitamente il principal dell'assegnatario della concessione. Tuttavia, quando il principale dell'assegnatario della concessione è un servizio AWS, il campo GranteePrincipal
contiene il principale del servizio, che potrebbe rappresentare più principali dell'assegnatario diversi.
Nelle lingue che richiedono un oggetto client, questi esempi utilizzano l'oggetto client AWS KMS creato in Creazione di un client.
Questi esempi utilizzano il parametro Limits
opzionale che determina il numero di concessioni restituite dall'operazione.
- Java
-
Per ulteriori informazioni sull'implementazione Java, consulta il metodo listGrants nella Documentazione di riferimento dell'API AWS SDK for Java.
// Listing grants on 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";
Integer limit = 10;
ListGrantsRequest req = new ListGrantsRequest().withKeyId(keyId).withLimit(limit);
ListGrantsResult result = kmsClient.listGrants(req);
- C#
-
Per maggiori dettagli, consultare il metodo ListGrants in AWS SDK for .NET.
// Listing grants on 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";
int limit = 10;
ListGrantsRequest listGrantsRequest = new ListGrantsRequest()
{
KeyId = keyId,
Limit = limit
};
ListGrantsResponse listGrantsResponse = kmsClient.ListGrants(listGrantsRequest);
- Python
-
Per maggiori dettagli, consultare il metodo list_grants
in AWS SDK for Python (Boto3).
# Listing grants on 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'
response = kms_client.list_grants(
KeyId=key_id,
Limit=10
)
- Ruby
-
Per maggiori dettagli, consultare il metodo dell'istanza list_grants
in AWS SDK for Ruby.
# Listing grants on 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'
response = kmsClient.list_grants({
key_id: key_id,
limit: 10
})
- PHP
-
Per maggiori dettagli, consultare il metodo ListGrants in AWS SDK for PHP.
// Listing grants on 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';
$limit = 10;
$result = $KmsClient->listGrants([
'KeyId' => $keyId,
'Limit' => $limit,
]);
- Node.js
-
Per i dettagli, vedete la proprietà ListGrants nell'SDK JavaScript per in AWS Node.js.
// Listing grants on 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 Limit = 10;
kmsClient.listGrants({ KeyId, Limit }, (err, data) => {
...
});
- PowerShell
-
Per visualizzare i dettagli di tutte le AWS KMS concessioni per una chiave KMS, utilizzare il cmdlet Get-KMS. GrantList
Per limitare il numero di oggetti di output, in questo esempio viene utilizzato il cmdlet Select-Object anziché il parametro Limit
, che viene considerato obsoleto nei cmdlet list. Per informazioni sull'impaginazione dell'output in AWS Tools for PowerShell, consulta Paginazione output con AWS Tools for PowerShell.
# Listing grants on 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'
$limit = 10
$response = Get-KMSGrantList -KeyId $keyId | Select-Object -First $limit
Per utilizzare i cmdlet, installa AWS.Tools. AWS KMS PowerShell KeyManagementServicemodulo. Per ulteriori informazioni, consulta la AWS Tools for Windows PowerShellGuida per l'utente.
È necessario specificare la chiave KMS chiave in ogni operazione ListGrants
. Tuttavia, è possibile filtrare ulteriormente l'elenco delle concessioni specificando l'ID di concessione o un assegnatario principale. Negli esempi seguenti vengono ottenute solo le concessioni per una chiave KMS in cui il ruolo test-engineer
è l'assegnatario principale.
- Java
-
Per ulteriori informazioni sull'implementazione Java, consulta il metodo listGrants nella Documentazione di riferimento dell'API AWS SDK for Java.
// Listing grants on 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 grantee = "arn:aws:iam::111122223333:role/test-engineer";
ListGrantsRequest req = new ListGrantsRequest().withKeyId(keyId).withGranteePrincipal(grantee);
ListGrantsResult result = kmsClient.listGrants(req);
- C#
-
Per maggiori dettagli, consultare il metodo ListGrants in AWS SDK for .NET.
// Listing grants on 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 grantee = "arn:aws:iam::111122223333:role/test-engineer";
ListGrantsRequest listGrantsRequest = new ListGrantsRequest()
{
KeyId = keyId,
GranteePrincipal = grantee
};
ListGrantsResponse listGrantsResponse = kmsClient.ListGrants(listGrantsRequest);
- Python
-
Per maggiori dettagli, consultare il metodo list_grants
in AWS SDK for Python (Boto3).
# Listing grants on 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'
grantee = 'arn:aws:iam::111122223333:role/test-engineer'
response = kms_client.list_grants(
KeyId=key_id,
GranteePrincipal=grantee
)
- Ruby
-
Per maggiori dettagli, consultare il metodo dell'istanza list_grants
in AWS SDK for Ruby.
# Listing grants on 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'
grantee = 'arn:aws:iam::111122223333:role/test-engineer'
response = kmsClient.list_grants({
key_id: keyId,
grantee_principal: grantee
})
- PHP
-
Per maggiori dettagli, consultare il metodo ListGrants in AWS SDK for PHP.
// Listing grants on 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';
$grantee = 'arn:aws:iam::111122223333:role/test-engineer';
$result = $KmsClient->listGrants([
'KeyId' => $keyId,
'GranteePrincipal' => $grantee,
]);
- Node.js
-
Per i dettagli, vedete la proprietà ListGrants nell'SDK JavaScript per in AWS Node.js.
// Listing grants on 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 Grantee = 'arn:aws:iam::111122223333:role/test-engineer';
kmsClient.listGrants({ KeyId, Grantee }, (err, data) => {
...
});
- PowerShell
-
Per visualizzare i dettagli di tutte le AWS KMS concessioni per una chiave KMS, utilizzare il cmdlet Get-KMS. GrantList
# Listing grants on 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'
$grantee = 'arn:aws:iam::111122223333:role/test-engineer'
$response = Get-KMSGrantList -KeyId $keyId -GranteePrincipal $grantee
Per utilizzare i cmdlet, installa AWS.Tools. AWS KMS PowerShell KeyManagementServicemodulo. Per ulteriori informazioni, consulta la AWS Tools for Windows PowerShellGuida per l'utente.
Ritiro di una concessione
Per ritirare una concessione per una chiave KMS, usa l'RetireGrantoperazione. È consigliabile ritirare una concessione dopo aver terminato il suo utilizzo.
Per ritirare una concessione specifica il token di concessione oppure sia l'ID di concessione che l'ID chiave della chiave KMS. Per questa operazione, l'ID della chiave KMS deve essere l'Amazon Resource Name (ARN) della chiave KMS. Il token di concessione viene restituito dall'CreateGrantoperazione. L'ID della concessione viene restituito dalle ListGrantsoperazioni CreateGrant and.
RetireGrant non restituisce una risposta. Per verificare che sia efficace, usa l'ListGrantsoperazione.
Nelle lingue che richiedono un oggetto client, questi esempi utilizzano l'oggetto client AWS KMS creato in Creazione di un client.
- Java
-
Per ulteriori informazioni, consulta il metodo retireGrant nella Documentazione di riferimento dell'API AWS SDK for Java.
// Retire a grant
//
String grantToken = Place your grant token here
;
RetireGrantRequest req = new RetireGrantRequest().withGrantToken(grantToken);
kmsClient.retireGrant(req);
- C#
-
Per maggiori dettagli, consultare il metodo RetireGrant in AWS SDK for .NET.
// Retire a grant
//
String grantToken = "Place your grant token here
";
RetireGrantRequest retireGrantRequest = new RetireGrantRequest()
{
GrantToken = grantToken
};
kmsClient.RetireGrant(retireGrantRequest);
- Python
-
Per maggiori dettagli, consultare il metodo retire_grant
in AWS SDK for Python (Boto3).
# Retire a grant
grant_token = Place your grant token here
response = kms_client.retire_grant(
GrantToken=grant_token
)
- Ruby
-
Per maggiori dettagli, consultare il metodo dell'istanza retire_grant
in AWS SDK for Ruby.
# Retire a grant
grant_token = Place your grant token here
response = kmsClient.retire_grant({
grant_token: grant_token
})
- PHP
-
Per maggiori dettagli, consultare il metodo RetireGrant in AWS SDK for PHP.
// Retire a grant
//
$grantToken = 'Place your grant token here
';
$result = $KmsClient->retireGrant([
'GrantToken' => $grantToken,
]);
- Node.js
-
Per i dettagli, vedete la proprietà RetireGrant nell'SDK JavaScript per in AWS Node.js.
// Retire a grant
//
const GrantToken = 'Place your grant token here
';
kmsClient.retireGrant({ GrantToken }, (err, data) => {
...
});
- PowerShell
-
Per ritirare una concessione, utilizzare il cmdlet Disable-KMSGrant. Per ottenere il token di concessione, utilizzare il cmdlet New-KMSGrant. Il parametro GrantToken
accetta una stringa, quindi non è necessario convertire l'output restituito dal cmdlet Read-Host.
# Retire a grant
$grantToken = Read-Host -Message Place your grant token here
Disable-KMSGrant -GrantToken $grantToken
Per utilizzare i AWS KMS PowerShell cmdlet, installa AWS.Tools. KeyManagementServicemodulo. Per ulteriori informazioni, consulta la AWS Tools for Windows PowerShellGuida per l'utente.
Revoca di una concessione
Per revocare una concessione a una chiave KMS, usa l'operazione. RevokeGrant Puoi revocare una concessione per negare esplicitamente le operazioni che dipendono da essa.
Nelle lingue che richiedono un oggetto client, questi esempi utilizzano l'oggetto client AWS KMS creato in Creazione di un client.
- Java
-
Per ulteriori informazioni, consulta il metodo revokeGrant nella Documentazione di riferimento dell'API AWS SDK for Java.
// Revoke a grant on 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";
// Replace the following example grant ID with a valid one
String grantId = "grant1";
RevokeGrantRequest req = new RevokeGrantRequest().withKeyId(keyId).withGrantId(grantId);
kmsClient.revokeGrant(req);
- C#
-
Per maggiori dettagli, consultare il metodo RevokeGrant in AWS SDK for .NET.
// Revoke a grant on 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";
// Replace the following example grant ID with a valid one
String grantId = "grant1";
RevokeGrantRequest revokeGrantRequest = new RevokeGrantRequest()
{
KeyId = keyId,
GrantId = grantId
};
kmsClient.RevokeGrant(revokeGrantRequest);
Per utilizzare i AWS KMS PowerShell cmdlet, installa AWS.Tools. KeyManagementServicemodulo. Per ulteriori informazioni, consulta la AWS Tools for Windows PowerShellGuida per l'utente.
- Python
-
Per maggiori dettagli, consultare il metodo revoke_grant
in AWS SDK for Python (Boto3).
# Revoke a grant on 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'
# Replace the following example grant ID with a valid one
grant_id = 'grant1'
response = kms_client.revoke_grant(
KeyId=key_id,
GrantId=grant_id
)
- Ruby
-
Per maggiori dettagli, consultare il metodo dell'istanza revoke_grant
in AWS SDK for Ruby.
# Revoke a grant on 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'
# Replace the following example grant ID with a valid one
grant_id = 'grant1'
response = kmsClient.revoke_grant({
key_id: key_id,
grant_id: grant_id
})
- PHP
-
Per maggiori dettagli, consultare il metodo RevokeGrant in AWS SDK for PHP.
// Revoke a grant on 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';
// Replace the following example grant ID with a valid one
$grantId = "grant1";
$result = $KmsClient->revokeGrant([
'KeyId' => $keyId,
'GrantId' => $grantId,
]);
- Node.js
-
Per i dettagli, vedete la proprietà Revokegrant nell'AWSSDK per Node.js. JavaScript
// Revoke a grant on 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';
// Replace the following example grant ID with a valid one
const GrantId = 'grant1';
kmsClient.revokeGrant({ GrantId, KeyId }, (err, data) => {
...
});
- PowerShell
-
Per revocare una concessione, utilizzare il cmdlet Revoke-KMSGrant.
# Revoke a grant on 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'
# Replace the following example grant ID with a valid one
$grantId = 'grant1'
Revoke-KMSGrant -KeyId $keyId -GrantId $grantId
Per utilizzare i AWS KMS PowerShell cmdlet, installa AWS.Tools. KeyManagementServicemodulo. Per ulteriori informazioni, consulta la Guida per l'utente AWS Tools for Windows PowerShell.