From 3e382dcd9440f6dcf7bc3b0ec041c7d3839c7c8c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:14:18 +0000 Subject: [PATCH] Bump github.com/gophercloud/gophercloud/v2 from 2.15.0 to 2.16.0 Bumps [github.com/gophercloud/gophercloud/v2](https://github.com/gophercloud/gophercloud) from 2.15.0 to 2.16.0. - [Release notes](https://github.com/gophercloud/gophercloud/releases) - [Changelog](https://github.com/gophercloud/gophercloud/blob/v2.16.0/CHANGELOG.md) - [Commits](https://github.com/gophercloud/gophercloud/compare/v2.15.0...v2.16.0) --- updated-dependencies: - dependency-name: github.com/gophercloud/gophercloud/v2 dependency-version: 2.16.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../gophercloud/gophercloud/v2/AGENTS.md | 7 + .../gophercloud/gophercloud/v2/CHANGELOG.md | 34 +++++ .../gophercloud/gophercloud/v2/Makefile | 6 +- .../gophercloud/v2/openstack/client.go | 72 ++++++++--- .../openstack/compute/v2/servers/results.go | 70 ++++++++++ .../openstack/identity/v2/tokens/results.go | 10 ++ .../identity/v3/ec2tokens/requests.go | 6 +- .../openstack/identity/v3/tokens/results.go | 10 ++ .../gophercloud/v2/provider_client.go | 121 +++++++++++++++++- vendor/modules.txt | 2 +- 12 files changed, 318 insertions(+), 26 deletions(-) diff --git a/go.mod b/go.mod index c44ecd1..ce5658d 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/BurntSushi/toml v1.6.0 github.com/cloudbase/garm-provider-common v0.1.10-0.20261111212522-a63fbe8afd51 github.com/google/uuid v1.6.0 - github.com/gophercloud/gophercloud/v2 v2.15.0 + github.com/gophercloud/gophercloud/v2 v2.16.0 github.com/gophercloud/utils/v2 v2.0.0-20260626221802-4ae35253ac13 github.com/invopop/jsonschema v0.14.0 github.com/stretchr/testify v1.12.1 diff --git a/go.sum b/go.sum index bd37f69..ee5c688 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/gofrs/uuid/v5 v5.4.0 h1:EfbpCTjqMuGyq5ZJwxqzn3Cbr2d0rUZU7v5ycAk/e/0= github.com/gofrs/uuid/v5 v5.4.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gophercloud/gophercloud/v2 v2.15.0 h1:4zLiLYTFraZMlJ77FH1Kzq7itjfVP+BIbWcCurCrgic= -github.com/gophercloud/gophercloud/v2 v2.15.0/go.mod h1:4fs5I9VH6Wg2LyocDL9xf0ASb8VD63tyLA8sgAX/69U= +github.com/gophercloud/gophercloud/v2 v2.16.0 h1:qhQKoU5mNX8hp4YVN5eks8Y6zFFlBAMYCu55Fc+tGkc= +github.com/gophercloud/gophercloud/v2 v2.16.0/go.mod h1:4fs5I9VH6Wg2LyocDL9xf0ASb8VD63tyLA8sgAX/69U= github.com/gophercloud/utils/v2 v2.0.0-20260626221802-4ae35253ac13 h1:Dnid+JYEmkqPWw/vJHRUzZsjO3mdoyCRo2l5UYCqh8k= github.com/gophercloud/utils/v2 v2.0.0-20260626221802-4ae35253ac13/go.mod h1:zpDKeT3ElgCs1UA+7B8+XlDu3R+jkK/CBC1di5qOeow= github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE= diff --git a/vendor/github.com/gophercloud/gophercloud/v2/AGENTS.md b/vendor/github.com/gophercloud/gophercloud/v2/AGENTS.md index 1b5a205..7528006 100644 --- a/vendor/github.com/gophercloud/gophercloud/v2/AGENTS.md +++ b/vendor/github.com/gophercloud/gophercloud/v2/AGENTS.md @@ -120,6 +120,13 @@ func (opts CreateOpts) ToServerCreateMap() (map[string]interface{}, error) { - **Optional request fields:** Always use `omitempty` JSON tag - **Required fields:** No `omitempty` tag +### Timestamps & Timezones + +- Verify timestamp formats and timezone semantics against the relevant OpenStack API documentation or implementation before adding serialization. +- For fields representing an instant, accept non-UTC `time.Time` inputs without shifting that instant. If the API requires UTC clock values without an offset or with a literal `Z`, use `timestamp.UTC().Format(layout)`. Formatting alone does not convert the timezone. +- Follow the API's requirements for offset-bearing timestamps and calendar dates; do not apply blanket UTC conversion. +- Preserve API-specific precision and nil/zero handling. Do not mutate caller-owned timestamps or change shared layout constants to fix a service-specific serialization issue. + ### Error Handling - Use `gophercloud.Result` and `gophercloud.ErrResult` types diff --git a/vendor/github.com/gophercloud/gophercloud/v2/CHANGELOG.md b/vendor/github.com/gophercloud/gophercloud/v2/CHANGELOG.md index 9bd4237..d9055d2 100644 --- a/vendor/github.com/gophercloud/gophercloud/v2/CHANGELOG.md +++ b/vendor/github.com/gophercloud/gophercloud/v2/CHANGELOG.md @@ -1,3 +1,37 @@ +## v2.16.0 (2026-11-13) + +* [GH-4026](https://github.com/gophercloud/gophercloud/pull/4026) build(deps): bump the all-github-actions group with 3 updates +* [GH-4032](https://github.com/gophercloud/gophercloud/pull/4032) [v2] reservation: add leases resources +* [GH-4033](https://github.com/gophercloud/gophercloud/pull/4033) build(deps): bump the all-github-actions group with 3 updates +* [GH-4034](https://github.com/gophercloud/gophercloud/pull/4034) [v2] Add the Security Group for Virtual IP +* [GH-4036](https://github.com/gophercloud/gophercloud/pull/4036) build(deps): bump the all-github-actions group with 3 updates +* [GH-4043](https://github.com/gophercloud/gophercloud/pull/4043) [v2] identity: compare blob values instead of the literal string +* [GH-4045](https://github.com/gophercloud/gophercloud/pull/4045) [v2] reservation: start a lease now when StartDate is zero +* [GH-4046](https://github.com/gophercloud/gophercloud/pull/4046) [v2] reservation: add host allocations and resource properties +* [GH-4048](https://github.com/gophercloud/gophercloud/pull/4048) [v2] fix(config/clouds): find the clouds config file independently of each… +* [GH-4049](https://github.com/gophercloud/gophercloud/pull/4049) [v2] Return early on initClientOpts error in service client constructors +* [GH-4050](https://github.com/gophercloud/gophercloud/pull/4050) [v2] openstack: don't add version suffix to versioned endpoints +* [GH-4051](https://github.com/gophercloud/gophercloud/pull/4051) build(deps): bump the all-github-actions group with 5 updates +* [GH-4055](https://github.com/gophercloud/gophercloud/pull/4055) [v2] identity: fix role assignment to target domain +* [GH-4057](https://github.com/gophercloud/gophercloud/pull/4057) [v2] db: change functional tests to accept common configs +* [GH-4060](https://github.com/gophercloud/gophercloud/pull/4060) build(deps): bump the all-github-actions group with 3 updates +* [GH-4062](https://github.com/gophercloud/gophercloud/pull/4062) [v2] networking/v2/fwaas_v2: add created_at and updated_at +* [GH-4065](https://github.com/gophercloud/gophercloud/pull/4065) CI: Update tag comments +* [GH-4066](https://github.com/gophercloud/gophercloud/pull/4066) [v2] ci: add hibiscus release, drop epoxy +* [GH-4071](https://github.com/gophercloud/gophercloud/pull/4071) [v2] networking/v2/attributestags: escape the tag in the URL +* [GH-4073](https://github.com/gophercloud/gophercloud/pull/4073) [v2] Conditionally set `OS_SYSTEM_SCOPE` through env instead of openrc +* [GH-4078](https://github.com/gophercloud/gophercloud/pull/4078) build(deps): bump the all-github-actions group across 1 directory with 4 updates +* [GH-4081](https://github.com/gophercloud/gophercloud/pull/4081) [v2] Normalize timestamp serialization to UTC +* [GH-4083](https://github.com/gophercloud/gophercloud/pull/4083) [v2] Do not send X-Auth-Token on a redirect to another origin +* [GH-4084](https://github.com/gophercloud/gophercloud/pull/4084) [v2] Added support for baremetal portgroups +* [GH-4085](https://github.com/gophercloud/gophercloud/pull/4085) [v2] baremetal: follow the next link when listing +* [GH-4086](https://github.com/gophercloud/gophercloud/pull/4086) [v2] Add Ironic runbooks API +* [GH-4089](https://github.com/gophercloud/gophercloud/pull/4089) [v2] networking/v2/qos: add minimum packet rate and packet rate limit rules +* [GH-4092](https://github.com/gophercloud/gophercloud/pull/4092) [v2] Add read-only Masakari Instance HA API support +* [GH-4093](https://github.com/gophercloud/gophercloud/pull/4093) [v2] Reauthenticate before token expires +* [GH-4094](https://github.com/gophercloud/gophercloud/pull/4094) [v2] Fix semver comparison baseline +* [GH-4095](https://github.com/gophercloud/gophercloud/pull/4095) [v2] compute: stop re-decoding server list pages in IsEmpty and NextPageURL + ## v2.15.0 (2026-09-18) * [GH-3980](https://github.com/gophercloud/gophercloud/pull/3980) [v2] fix(config/clouds): resolve reference to clouds-public.yaml diff --git a/vendor/github.com/gophercloud/gophercloud/v2/Makefile b/vendor/github.com/gophercloud/gophercloud/v2/Makefile index 56281dc..bf69afd 100644 --- a/vendor/github.com/gophercloud/gophercloud/v2/Makefile +++ b/vendor/github.com/gophercloud/gophercloud/v2/Makefile @@ -43,7 +43,7 @@ coverage: $(GO_TEST) -shuffle on -covermode count -coverprofile cover.out -coverpkg=./... ./... .PHONY: coverage -acceptance: acceptance-basic acceptance-baremetal acceptance-blockstorage acceptance-compute acceptance-container acceptance-containerinfra acceptance-db acceptance-dns acceptance-identity acceptance-image acceptance-keymanager acceptance-loadbalancer acceptance-messaging acceptance-metric acceptance-networking acceptance-objectstorage acceptance-orchestration acceptance-placement acceptance-reservation acceptance-sharedfilesystems acceptance-workflow +acceptance: acceptance-basic acceptance-baremetal acceptance-blockstorage acceptance-compute acceptance-container acceptance-containerinfra acceptance-db acceptance-dns acceptance-identity acceptance-image acceptance-instanceha acceptance-keymanager acceptance-loadbalancer acceptance-messaging acceptance-metric acceptance-networking acceptance-objectstorage acceptance-orchestration acceptance-placement acceptance-reservation acceptance-sharedfilesystems acceptance-workflow .PHONY: acceptance acceptance-basic: @@ -90,6 +90,10 @@ acceptance-image: $(GO_TEST) -timeout $(TIMEOUT) -tags "fixtures acceptance" ./internal/acceptance/openstack/image/... .PHONY: acceptance-image +acceptance-instanceha: + $(GO_TEST) -timeout $(TIMEOUT) -tags "fixtures acceptance" ./internal/acceptance/openstack/instanceha/... +.PHONY: acceptance-instanceha + acceptance-keymanager: $(GO_TEST) -timeout $(TIMEOUT) -tags "fixtures acceptance" ./internal/acceptance/openstack/keymanager/... .PHONY: acceptance-keymanager diff --git a/vendor/github.com/gophercloud/gophercloud/v2/openstack/client.go b/vendor/github.com/gophercloud/gophercloud/v2/openstack/client.go index e1bfa3e..b752ea9 100644 --- a/vendor/github.com/gophercloud/gophercloud/v2/openstack/client.go +++ b/vendor/github.com/gophercloud/gophercloud/v2/openstack/client.go @@ -366,14 +366,26 @@ func initClientOpts(client *gophercloud.ProviderClient, eo gophercloud.EndpointO return sc, nil } +// resourceBase returns the endpoint with the given version path appended, +// unless the endpoint already ends with that version path. This avoids +// building URLs such as ".../v2/v2/" when the service catalog publishes an +// already-versioned endpoint. +func resourceBase(endpoint, version string) string { + if strings.HasSuffix(strings.TrimSuffix(endpoint, "/"), "/"+version) { + return endpoint + } + return endpoint + version + "/" +} + // NewBareMetalV1 creates a ServiceClient that may be used with the v1 // bare metal package. func NewBareMetalV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { sc, err := initClientOpts(client, eo, "baremetal", 1) - if !strings.HasSuffix(strings.TrimSuffix(sc.Endpoint, "/"), "v1") { - sc.ResourceBase = sc.Endpoint + "v1/" + if err != nil { + return sc, err } - return sc, err + sc.ResourceBase = resourceBase(sc.Endpoint, "v1") + return sc, nil } // NewBareMetalIntrospectionV1 creates a ServiceClient that may be used with the v1 @@ -398,8 +410,11 @@ func NewComputeV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpt // package. func NewNetworkV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { sc, err := initClientOpts(client, eo, "network", 2) - sc.ResourceBase = sc.Endpoint + "v2.0/" - return sc, err + if err != nil { + return sc, err + } + sc.ResourceBase = resourceBase(sc.Endpoint, "v2.0") + return sc, nil } // TODO(stephenfin): Remove this in v3. We no longer support the V1 Block Storage service. @@ -440,44 +455,59 @@ func NewDBV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (* // service. func NewDNSV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { sc, err := initClientOpts(client, eo, "dns", 2) - sc.ResourceBase = sc.Endpoint + "v2/" - return sc, err + if err != nil { + return sc, err + } + sc.ResourceBase = resourceBase(sc.Endpoint, "v2") + return sc, nil } // NewImageV2 creates a ServiceClient that may be used to access the v2 image // service. func NewImageV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { sc, err := initClientOpts(client, eo, "image", 2) - sc.ResourceBase = sc.Endpoint + "v2/" - return sc, err + if err != nil { + return sc, err + } + sc.ResourceBase = resourceBase(sc.Endpoint, "v2") + return sc, nil } // NewLoadBalancerV2 creates a ServiceClient that may be used to access the v2 // load balancer service. func NewLoadBalancerV2(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { sc, err := initClientOpts(client, eo, "load-balancer", 2) + if err != nil { + return sc, err + } // Fixes edge case having an OpenStack lb endpoint with trailing version number. endpoint := strings.ReplaceAll(sc.Endpoint, "v2.0/", "") sc.ResourceBase = endpoint + "v2.0/" - return sc, err + return sc, nil } // NewMetricV1 creates a ServiceClient that may be used with the v1 metric-storage // service (Aetos). func NewMetricV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { sc, err := initClientOpts(client, eo, "metric-storage", 1) - sc.ResourceBase = sc.Endpoint + "api/v1/" - return sc, err + if err != nil { + return sc, err + } + sc.ResourceBase = resourceBase(sc.Endpoint, "api/v1") + return sc, nil } // NewMessagingV2 creates a ServiceClient that may be used with the v2 messaging // service. func NewMessagingV2(client *gophercloud.ProviderClient, clientID string, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { sc, err := initClientOpts(client, eo, "message", 2) + if err != nil { + return sc, err + } sc.MoreHeaders = map[string]string{"Client-ID": clientID} - return sc, err + return sc, nil } // NewContainerV1 creates a ServiceClient that may be used with v1 container package @@ -489,8 +519,11 @@ func NewContainerV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointO // manager service. func NewKeyManagerV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { sc, err := initClientOpts(client, eo, "key-manager", 1) - sc.ResourceBase = sc.Endpoint + "v1/" - return sc, err + if err != nil { + return sc, err + } + sc.ResourceBase = resourceBase(sc.Endpoint, "v1") + return sc, nil } // NewContainerInfraV1 creates a ServiceClient that may be used with the v1 container infra management @@ -509,14 +542,17 @@ func NewPlacementV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointO return initClientOpts(client, eo, "placement", 1) } +// NewInstanceHAV1 creates a client for the Masakari instance-ha v1 API. +func NewInstanceHAV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { + return initClientOpts(client, eo, "instance-ha", 1) +} + // NewReservationV1 creates a ServiceClient that may be used with the reservation package. func NewReservationV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) { sc, err := initClientOpts(client, eo, "reservation", 1) if err != nil { return sc, err } - if !strings.HasSuffix(strings.TrimSuffix(sc.Endpoint, "/"), "v1") { - sc.ResourceBase = sc.Endpoint + "v1/" - } + sc.ResourceBase = resourceBase(sc.Endpoint, "v1") return sc, nil } diff --git a/vendor/github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers/results.go b/vendor/github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers/results.go index b11b9b2..73210c2 100644 --- a/vendor/github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers/results.go +++ b/vendor/github.com/gophercloud/gophercloud/v2/openstack/compute/v2/servers/results.go @@ -436,6 +436,17 @@ func (r ServerPage) IsEmpty() (bool, error) { return true, nil } + if r.Err != nil { + return true, r.Err + } + + // Body is already decoded by pagination.PageResultFrom; avoid re-encoding it. + if body, ok := r.Body.(map[string]any); ok { + if n, ok := decodedServerCount(body["servers"]); ok { + return n == 0, nil + } + } + s, err := ExtractServers(r) return len(s) == 0, err } @@ -443,6 +454,16 @@ func (r ServerPage) IsEmpty() (bool, error) { // NextPageURL uses the response's embedded link reference to navigate to the // next page of results. func (r ServerPage) NextPageURL() (string, error) { + if r.Err != nil { + return "", r.Err + } + + if body, ok := r.Body.(map[string]any); ok { + if links, ok := decodedServerLinks(body["servers_links"]); ok { + return gophercloud.ExtractNextURL(links) + } + } + var s struct { Links []gophercloud.Link `json:"servers_links"` } @@ -453,6 +474,55 @@ func (r ServerPage) NextPageURL() (string, error) { return gophercloud.ExtractNextURL(s.Links) } +// decodedServerCount counts the servers in an already decoded body. It only +// checks that servers is a list of objects and does not validate the fields of +// each server; a type mismatch inside a server surfaces from ExtractServers. +// The second return is false when the value needs the generic decode path, +// which also reports its errors. +func decodedServerCount(raw any) (int, bool) { + items, ok := raw.([]any) + if !ok { + return 0, false + } + + for _, item := range items { + if _, ok := item.(map[string]any); !ok { + return 0, false + } + } + return len(items), true +} + +// decodedServerLinks reads servers_links from an already decoded body. The +// second return is false when the value needs the generic decode path. +func decodedServerLinks(raw any) ([]gophercloud.Link, bool) { + if raw == nil { + return nil, true + } + + items, ok := raw.([]any) + if !ok { + return nil, false + } + + links := make([]gophercloud.Link, 0, len(items)) + for _, item := range items { + m, ok := item.(map[string]any) + if !ok { + return nil, false + } + + href, hrefOK := m["href"].(string) + rel, relOK := m["rel"].(string) + if !hrefOK || !relOK { + return nil, false + } + + links = append(links, gophercloud.Link{Href: href, Rel: rel}) + } + return links, true +} + // ExtractServers interprets the results of a single page from a List() call, // producing a slice of Server entities. func ExtractServers(r pagination.Page) ([]Server, error) { diff --git a/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v2/tokens/results.go b/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v2/tokens/results.go index 516371e..b5c0972 100644 --- a/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v2/tokens/results.go +++ b/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v2/tokens/results.go @@ -135,6 +135,16 @@ func (r CreateResult) ExtractToken() (*Token, error) { }, nil } +// TokenExpiry returns the timestamp at which the token in this result expires, +// or the zero time if the token is unknown. +func (r CreateResult) TokenExpiry() time.Time { + token, err := r.ExtractToken() + if err != nil { + return time.Time{} + } + return token.ExpiresAt +} + // ExtractTokenID implements the gophercloud.AuthResult interface. The returned // string is the same as the ID field of the Token struct returned from // ExtractToken(). diff --git a/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v3/ec2tokens/requests.go b/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v3/ec2tokens/requests.go index 1d4cb54..e1a13cf 100644 --- a/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v3/ec2tokens/requests.go +++ b/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v3/ec2tokens/requests.go @@ -72,6 +72,7 @@ type AuthOptions struct { // is not set, a random hash is generated. Optional. BodyHash *string `json:"body_hash"` // Timestamp is a timestamp to calculate a V4 signature. Optional. + // It is converted to UTC for signing. Timestamp *time.Time `json:"-"` // Token is a []byte string (encoded to base64 automatically) which was // signed by an EC2 secret key. Used by S3 tokens for validation only. @@ -147,6 +148,7 @@ func EC2CredentialsBuildCanonicalHeadersV4(headers map[string]string, signedHead // input parameters. // https://github.com/openstack/python-keystoneclient/blob/stable/train/keystoneclient/contrib/ec2/utils.py#L169 func EC2CredentialsBuildSignatureKeyV4(secret, region, service string, date time.Time) []byte { + date = date.UTC() kDate := sumHMAC256([]byte("AWS4"+secret), []byte(date.Format(EC2CredentialsDateFormatV4))) kRegion := sumHMAC256(kDate, []byte(region)) kService := sumHMAC256(kRegion, []byte(service)) @@ -157,6 +159,7 @@ func EC2CredentialsBuildSignatureKeyV4(secret, region, service string, date time // based on input parameters. // https://github.com/openstack/python-keystoneclient/blob/stable/train/keystoneclient/contrib/ec2/utils.py#L251 func EC2CredentialsBuildStringToSignV4(opts AuthOptions, signedHeaders string, bodyHash string, date time.Time) []byte { + date = date.UTC() scope := strings.Join([]string{ date.Format(EC2CredentialsDateFormatV4), opts.Region, @@ -192,6 +195,7 @@ func EC2CredentialsBuildSignatureV4(key []byte, stringToSign []byte) string { // EC2CredentialsBuildAuthorizationHeaderV4 builds an AWS v4 Authorization // header based on auth parameters, date and signature func EC2CredentialsBuildAuthorizationHeaderV4(opts AuthOptions, signedHeaders string, signature string, date time.Time) string { + date = date.UTC() return fmt.Sprintf("%s Credential=%s/%s/%s/%s/%s, SignedHeaders=%s, Signature=%s", EC2CredentialsAwsHmacV4, opts.Access, @@ -263,7 +267,7 @@ func (opts *AuthOptions) ToTokenV3CreateMap(map[string]any) (map[string]any, err // it is not a signature v2, but a signature v4 date := time.Now().UTC() if opts.Timestamp != nil { - date = *opts.Timestamp + date = opts.Timestamp.UTC() } if v := c["body_hash"]; v == nil { // when body_hash is not set, generate a random one diff --git a/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v3/tokens/results.go b/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v3/tokens/results.go index bd61a9a..e9b2488 100644 --- a/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v3/tokens/results.go +++ b/vendor/github.com/gophercloud/gophercloud/v2/openstack/identity/v3/tokens/results.go @@ -210,6 +210,16 @@ type Token struct { ExpiresAt time.Time `json:"expires_at"` } +// TokenExpiry returns the timestamp at which the token in this result expires, +// or the zero time if the token is unknown. +func (r commonResult) TokenExpiry() time.Time { + token, err := r.ExtractToken() + if err != nil { + return time.Time{} + } + return token.ExpiresAt +} + func (r commonResult) ExtractInto(v any) error { return r.ExtractIntoStructPtr(v, "token") } diff --git a/vendor/github.com/gophercloud/gophercloud/v2/provider_client.go b/vendor/github.com/gophercloud/gophercloud/v2/provider_client.go index 5310de3..6f1a0ed 100644 --- a/vendor/github.com/gophercloud/gophercloud/v2/provider_client.go +++ b/vendor/github.com/gophercloud/gophercloud/v2/provider_client.go @@ -7,14 +7,16 @@ import ( "errors" "io" "net/http" + "net/url" "slices" "strings" "sync" + "time" ) // DefaultUserAgent is the default User-Agent string set in the request header. const ( - DefaultUserAgent = "gophercloud/v2.15.0" + DefaultUserAgent = "gophercloud/v2.16.0" DefaultMaxBackoffRetries = 60 ) @@ -84,6 +86,20 @@ type ProviderClient struct { // authentication functions for different Identity service versions. ReauthFunc func(context.Context) error + // ReauthBeforeTokenExpiration specifies how long before the token expires + // the client should reauthenticate proactively, before issuing a request + // that would carry the expiring token. If non-zero and the token's + // expiration time is known, a request made within this window of the + // expiration triggers ReauthFunc before it is sent. If the + // reauthentication fails, the request proceeds with the current token and + // a 401 response triggers the existing reauth-and-retry behavior. A zero + // value disables proactive reauthentication. + // + // Proactive reauthentication is only active when ReauthFunc is set. The + // margin should be smaller than the token lifetime; otherwise every + // request triggers a reauthentication. + ReauthBeforeTokenExpiration time.Duration + // Throwaway determines whether if this client is a throw-away client. It's a copy of user's provider client // with the token and reauth func zeroed. Such client can be used to perform reauthorization. Throwaway bool @@ -107,6 +123,11 @@ type ProviderClient struct { reauthmut *reauthlock authResult AuthResult + + // tokenExpiry is the expiration time of the currently cached token, if + // known. It is populated from the AuthResult when the result exposes the + // token's expiration. + tokenExpiry time.Time } // reauthlock represents a set of attributes used to help in the reauthentication process. @@ -170,6 +191,17 @@ func (client *ProviderClient) authenticatedHeaders(ctx context.Context) (map[str if t == "" { return nil, nil } + if client.ReauthFunc != nil && client.ReauthBeforeTokenExpiration > 0 { + if expiry := client.TokenExpiry(); !expiry.IsZero() && !time.Now().Add(client.ReauthBeforeTokenExpiration).Before(expiry) { + // The token expires within the margin (or already did): reauthenticate + // before sending. If the reauthentication fails, proceed with the + // current token; a 401 response triggers the existing reauth-and-retry + // behavior. + if err := client.Reauthenticate(ctx, t); err == nil { + t = client.Token() + } + } + } return map[string]string{"X-Auth-Token": t}, nil } @@ -204,6 +236,16 @@ func (client *ProviderClient) Token() string { return client.TokenID } +// TokenExpiry safely returns the expiration time of the cached token, or the +// zero time if it is unknown. +func (client *ProviderClient) TokenExpiry() time.Time { + if client.mut != nil { + client.mut.RLock() + defer client.mut.RUnlock() + } + return client.tokenExpiry +} + // SetToken safely sets the value of the auth token in the ProviderClient. Applications may // use this method in a custom ReauthFunc. // @@ -215,6 +257,7 @@ func (client *ProviderClient) SetToken(t string) { } client.TokenID = t client.authResult = nil + client.tokenExpiry = time.Time{} } // SetTokenAndAuthResult safely sets the value of the auth token in the @@ -236,6 +279,10 @@ func (client *ProviderClient) SetTokenAndAuthResult(r AuthResult) error { } client.TokenID = tokenID client.authResult = r + client.tokenExpiry = time.Time{} + if e, ok := r.(interface{ TokenExpiry() time.Time }); ok { + client.tokenExpiry = e.TokenExpiry() + } return nil } @@ -252,6 +299,7 @@ func (client *ProviderClient) CopyTokenFrom(other *ProviderClient) { } client.TokenID = other.TokenID client.authResult = other.authResult + client.tokenExpiry = other.tokenExpiry } // IsThrowaway safely reads the value of the client Throwaway field. @@ -365,6 +413,75 @@ func (client *ProviderClient) Request(ctx context.Context, method, url string, o }) } +// httpClientForRequest returns a copy of client.HTTPClient to issue one request +// with. When the caller has not set a redirect policy, the copy gets +// stripTokenOnCrossOriginRedirect, so the token never travels to another +// origin than the one it was sent to. A CheckRedirect set by the caller is +// used as is. +func (client *ProviderClient) httpClientForRequest() *http.Client { + httpClient := client.HTTPClient + if httpClient.CheckRedirect == nil { + httpClient.CheckRedirect = stripTokenOnCrossOriginRedirect + } + return &httpClient +} + +// stripTokenOnCrossOriginRedirect is the redirect policy applied when the +// caller sets none. It keeps net/http's limit of ten redirects and follows +// every redirect, but a redirect to another origin (scheme, host or port) +// than the original request goes out without X-Auth-Token. +// +// net/http removes Authorization on a cross-host redirect by itself and knows +// nothing about the OpenStack token header. Without this policy a redirect +// from a configured endpoint, for example from a proxy or load balancer +// rewrite, a lapsed DNS name a service still redirects to, or an https to +// http downgrade, hands the token to whatever host the Location header +// names. The original request is the reference, so a chain that leaves the +// origin and comes back does not regain the token. +func stripTokenOnCrossOriginRedirect(req *http.Request, via []*http.Request) error { + if len(via) >= 10 { + return errors.New("stopped after 10 redirects") + } + if leftOrigin(via, req) { + req.Header.Del("X-Auth-Token") + } + return nil +} + +// leftOrigin reports whether req, or any redirect before it, is on another +// origin than the original request. net/http rebuilds every redirected +// request from the original one, so once a chain has left the origin the +// token must stay off even on a hop that comes back. +func leftOrigin(via []*http.Request, req *http.Request) bool { + origin := via[0].URL + for _, hop := range via[1:] { + if !sameOrigin(origin, hop.URL) { + return true + } + } + return !sameOrigin(origin, req.URL) +} + +// sameOrigin reports whether two URLs share scheme, host and effective port. +func sameOrigin(a, b *url.URL) bool { + return strings.EqualFold(a.Scheme, b.Scheme) && + strings.EqualFold(a.Hostname(), b.Hostname()) && + portOrDefault(a) == portOrDefault(b) +} + +func portOrDefault(u *url.URL) string { + if port := u.Port(); port != "" { + return port + } + switch strings.ToLower(u.Scheme) { + case "http": + return "80" + case "https": + return "443" + } + return "" +} + func (client *ProviderClient) doRequest(ctx context.Context, method, url string, options *RequestOpts, state *requestState) (*http.Response, error) { var body io.Reader var contentType *string @@ -432,7 +549,7 @@ func (client *ProviderClient) doRequest(ctx context.Context, method, url string, prereqtok := req.Header.Get("X-Auth-Token") // Issue the request. - resp, err := client.HTTPClient.Do(req) + resp, err := client.httpClientForRequest().Do(req) if err != nil { if client.RetryFunc != nil { var e error diff --git a/vendor/modules.txt b/vendor/modules.txt index a78519a..c3b8785 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -28,7 +28,7 @@ github.com/gofrs/uuid/v5 # github.com/google/uuid v1.6.0 ## explicit github.com/google/uuid -# github.com/gophercloud/gophercloud/v2 v2.15.0 +# github.com/gophercloud/gophercloud/v2 v2.16.0 ## explicit; go 1.25.0 github.com/gophercloud/gophercloud/v2 github.com/gophercloud/gophercloud/v2/openstack