Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/vsiswift/: expiration of SWIFT_AUTH_TOKEN doesn't make RasterIO() to fail #2239

Closed
talaj opened this issue Feb 13, 2020 · 4 comments
Closed

Comments

@talaj
Copy link
Contributor

talaj commented Feb 13, 2020

Expected behavior and actual behavior.

When SWIFT_AUTH_TOKEN expire, swift begins to return 401.
This behavior is documented here:
https://docs.openstack.org/swift/queens/api/authentication.html

In such case I would expect RasterIO() call to fail so user can handle it somehow.
Instead the call silently returns empty data.

With debugging on, I can see

VSICURL: Got response_code=401

which comes from here:

CPLDebug("VSICURL", "Got response_code=%ld", response_code);

I don't see any error handling in VSICurlHandle::DownloadRegion, it just returns empty string.

Steps to reproduce the problem.

Either it is possible to wait a day to let the token expire, or it is possible to make a small change to code to take the token always from config map, when constructing headers. It is then possible to change the token to invalid one.

diff --git a/gdal/port/cpl_swift.cpp b/gdal/port/cpl_swift.cpp
index 45155ac5d3..30662b63a5 100644
--- a/gdal/port/cpl_swift.cpp
+++ b/gdal/port/cpl_swift.cpp
@@ -52,13 +52,14 @@ static CPLString g_osLastAuthToken;
 /************************************************************************/

 static
-struct curl_slist* GetSwiftHeaders( const CPLString& osAuthToken )
+struct curl_slist* GetSwiftHeaders( const CPLString& )
 {
     struct curl_slist *headers=nullptr;
     headers = curl_slist_append(
         headers, "Accept: application/json");
+    const char * osAuthToken = CPLGetConfigOption("SWIFT_AUTH_TOKEN", "");
     headers = curl_slist_append(
-        headers, CPLSPrintf("x-auth-token: %s", osAuthToken.c_str()));
+        headers, CPLSPrintf("x-auth-token: %s", osAuthToken));
     return headers;
 }

Operating system

Debian Buster

GDAL version and provenance

The latest master from github.

@rouault
Copy link
Member

rouault commented Feb 13, 2020

A more appropriate / general fix would be to handle token expiration, and re-issue a request for a token for the case where the user doesn't provide SWIFT_AUTH_TOKEN, but uses SWIFT_AUTH_V1_URL + SWIFT_USER + SWIFT_KEY

@talaj
Copy link
Contributor Author

talaj commented Feb 13, 2020

I'm willing to implement the refresh of the token by SWIFT_AUTH_V1_URL. I would also like to add V3 interface for authentication.
If you would have some tips where to put the code that would be much appreciated.

@rouault
Copy link
Member

rouault commented Feb 13, 2020

port/cpl_swift.cpp for authentication logic and port/cpl_vsil_swift.cpp for virtual file system logic.

For the refresh, there is some logic in port/cpl_aws.cpp (which may not work according to #1593 (comment)). Not completely sure if that can help or is a model for inspiration

@rouault
Copy link
Member

rouault commented Mar 9, 2020

Fixed per #2296

@rouault rouault closed this as completed Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants