rstudio / pins-r

Pin, discover, and share resources
https://pins.rstudio.com
Other
312 stars 63 forks source link

Pin unable to overwrite old pin - Error 403 #539

Closed dewoller closed 2 years ago

dewoller commented 2 years ago

Hi All. Love your work! Pins make so many things better. And I would love to use qs as my pin storage format, hence testing out the bleeding edge version of the code. Unfortunately, it doesn't work. The board connects and authenticates, and I can even write a pin. Once. The second time, it errors out.

> rsconnect_board =  board_rsconnect( auth="envvar" )
> rsconnect_board %>% pin_write(iris)
Using `name = 'iris'`
Guessing `type = 'rds'`
Writing to pin 'dennis.wollersheim@XXXX/iris'
> rsconnect_board %>% pin_write(iris)
Using `name = 'iris'`
Guessing `type = 'rds'`
Error in rsc_check_status(req) : Forbidden (HTTP 403).

If I delete the pin first, then I can write, albeit with a warning:

name='iris'
  if (pin_exists( rsconnect_board, name)) {
    pin_delete(rsconnect_board, name)
  }
  pin_write(rsconnect_board, iris, name=name)

#Second run
  if (pin_exists( rsconnect_board, name)) {
    pin_delete(rsconnect_board, name)
  }
  pin_write(rsconnect_board, iris, name=name)

The second run of the code returns the following warning from the pin_delete:

! Please use full name when reading a pin: "dennis.wollersheim@XXXX/iris", not "iris".
! Please use full name when reading a pin: "dennis.wollersheim@XXXX/iris", not "iris".
! Please use full name when reading a pin: "dennis.wollersheim@XXXX/iris", not "iris".

If I include my full name in the name parameter (which I want), e.g. pin_delete( rsconnect_board, "dennis.wollersheim@XXXX/iris") I get the following error at the pin_delete call

Error: RStudio Connect API failed [404]

dewoller commented 2 years ago

The second write fails when it attempts a http PATCH operation, while the first succeeds using a standard POST.

sellorm commented 2 years ago

In the environment I have access to (Connect v2021.09.0) this works fine for me.

I'm using pins 1.0.0 with R 4.1.0

I've declared a specific name because there are already "multiple pins with name 'iris'", so I chose something else, but otherwise this is the same as the code you provided.

library(pins)
rsconnect_board =  board_rsconnect( auth="envvar" )
#> Connecting to RSC 2021.09.0 at <https://connect.example.com/rsc>
rsconnect_board %>% pin_write(iris, name = "pins_issue")
#> Guessing `type = 'rds'`
#> Writing to pin 'mark.sellors/pins_issue'
rsconnect_board %>% pin_write(iris, name = "pins_issue")
#> Guessing `type = 'rds'`
#> Writing to pin 'mark.sellors/pins_issue'

Created on 2021-11-03 by the reprex package (v2.0.1)

Similarly, the pin_delete() worked in my case.

It would be worth looking at your Connect instance to ensure that it's up-to-date and that there's nothing in the connect infrastructure environment that might be causing issues. Reverse proxies and things like that for instance.

dewoller commented 2 years ago

Thanks @sellorm, your comment about proxies was the clue I needed to solve the issue.

The problem was due to a setting in the Azure gateway web application firewall that exists in front of the Rstudio-rsconnect server. The setting that blocked the PATCH request was REQUEST-911-METHOD-ENFORCEMENT, specifically RuleId 911100, Method is not allowed by policy. This rule blocks all PUT and PATCH requests, and disabling this rule allows pin updating. Woowee!

sellorm commented 2 years ago

Glad you figured it out! 🎉

hadley commented 2 years ago

I'm going to close this issue, but it'll still be accessible via search so any one else suffering the same problem is likely to find it.

github-actions[bot] commented 2 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.