18676: make v2 token check more strict, and add the ["GET /"] scope to
authorWard Vandewege <ward@curii.com>
Fri, 18 Feb 2022 13:34:02 +0000 (08:34 -0500)
committerWard Vandewege <ward@curii.com>
Fri, 18 Feb 2022 13:34:02 +0000 (08:34 -0500)
       the new anonymous token code path.

Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward@curii.com>

lib/config/load.go
services/api/app/models/api_client_authorization.rb

index 7136c60e468aa716af93ad6f011810287c5230e8..8d498af170f2180881fac496c82900b1bd764d7f 100644 (file)
@@ -358,7 +358,7 @@ func (ldr *Loader) checkToken(label, token string, mandatory bool, acceptV2 bool
                if len(tmp) != 3 {
                        return fmt.Errorf("%s: unacceptable characters in token (only a-z, A-Z, 0-9 are acceptable)", label)
                }
-               if strings.Index(token, "v2/") == -1 {
+               if !strings.HasPrefix(token, "v2/") {
                        return fmt.Errorf("%s: unacceptable characters in token (only a-z, A-Z, 0-9 are acceptable)", label)
                }
                ldr.Logger.Warnf("%s: token is a full V2 token, should just be a secret (remove everything up to and including the last forward slash)", label)
index f8454029d6b8cf2561505080ac5b74b8d57b8c70..c74c1ce5bf353a951e7c6ca076f2a4fd426f3038 100644 (file)
@@ -130,7 +130,8 @@ class ApiClientAuthorization < ArvadosModel
       return ApiClientAuthorization.new(user: User.find_by_uuid(anonymous_user_uuid),
                                         uuid: Rails.configuration.ClusterID+"-gj3su-anonymouspublic",
                                         api_token: token,
-                                        api_client: anonymous_user_token_api_client)
+                                        api_client: anonymous_user_token_api_client,
+                                        scopes: ['GET /'])
     else
       return nil
     end