Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

[Compliance] allow_access endpoint records should be checked before calling ask_user callback #36

Open
Mr0grog opened this issue Sep 22, 2016 · 8 comments · May be fixed by #38
Open

[Compliance] allow_access endpoint records should be checked before calling ask_user callback #36

Mr0grog opened this issue Sep 22, 2016 · 8 comments · May be fixed by #38
Milestone

Comments

@Mr0grog
Copy link
Contributor

Mr0grog commented Sep 22, 2016

The readme for compliance currently states that if the ask_user callback is not specified, “then the customer information won't be given to the other FI.” This isn’t actually true—it falls back to users and domains that have been whitelisted using the allow_access endpoint.

Additionally, the description of the allow_access endpoint and its effects is incredibly unclear. I definitely didn’t understand it until I spent some time browsing the source, which a user definitely should not need to do.

@Mr0grog
Copy link
Contributor Author

Mr0grog commented Sep 22, 2016

@nullstyle do you know if there are any plans to change the general behavior w/r/t this? At current, it looks like either you implement ask_user and that is the source of truth or you use the /allow_access API—the two are totally separate ways of authorizing info and don’t really have any interplay with each other.

I can imagine intended or deprecated scenarios (I don’t really know the history/genesis of this feature) where you whitelist/blacklist w/ the API and fall back to the callback or something, but that certainly doesn’t seem to be how it works now.

Just trying to understand the direction this is moving in (if any) for documenting.

@jedmccaleb
Copy link
Contributor

ask_user is a fallback in case allow_access fails. So it would be:

request_comes_in()
{
   if(allow_access)
   {
       return: user info
   }else if(ask_user)
   {
         return: user info
   }
   return: no info
}

@Mr0grog
Copy link
Contributor Author

Mr0grog commented Sep 23, 2016

Hmmm, it could be that I’m reading it wrong, but it seems like the only time the database is checked (i.e. we look at the allow_access path) is if ask_user is unimplemented: https://github.com/stellar/bridge-server/blob/master/src/github.com/stellar/gateway/compliance/handlers/request_handler_auth.go#L202-L236

…so it can’t really fall back. Is what you’re describing the intended behavior and the current implementation just isn’t correct?

@jedmccaleb
Copy link
Contributor

I haven't looked at the implementation. What I described is how it should work

@bartekn
Copy link
Contributor

bartekn commented Sep 23, 2016

It works exactly as @jedmccaleb explained. Excerpt from compliance/handlers/request_handler_auth.go:

if rh.Config.Callbacks.AskUser == "" {
  // There is no ask_user callback specified
  // Check if domain or user*domain is in allowed table
  if "record exists in a DB" {
    return compliance.AuthStatusOk
  } else {
    return compliance.AuthStatusDenied
  }
} else {
  // Send request to ask_user callback
  if "callback returned OK" {
    return compliance.AuthStatusOk
  } else {
    return compliance.AuthStatusDenied
  }
}

The readme for compliance currently states that if the ask_user callback is not specified, “then the customer information won't be given to the other FI.” This isn’t actually true—it falls back to users and domains that have been whitelisted using the allow_access endpoint.

Yeah, you're right. This sentence is true, however, when AllowedFi/AllowedUser tables are empty. So we should rewrite this single statement.

At current, it looks like either you implement ask_user and that is the source of truth or you use the /allow_access API—the two are totally separate ways of authorizing info and don’t really have any interplay with each other.

These two options seem similar but ask_user callback gives you more control. The main difference is that ask_user callback is actually meant to ask user whether she wants to accept a payment. Besides other fields, we're sending amount, asset and note attached to a payment. /allow_access simply saves domain or user*domain of the sender and when a payment arrives, compliance server only check the sender field.

@Mr0grog
Copy link
Contributor Author

Mr0grog commented Sep 23, 2016

Excerpt from compliance/handlers/request_handler_auth.go

Right! I started this issue as a result of reading that code :)

I think the confusion here is that we each understood @jedmccaleb's answer very differently. He wrote:

if (allow_access) {
  return: user info

Which I interpreted like:

if (user_or_domain_is_in_db) {
  return: user_info

And you interpreted like:

if (should_check_db) {
  return user_or_domain_is_in_db ? user_info : auth_denied

For my part, I definitely thought he meant the former, but now I don’t know. Can you clarify, @jedmccaleb?

If the latter, everything about the code is 👍. If the former, it seems like there’s a bug in the code in addition to the documentation issue.

Anyway! I can do a PR for clarifying all this in the readme, but I want to make sure the current state of the code matches the intended design (our point of confusion above). If it does not, I should probably hold off, because documenting the current state of affairs will set up wrong future expectations for users and documenting the intended state of affairs would lead someone to think they can use the service in a way that won’t actually work today :P

@bartekn
Copy link
Contributor

bartekn commented Sep 23, 2016

OK, I think I understand now. I checked the Compliance Server design doc and there's a following sentence:

If ASK_USER_CALLBACK is not set then if the FI can't be found in the DB for this user then info_status will be no denied
If the sending FI does show up in FIAllows or the UserAllows table then call FETCH_INFO_CALLBACK to get the info to return to the requester.

It's not clear and can be implemented in at least two different ways. So yeah, let's wait for Jed to clarify.

PS. @Mr0grog I can share this doc with you but I don't have your email. Send me a message :)

@jedmccaleb
Copy link
Contributor

Yeah Rob's first interpretation is correct. To rewrite your code bartek:

if "record exists in a DB" {
    return compliance.AuthStatusOk
  } else {
     if rh.Config.Callbacks.AskUser != "" {
            // Send request to ask_user callback
            if "callback returned OK" {
                return compliance.AuthStatusOk
             }
        }
       return compliance.AuthStatusDenied
  }

but don't fix it till scott lands his changes

@Mr0grog Mr0grog changed the title [Compliance] allow_access endpoint and ask_user callback interaction is unclear [Compliance] allow_access endpoint records should be checked before calling ask_user callback Sep 23, 2016
Mr0grog added a commit to Mr0grog/bridge-server that referenced this issue Sep 23, 2016
After all the discussion in stellar-deprecated#36, this attempts to improve the README for compliance server to explain how `/allow_access`, `/remove_access`, and `callbacks.ask_user` are intended to work together.

NOTE the current code does not reflect this documentation; it still needs to be updated to fix stellar-deprecated#36.
@Mr0grog Mr0grog linked a pull request Sep 23, 2016 that will close this issue
Mr0grog added a commit to Mr0grog/bridge-server that referenced this issue Sep 23, 2016
After all the discussion in stellar-deprecated#36, this attempts to improve the README for compliance server to explain how `/allow_access`, `/remove_access`, and `callbacks.ask_user` are intended to work together.

NOTE the current code does not reflect this documentation; it still needs to be updated to fix stellar-deprecated#36.
@jedmccaleb jedmccaleb added this to the after port milestone Oct 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants