Configurez une liste d'autorisation ou de blocage de Referer pour un compartiment Object Storage Service (OSS). Spécifiez si les requêtes dont le champ Referer est vide sont autorisées et si la chaîne de requête dans l'URL doit être tronquée.
Notes d'utilisation
Par défaut, un compte Alibaba Cloud dispose des autorisations nécessaires pour configurer une liste d'autorisation ou de blocage de Referer pour un compartiment OSS. Pour configurer cette liste à l'aide d'un utilisateur RAM ou du Security Token Service (STS), vous devez disposer de l'autorisation oss:PutBucketReferer. Pour plus d'informations, consultez la rubrique Attacher une stratégie personnalisée à un utilisateur RAM.
Syntaxe de la commande
ossutil api put-bucket-referer --bucket value --referer-configuration value [flags]
|
Paramètre |
Type |
Description |
|
--bucket |
string |
Nom du compartiment. |
|
--referer-configuration |
string |
Conteneur stockant les configurations de protection contre le hotlinking. |
La commande put-bucket-referer correspond à l'opération PutBucketReferer. Pour plus d'informations sur les paramètres de l'opération PutBucketReferer, consultez la rubrique PutBucketReferer.
--referer-configuration
L'option --referer-configuration prend en charge les formats XML et JSON. Si la valeur de l'option contient le préfixe file://, ossutil lit les configurations depuis un fichier.
-
Format XML :
<RefererConfiguration> <TruncatePath>boolean</TruncatePath> <RefererList> <Referer>string</Referer> </RefererList> <RefererBlacklist> <Referer>string</Referer> </RefererBlacklist> <AllowEmptyReferer>boolean</AllowEmptyReferer> <AllowTruncateQueryString>boolean</AllowTruncateQueryString> </RefererConfiguration> -
Format JSON :
{ "AllowEmptyReferer": boolean, "AllowTruncateQueryString": boolean, "TruncatePath": boolean, "RefererList": { "Referer": ["string", ...] }, "RefererBlacklist": { "Referer": ["string", ...] } }
Pour plus d'informations sur les options de ligne de commande globales prises en charge, consultez la rubrique Options de ligne de commande globales.
Exemples
Les exemples suivants montrent comment configurer une liste d'autorisation ou de blocage de Referer pour un compartiment nommé examplebucket :
-
Créez un fichier de configuration nommé referer-configuration.xml et ajoutez-y le code suivant :
<?xml version="1.0" encoding="UTF-8"?> <RefererConfiguration> <AllowEmptyReferer>false</AllowEmptyReferer> <AllowTruncateQueryString>true</AllowTruncateQueryString> <TruncatePath>true</TruncatePath> <RefererList> <Referer>http://www.aliyun.com</Referer> <Referer>https://www.aliyun.com</Referer> <Referer>http://www.*.com</Referer> <Referer>https://www.?.aliyuncs.com</Referer> </RefererList> <RefererBlacklist> <Referer>http://www.refuse.com</Referer> <Referer>https://*.hack.com</Referer> <Referer>http://ban.*.com</Referer> <Referer>https://www.?.deny.com</Referer> </RefererBlacklist> </RefererConfiguration>
Exemple de commande :
ossutil api put-bucket-referer --bucket examplebucket --referer-configuration file://referer-configuration.xml
-
Créez un fichier de configuration nommé referer-configuration.json et ajoutez-y le code suivant :
{ "AllowEmptyReferer": "false", "AllowTruncateQueryString": "true", "TruncatePath": "true", "RefererList": { "Referer": [ "http://www.aliyun.com", "https://www.aliyun.com", "http://www.*.com", "https://www.?.aliyuncs.com" ] }, "RefererBlacklist": { "Referer": [ "http://www.refuse.com", "https://*.hack.com", "http://ban.*.com", "https://www.?.deny.com" ] } }Exemple de commande :
ossutil api put-bucket-referer --bucket examplebucket --referer-configuration file://referer-configuration.json -
Spécifiez les paramètres de la commande suivante au format JSON :
ossutil api put-bucket-referer --bucket examplebucket --referer-configuration "{\"AllowEmptyReferer\":\"false\",\"AllowTruncateQueryString\":\"true\",\"TruncatePath\":\"true\",\"RefererList\":{\"Referer\":[\"http://www.aliyun.com\",\"https://www.aliyun.com\",\"http://www.*.com\",\"https://www.?.aliyuncs.com\"]},\"RefererBlacklist\":{\"Referer\":[\"http://www.refuse.com\",\"https://*.hack.com\",\"http://ban.*.com\",\"https://www.?.deny.com\"]}}"