pachadotdev / analogsea

Digital Ocean R client
https://pacha.dev/analogsea/
Apache License 2.0
154 stars 24 forks source link

analogsea::key_create results in "Error: Key can't be blank" #215

Closed mnr closed 1 year ago

mnr commented 2 years ago

System details

Output of sessioninfo::session_info()():

─ Session info ──────────────────────────────────────────────────────
 setting  value
 version  R version 4.1.1 (2021-08-10)
 os       macOS Monterey 12.5.1
 system   x86_64, darwin17.0
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Los_Angeles
 date     2022-08-22
 rstudio  2022.07.1+554 Spotted Wakerobin (desktop)
 pandoc   NA

─ Packages ──────────────────────────────────────────────────────────
 ! package       * version date (UTC) lib source
   analogsea       1.0.6   2022-05-08 [1] CRAN (R 4.1.2)
   askpass         1.1     2019-01-13 [1] CRAN (R 4.1.0)
   callr           3.7.0   2021-04-20 [1] CRAN (R 4.1.0)
   cli             3.1.1   2022-01-20 [1] CRAN (R 4.1.2)
   crayon          1.5.1   2022-03-26 [1] CRAN (R 4.1.2)
   curl            4.3.2   2021-06-23 [1] CRAN (R 4.1.0)
   httr            1.4.2   2020-07-20 [1] CRAN (R 4.1.0)
 V jsonlite        1.7.2   2022-02-22 [1] CRAN (R 4.1.2) (on disk 1.8.0)
 V magrittr        2.0.1   2022-03-30 [1] CRAN (R 4.1.2) (on disk 2.0.3)
   openssl         1.4.5   2021-09-02 [1] CRAN (R 4.1.0)
   pkgbuild        1.3.1   2021-12-20 [1] CRAN (R 4.1.0)
   plumberDeploy * 0.2.1   2021-03-22 [1] CRAN (R 4.1.0)
   prettyunits     1.1.1   2020-01-24 [1] CRAN (R 4.1.0)
   processx        3.5.2   2021-04-30 [1] CRAN (R 4.1.0)
   ps              1.6.0   2021-02-28 [1] CRAN (R 4.1.0)
   R6              2.5.1   2021-08-19 [1] CRAN (R 4.1.0)
   remotes         2.4.2   2021-11-30 [1] CRAN (R 4.1.0)
   rprojroot       2.0.2   2020-11-15 [1] CRAN (R 4.1.0)
   rstudioapi      0.13    2020-11-12 [1] CRAN (R 4.1.0)
   sessioninfo     1.2.2   2021-12-06 [1] CRAN (R 4.1.0)
   withr           2.4.3   2021-11-30 [1] CRAN (R 4.1.0)
   yaml            2.2.1   2020-02-01 [1] CRAN (R 4.1.0)

 [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library

Example application or steps to reproduce the problem

install plumber deploy install.packages("plumberDeploy") I also tried... remotes::install_github("rstudio/plumber") then... library(plumberDeploy)

analogsea::account() # validate

plumbSSHKey <- analogsea::key_create("plumberSSH", readLines("~/.ssh/id_rsa.pub"))

which results in .... Error: Key can't be blank

I've confirmed readLines("~/.ssh/id_rsa.pub") returns a valid SSH key

Describe the problem in detail

Trying to create an SSH key results in error: key can't be blank

mnr commented 2 years ago

Originally posted to @meztez in plumberDeploy repo. @ghstreamline suggests posting here.

pachadotdev commented 2 years ago

Hi @mnr ! Thanks for reporting. Are you trying to add a key to a droplet?

mnr commented 2 years ago

I don't believe I've created a droplet just yet. I'm just trying to set up to deploy a plumber instance. I'm following the procedure outlined at https://github.com/meztez/plumberDeploy. Step three is to configure an ssh key for the Digital Ocean account using analogsea::key_create.

Step 4 is to use analogsea::droplets() - but I haven't gotten there yet.

pachadotdev commented 2 years ago

hi @mnr just to be triple sure, did you add your public ssh key to the project you are working with on digitalocean? can you please send me a minimal example of what you did?

mnr commented 2 years ago

I have not set up an SSH key with digital ocean. let me try that first, then see if things change.

In the meantime, here is the code I am running. It's in R...

install.packages("plumberDeploy")
remotes::install_github("rstudio/plumber")
library(plumberDeploy)
analogsea::account()
plumbSSHKey <- analogsea::key_create("plumberSSH", readLines("~/.ssh/id_rsa.pub"))
mnr commented 2 years ago

I've set up an SSH key as detailed at https://cloud.digitalocean.com/ssh_keys. Subsequently running the above code still results in "Error: Key can't be blank"

mnr commented 2 years ago

I'm not sure if this is helpful, but analogsea::account() produces the (redacted) result...

   email: (my correct email)
   E-mail verified:   TRUE
   UUID: (a long number/string)
   Droplet limit: 10
   Floating IP limit: 3
   Status: active
   Status message: (blank)
pachadotdev commented 2 years ago

I've set up an SSH key as detailed at https://cloud.digitalocean.com/ssh_keys. Subsequently running the above code still results in "Error: Key can't be blank"

sorry the slow reply you can @ me (i.e. @mnr)

after inspecting this, it's something about API changes on DigitalOcean side I'll write to the people I know there to ask for more details

in the meanwhile, you can add keys here https://cloud.digitalocean.com/account/security

hdoran commented 1 year ago

I too am experiencing a similar issue. I observe using the dev version of plumberDeploy from github:

k <- analogsea::key_create("PACER", readLines('C:\plumber\digitalOcean.pub'))
Error: Key can't be blank 
mydrop <- plumberDeploy::do_provision()
THIS ACTION COSTS YOU MONEY!
Provisioning a new server for which you will get a bill from DigitalOcean.
Using default ssh keys: PACER
NB: This costs $0.00893 / hour until you droplet_delete() it
Waiting for create ....................................
New server key: [[deleted for purposes of this post]]
Error: Authentication with ssh server failed
lapply(analogsea::keys(), '[[', "public_key")
$PACER
[1] "ssh-rsa [[[key deleted]]Extreme\n"

I have not yet been successful and am also looking for a solution.

pachadotdev commented 1 year ago

@mnr sorry the long delay, you can install the development version with devtools::install_github("pachadotdev/analogsea")

hdoran commented 1 year ago

I updated as suggested by @pachadotdev and now I see:

k <- analogsea::key_create("PACER", readLines('C:\\plumber\\digitalOcean.pub'))
Error: SSH Key is already in use on your account

But still observe:

> mydrop <- plumberDeploy::do_provision()
THIS ACTION COSTS YOU MONEY!
Provisioning a new server for which you will get a bill from DigitalOcean.
Using default ssh keys: PACER
NB: This costs $0.00893 / hour until you droplet_delete() it
Waiting for create ...............................
New server key: [[deleted]]
Error: Authentication with ssh server failed

I do see that when I run and squint at the pubkey printed using ssh::ssh_key_info() it does NOT match the one in the .pub file on my DO settings. Perhaps that's the culprit? If so, I'm not sure how to make sure the local key matches the one on the DO settings?

hdoran commented 1 year ago

Just a quick real time update. I found the two files R was reading when it looked at ssh::ssh_key_info(). I manually went into those files and did a copy paste of the contents from the two files created by DO when I generated the SSH key. Now, this process is running and appears to be moving in a good direction so far. I'll share updates in case this is useful to others.

pachadotdev commented 1 year ago

@hdoran hi! that is different, one thing is to add the ssh to a droplet and another is to use that ssh key for API purposes please keep us posted!

hdoran commented 1 year ago

This may not be a plumberDeploy issue, but I'll ask it on this thread anyhow to see if appropriate. I have now successfully deployed on DO. Locally, I can run my API because the functions I use are in the R workspace. However, when deployed at DO I need to figure out how to also push my code to the server and this code is NOT in a package and would prefer it not be.

Here is a toy example that does not work because the function myadd() is outside the endpoint. Is there a way to push just the R code that is used in the endpoints to the DO server so the code could run?

#* Return the sum of two numbers
#* @param a The first number to add
#* @param b The second number to add
#* @get /sum
function(a, b) {
  myAdd(a,b)
}

myAdd <- function(x,y){
    x + y
}
pachadotdev commented 1 year ago

sorry, my experience led me to create an internal R package just to export those functions :(

hdoran commented 1 year ago

OK, I decided to build the R package and deploy. I moved the contents of the package to a public github, but it's not obvious to me how to install from that repo.

If I were just doing a regular install in R, I would use: devtools::install_github("myname/Blog", subdir='mypackage')

I tried

analogsea::install_github_r_package(mydrop, "PACERStuff",  repo = "myname/Blog/mypackage")
analogsea::install_github_r_package(mydrop, "PACERStuff",  repo = "https://github.com/myname/Blog/tree/master/mypackage")

Neither of which ends up installing the package at DO. Any obvious errors in what I'm doing or suggestions to use fix this?

pachadotdev commented 1 year ago

@hdoran you need something like

x <- droplet_create(n, region = r, size = s, image = img, wait = T)
x <- droplet(x$id)
install_github_r_package(x, "pachamaltese/eflm")

I would look at the tests for more examples https://github.com/pachadotdev/analogsea/blob/main/tests/testthat/test-droplet_actions_1.R

hdoran commented 1 year ago

This was successful to resolve installing from github. API is now live and hosted. I also found it helpful that via digital ocean you can log into an R session on your droplet via its terminal to see if packages load there as expected for some debugging.