Créer une nouvelle version d’une politique gérée

Vous pouvez créer une nouvelle version d’une politique gérée pour la mettre à jour. Les politiques gérées peuvent avoir jusqu’à cinq versions.

Vous pouvez définir cette nouvelle version comme celle à appliquer par défaut aux identités EIM auxquelles la politique est attachée.

Créer une nouvelle version d’une politique gérée avec OSC CLI

À ce jour, cette section est disponible en anglais uniquement.

The CreatePolicyVersion command creates a version of a specified managed policy.
A managed policy can have up to five versions.

Request sample
$ osc-cli api CreatePolicyVersion --profile "default" \
    --Document '"{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}"' \
    --PolicyOrn "orn:ows:idauth::012345678910:policy/example/example-user-policy" \
    --SetAsDefault True

This command contains the following attributes that you need to specify:

  • Document: The policy document, corresponding to a JSON string that contains the policy. This policy document can contain a maximum of 5120 non-whitespace characters. For more information, see EIM Reference Information and EIM Policy Generator.

  • PolicyOrn: The OUTSCALE Resource Name (ORN) of the policy. For more information, see Resource Identifiers.

  • SetAsDefault: (optional) If set to true, the new policy version is set as the default version and becomes the operative one.

The CreatePolicyVersion command returns the following elements:

  • PolicyVersion: Information about the policy version.

    • Body: The policy document, corresponding to a JSON string that contains the policy. For more information, see EIM Reference Information and EIM Policy Generator.

    • CreationDate: The date and time (UTC) at which the version was created.

    • DefaultVersion: If true, the version is the default one.

    • VersionId: The ID of the version.

  • ResponseContext: Information about the context of the response.

    • RequestId: The ID of the request.

Result sample
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "PolicyVersion": {
    "VersionId": "v2",
    "DefaultVersion": true,
    "CreationDate": "2017-05-10T12:34:56.789+0000",
    "Body": "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}"
  }
}

Créer une nouvelle version d’une politique gérée avec oapi-cli

À ce jour, cette section est disponible en anglais uniquement.

The CreatePolicyVersion command creates a version of a specified managed policy.
A managed policy can have up to five versions.

Request sample
$ oapi-cli --profile "default" CreatePolicyVersion \
    --Document --jsonstr-file "policy.json" \
    --PolicyOrn "orn:ows:idauth::012345678910:policy/example/example-user-policy" \
    --SetAsDefault True

This command contains the following attributes that you need to specify:

  • Document: The policy document, corresponding to a JSON string that contains the policy. This policy document can contain a maximum of 5120 non-whitespace characters. For more information, see EIM Reference Information and EIM Policy Generator.

  • PolicyOrn: The OUTSCALE Resource Name (ORN) of the policy. For more information, see Resource Identifiers.

  • SetAsDefault: (optional) If set to true, the new policy version is set as the default version and becomes the operative one.

The CreatePolicyVersion command returns the following elements:

  • PolicyVersion: Information about the policy version.

    • Body: The policy document, corresponding to a JSON string that contains the policy. For more information, see EIM Reference Information and EIM Policy Generator.

    • CreationDate: The date and time (UTC) at which the version was created.

    • DefaultVersion: If true, the version is the default one.

    • VersionId: The ID of the version.

  • ResponseContext: Information about the context of the response.

    • RequestId: The ID of the request.

Result sample
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "PolicyVersion": {
    "VersionId": "v2",
    "DefaultVersion": true,
    "CreationDate": "2017-05-10T12:34:56.789+0000",
    "Body": "{\"Statement\": [ {\"Effect\": \"Allow\", \"Action\": [\"*\"], \"Resource\": [\"*\"]} ]}"
  }
}

Créer une nouvelle version d’une politique gérée avec AWS CLI

Avant de commencer : Installez et configurez AWS CLI. Pour en savoir plus, voir Installer et configurer AWS CLI.

Pour créer une nouvelle version d’une politique gérée, utilisez la commande create-policy-version en suivant cette syntaxe :

Exemple de requête
$ aws iam create-policy-version \
    --profile YOUR_PROFILE \
    --policy-arn arn:aws:iam::123456789012:policy/MY_POLICY \
    --policy-document file://policy \
    --set-as-default \
    --endpoint https://eim.eu-west-2.outscale.com

Cette commande contient les attributs suivants que vous devez spécifier :

  • (optionnel) profile : Le profil nommé que vous voulez utiliser, créé pendant la configuration d’AWS CLI. Pour en savoir plus, voir Installer et configurer AWS CLI.

  • policy-arn : L’OUTSCALE Resource Name (ORN) de la politique. Pour en savoir plus, voir Identifiants de ressources.

  • policy-document : Le document de politique, correspondant à une chaîne JSON qui contient la nouvelle version de la politique. Ce document de politique peut contenir un maximum de 5120 caractères autres qu’un espace blanc. Pour en savoir plus, voir Informations de référence pour EIM et Générateur de politiques EIM.

  • (optionnel) set-as-default | no-set-as-default : Si paramétré sur set-as-default, la nouvelle version de la politique devient celle par défaut et est appliquée à toutes les identités EIM auxquelles la politique est attachée.

  • endpoint : Le endpoint correspondant à la Région à laquelle vous voulez envoyer la requête. Pour en savoir plus, voir Installer et configurer AWS CLI.

La commande create-policy-version renvoie les éléments suivants :

  • PolicyVersion : Informations à propos de la nouvelle version de la politique. Cet élément contient les informations suivantes :

    • CreateDate : La date et l’heure de création de la version de la politique.

    • VersionId : L’ID de la version de la politique.

    • IsDefaultVersion : Si true, la nouvelle version de la politique est celle par défaut.

Exemple de résultat
{
    "PolicyVersion": {
        "CreateDate": "2016-05-12T18:43:524Z",
        "VersionId": "v2",
        "IsDefaultVersion": true
    }
}

La version de la politique est créée et définie comme celle par défaut si vous l’avez spécifié.

Pages connexes

Méthode API correspondante

AWS™ et Amazon Web Services™ sont des marques de commerce d’Amazon Technologies, Inc. ou de ses affiliées aux États-Unis et/ou dans les autres pays.