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

Confusing bq_auth() selection choice and output #333

Closed
grantmcdermott opened this issue Jul 5, 2019 · 6 comments
Closed

Confusing bq_auth() selection choice and output #333

grantmcdermott opened this issue Jul 5, 2019 · 6 comments

Comments

@grantmcdermott
Copy link

I've just upgraded to version 1.2.0. of bigrquery, which uses the new gargle / bq_auth() authentication method. However, I struggled to authenticate correctly. Mostly because I kept selecting "Yes" (the normal default with these things) and I would just get an error message. Eventually, I tried selecting "No" on a whim and was taken through the browser authentication process.

I can't include standard reprex() output because of the interactive selection. (Apologies if there's a way that I missed.) But here is the output directly from my console.

Selecting "Yes" yields the following error message and some warnings.

> library(bigrquery)
> bq_auth()

1: Yes
2: No

Selection: 1
Error: Can't get Google credentials.
Are you running bigrquery in a non-interactive session? Consider:
  * Call `bq_auth()` directly with all necessary specifics.
In addition: Warning messages:
1: In file(txt) :
  'raw = FALSE' but '/home/grant/.config/gcloud' is not a regular file
2: In open.connection(con, "rb") :
  cannot open file '/home/grant/.config/gcloud': it is a directory

Selecting "No" works (I get taken to my browser for authentication), but still presents warning messages.

> library(bigrquery)
> bq_auth()

1: Yes
2: No

Selection: 2
Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Warning messages:
1: In file(txt) :
  'raw = FALSE' but '/home/grant/.config/gcloud' is not a regular file
2: In open.connection(con, "rb") :
  cannot open file '/home/grant/.config/gcloud': it is a directory

In summary:

  • Shouldn't bq_auth() give the user more detailed instructions than just "Yes" or "No". What exactly are we choosing here?
  • Similarly, why do I have to select "No" to get taken through the browser authentication process?
@jennybc
Copy link
Collaborator

jennybc commented Jul 5, 2019

I have never seen this.

The choice you're being asked to make should be clearly labelled, along the lines of this example in the gargle README:

#> The gargle package is requesting access to your Google account. Select a
#> pre-authorised account or enter '0' to obtain a new token. Press
#> Esc/Ctrl + C to abort.

#> 1: janedoe_personal@gmail.com
#> 2: janedoe@example.com

#> Selection: 1

But it looks like you've got some pre-existing gcloud config that's part of the story. Are you aware of that and you're trying to use creds stored there? Or were you expecting to do OAuth in the browser?

Can you set this option and try again? It should give us much more verbose output.

options(gargle_quiet = FALSE)

I'd also appreciate your session info.

@grantmcdermott
Copy link
Author

Thanks so much for the quick reply.

But it looks like you've got some pre-existing gcloud config that's part of the story.

Yes, I think that is likely the problem. (Although the missing choice message is still odd.) I have installed the gcloud command line utility, which I use to interact with VMs on Google Compute Engine among other things. Here are the files in my ~/.config/gcloud directory:

.  ..  cache  configurations  legacy_credentials  logs  access_tokens.db  active_config  config_sentinel  credentials.db  gce  .last_update_check.json

Separately, I've also previously downloaded an API service key as part of @MarkEdmondson1234's googleComputeEngineR package. However, I don't think that could be causing the problem, since this particular JSON file is not stored in the ~/.config/gcloud directory.

If it's any help at all, the full details of all of this are contained in my GCE lecture.

Or were you expecting to do OAuth in the browser?

Yes, that's what I was expecting although perhaps I should have been more specific given my existing setup?


Session info:

> sessionInfo()
R version 3.6.0 (2019-04-26)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Antergos Linux

Matrix products: default
BLAS/LAPACK: /usr/lib/libopenblas_haswellp-r0.3.6.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] bigrquery_1.2.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1       packrat_0.5.0    crayon_1.3.4     assertthat_0.2.1 R6_2.4.0         jsonlite_1.6    
 [7] DBI_1.0.0        pillar_1.4.2     httr_1.4.0       rlang_0.4.0      rstudioapi_0.10  tools_3.6.0     
[13] bit64_0.9-7      glue_1.3.1       bit_1.1-14       compiler_3.6.0   pkgconfig_2.0.2  tibble_2.1.3  

@grantmcdermott
Copy link
Author

Sorry, forgot to add the output with options(gargle_quiet = FALSE).

> options(gargle_quiet = FALSE)
> bq_auth()
trying token_fetch()
trying credentials_service_account()
Error: Argument 'txt' must be a JSON string, URL or file.
trying credentials_app_default()
file exists at ADC path: /home/grant/.config/gcloud
Error: cannot open the connection
trying credentials_gce()
trying credentials_byo_oauth()
Error: inherits(token, "Token2.0") is not TRUE
trying credentials_user_oauth2()
Gargle2.0 initialize
attempt from: bigrquery
adding 'userinfo.email' scope
Is it OK to cache OAuth access credentials in the folder '/home/grant/.R/gargle/gargle-oauth' between R sessions?

1: Yes
2: No

Selection: 1
Error: [EEXIST] Failed to make directory '/home/grant/.R/gargle/gargle-oauth': file already exists
Error: Can't get Google credentials.
Are you running bigrquery in a non-interactive session? Consider:
  * Call `bq_auth()` directly with all necessary specifics.
In addition: Warning messages:
1: In file(txt) :
  'raw = FALSE' but '/home/grant/.config/gcloud' is not a regular file
2: In open.connection(con, "rb") :
  cannot open file '/home/grant/.config/gcloud': it is a directory

@jennybc
Copy link
Collaborator

jennybc commented Jul 5, 2019

Aha! You are supposed to be seeing this question, when confronted with that "yes/ no":

Is it OK to cache OAuth access credentials in the folder '/home/grant/.R/gargle/gargle-oauth' between R sessions?

I think I've fixed it. If you're in a position to install gargle from GitHub and check me, that would be awesome. It does not contain any compiled code btw.

devtools::install_github("r-lib/gargle")

I don't really understand why your indicating 1: Yes didn't work initially, 🤔 even though you didn't know what you were consenting to. So we may have a second bug to work through.

@grantmcdermott
Copy link
Author

Super, thanks Jenny. That fixes the missing message problem.

I'm still not able to proceed when selecting 1: Yes, though. I haven't dug deep enough into gargle's code base yet. However, looking at my error message again...

Warning messages:
1: In file(txt) :
  'raw = FALSE' but '/home/grant/.config/gcloud' is not a regular file
2: In open.connection(con, "rb") :
  cannot open file '/home/grant/.config/gcloud': it is a directory

Is the idea that gargle will create / look for a regular cache file at ~/.config/gcloud? If so, then the error makes sense since ~/.config/gcloud already exists as a directory for me. Indeed, it was created when I first installed the gcloud CL tool IIRC. Moreover, if that's the case, then this same problem would crop up for anyone else who has previously installed gcloud.

Is the solution then simply for gargle to create / search the cache file within the directory? There's already a cache/ subdir in there...

~/.config/
   |_ gcloud/
      |_ cache/
         |_ xxxxxxxxxx@gmail.com/
            |_ resource.cache

@jennybc
Copy link
Collaborator

jennybc commented Jul 5, 2019

No, I think those messages are a red herring (and should be silenced). From your output, it looks like we cruise past them and successfully fall through to OAuth. I think the failure to create the cache folder, even though you've said "yes", is a separate problem. I will open two issues for these on gargle.

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