Skip to content

Commit bfc8cee

Browse files
authored
Merge pull request #9721 from dddinary/0508-sign-version
feat(oss): default OSS SDK client to v4 signature
2 parents d8273ad + f42fd2a commit bfc8cee

2 files changed

Lines changed: 39 additions & 12 deletions

File tree

alicloud/connectivity/client.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,16 @@ func (client *AliyunClient) WithOssClient(do func(*oss.Client) (interface{}, err
556556
clientOptions = append(clientOptions, oss.Region(client.config.RegionId))
557557

558558
// SignVersion
559+
authVersion := oss.AuthV4
559560
if ossV, ok := client.config.SignVersion.Load("oss"); ok {
560-
clientOptions = append(clientOptions, oss.AuthVersion(func(v any) oss.AuthVersionType {
561-
switch fmt.Sprintf("%v", v) {
562-
case "v4":
563-
return oss.AuthV4
564-
case "v2":
565-
return oss.AuthV2
566-
}
567-
//default is v1
568-
return oss.AuthV1
569-
}(ossV)))
561+
switch fmt.Sprintf("%v", ossV) {
562+
case "v1":
563+
authVersion = oss.AuthV1
564+
case "v4":
565+
authVersion = oss.AuthV4
566+
}
570567
}
568+
clientOptions = append(clientOptions, oss.AuthVersion(authVersion))
571569

572570
ossconn, err := oss.New(endpoint, "", "", clientOptions...)
573571
if err != nil {

website/docs/index.html.markdown

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,23 @@ or
272272
$ export TF_APPEND_USER_AGENT="ArgoAgent/argo-12345678 NodeID/1234 (Optional Extra Information)"
273273
```
274274

275+
### Custom Product Sign Version
276+
277+
Some Alibaba Cloud products support more than one API signature version. The provider lets you override the signature version per product through the [`sign_version`](#sign_version) block. Currently `oss` and `sls` are supported. Note that the OSS SDK client defaults to signature `v4` since v1.278.0 (it was `v1` in earlier versions); set `oss = "v1"` explicitly if you still need the legacy signature.
278+
279+
Usage:
280+
281+
```terraform
282+
provider "alicloud" {
283+
region = "cn-hangzhou"
284+
285+
sign_version {
286+
oss = "v4"
287+
sls = "v4"
288+
}
289+
}
290+
```
291+
275292
## Argument Reference
276293

277294
In addition to [generic `provider` arguments](https://www.terraform.io/docs/configuration/providers.html)
@@ -330,6 +347,8 @@ In addition to [generic `provider` arguments](https://www.terraform.io/docs/conf
330347

331348
* `endpoints` - (Optional) An [`endpoints`](#endpoints) block to support custom endpoints.
332349

350+
* `sign_version` - (Optional, Available since v1.215.0) A [`sign_version`](#sign_version) block to specify the signature version used for the API requests of certain cloud products (currently `oss` and `sls`). Only one `sign_version` block may be in the configuration.
351+
333352
* `skip_region_validation` - (Optional, Available since v1.52.0) Skip static validation of region ID. Used by users of alternative AlibabaCloud-like APIs or users w/ access to regions that are not public (yet).
334353

335354
* `configuration_source` - (Optional, Available since v1.56.0) Use a string to mark a configuration file source, like `terraform-alicloud-modules/terraform-alicloud-ecs-instance` or `terraform-provider-alicloud/examples/vpc`.
@@ -363,7 +382,7 @@ The length should not more than 128(Before 1.207.2, it should not more than 64).
363382
This parameter is provided by an external party and is used to prevent the confused deputy problem.
364383
The value must be 2 to 1,224 characters in length and can contain letters, digits, and the following special characters:`= , . @ : / - _`.
365384

366-
### assume_role_with_oidc Configuration Block
385+
### `assume_role_with_oidc` Configuration Block
367386

368387
The `assume_role_with_oidc` configuration block supports the following arguments:
369388

@@ -377,7 +396,17 @@ The `assume_role_with_oidc` configuration block supports the following arguments
377396
Can also be set with the `ALIBABA_CLOUD_ROLE_SESSION_NAME` environment variable.
378397
* `session_expiration` - (Optional) The validity period of the STS token. Unit: seconds. Default value: 3600. Minimum value: 900. Maximum value: the value of the MaxSessionDuration parameter when creating a ram role.
379398
* `policy` - (Optional) The policy that specifies the permissions of the returned STS token. You can use this parameter to grant the STS token fewer permissions than the permissions granted to the RAM role.
380-
399+
400+
### `sign_version` Configuration Block
401+
402+
The `sign_version` configuration block overrides the signature version used by the SDK client of specific cloud products. See [Custom Product Sign Version](#custom-product-sign-version) for an example. The following arguments are supported:
403+
404+
* `oss` - (Optional) The signature version used by the OSS SDK client. Valid values: `v1`, `v4`. Starting from v1.278.0, the default value is changed from `v1` to `v4`; in earlier versions the default was `v1`. Set this field to `v1` explicitly if you need to keep using the legacy signature.
405+
406+
->**NOTE:** `v2` is no longer accepted starting from v1.278.0; the value will be treated as the default and the client will fall back to `v4`.
407+
408+
* `sls` - (Optional) The signature version used by the SLS (Log Service) SDK client. Valid values: `v1`, `v4`. Defaults to `v1`. Full v4 signature support across all `alicloud_sls_*` / `alicloud_log_*` resources is available since v1.276.0.
409+
381410
### `endpoints`
382411

383412
**NOTE:** Due to certain API restrictions, the endpoints pointing to the area should be consistent with the `region_id`.

0 commit comments

Comments
 (0)