Applying Permissions to Global Realm Not Working

ros

#1

There seem’s to be a problem with applying read/write permissions for global realms. It seems like I am not the only person to run into this issue recently: https://stackoverflow.com/questions/49587780/realm-permission-changes-not-working.

I am following the access control documentation (as you can see in my code below), however the ‘syncUser.apply(:_)’ function never completes for some reason. In my code, “about to apply permission” is successfully printed, but “Received a response for permission” is never printed.

Also, I am certainly calling this function from the main thread so the following solution does not apply to me: https://stackoverflow.com/questions/46587720/realm-object-server-swift-changing-default-permission-of-a-realm.

Other notes are that I am using Realm Cloud and in Realm Studio “/CommonRealm” is owned by an admin user but it says “This realm currently has no permissions”.

I’ve been stumped on this issue for quite a while and would appreciate if someone has an idea as to what could be causing the problem.

Thanks in advance!

    class func applyPermissionFor(realm: Realm, syncUser: SyncUser) {
        
        let perm = SyncPermission(realmPath: "/CommonRealm",
                                  identity: "*",
                                  accessLevel: .write)
        
        if syncUser.isAdmin == true {
            
            print("about to apply permission")
            
            syncUser.apply(perm) { error in
                print("Received a response for permission")
                if let error = error {
                    print(error.localizedDescription)
                } else {
                    print("Permission applied successfully")
                }
            }
            
        }
    }

#2

@rrozenv Who is the SyncUser you are using the apply permissions?

Can you turn up to debug mode and share logs please?


#3

Thanks for the quick reply.

I am generating a SyncUser by passing valid credentials for an admin user:

let credentials = SyncCredentials.usernamePassword(username: email, password: password, register: false)
SyncUser.logIn(with: credentials, server: Constants.syncAuthURL, onCompletion: { (syncUser, error) in
                if let user = syncUser {
                    print("Admin user logged in successfully!")
                }
}

After I generate a sync user successfully, I open up the Global Realm in question:

Realm.asyncOpen(configuration: RealmConfig.common.configuration, callback: { (realm, error) in
                if let realm = realm {
                    print("opened Global Realm")
                }
}

At this point I have successfully generated an admin SyncUser and opened the Global Realm. These are the arguments I am using for the function in my original post.

I attached an image of my logs where you can see that my print statements are all output in an order that is expected. The only issue is that the ‘syncUser.apply(perm)’ function never triggers a callback.


#4

@rrozenv Can you share the logs on the ROS side too please? You should be able to see these in Studio and then switch to debug mode to get more detail


#5

@ianward these are the relevant debug logs from the moment I launch my application.


#6

@rrozenv Thank you - we are investigating.


#7

@ianward Has there been any progress on this issue?

Thanks


#8

We have a working theory on the root cause. To test it, can you try to create a new user in studio and make them an admin, then use that new user to apply permissions?


#9

@nirinchev I added a new user using realm studio and made them the admin. Tried adding permissions using that user but the results are the same as I described above (apply permission function never triggers a callback).

I also attached the relevant logs. I see now there is some sort of auth error, but Im not sure if it’s related to this issue. I think it may have been triggered when I deleted the global realm through Realm Studio.


#10

@nirinchev @ianward is there any news on this? This issue is stopping me from releasing my app into production so it would be nice to get it resolved. Thanks


#12

@rrozenv We have released a fix for a similar issue that another user has reported. Can you check if it has resolved your case as well? If it hasn’t we’ll follow up to get some diagnostic information and investigate further.


#13

@nirinchev So I still don’t receive a callback, but I do see an error now appearing in the logs that wasn’t appearing before. As always, I still see the realm (named ‘/CommonRealm’) appear in Realm Studio without any permissions set. Any idea why I would be seeing this error?


#14

What does this HTTP 400 (Bad Request) when sending POST /auth do ? It seems the Realm client library and ROS are not 100% compatible.


#15

It appears you’re trying to get an access token for a Realm that has a non-standard name. Do you know what code triggers this error?