-
-
Notifications
You must be signed in to change notification settings - Fork 964
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
Can not update an identity using PUT /identities/{id} #435
Comments
Yeah it's currently not supported to update identities in a way that changes their credentials, because we don't have the infrastructure to e.g. set a password using the Admin API. This is definitely a feature/bug. You will probably succeed with your request if you don't change the email address. |
No, even with the email address left out, it fails:
|
You need to include the email, and keep it unchanged! |
Yes, that's what I did in the first place. I created the identity as |
Ok, we definitely need to give the Admin API some love. Sorry about that! But we're addressing some other hard-pressing issues (account recovery) first and we don't have enough bandwidth to solve this simoultaneously. Unfortunately, this needs a lot of internal knowledge that isn't documented so it probably won't be easy to contribute, but you can try of course :) |
The Admin API definitely need some love. And your right, it's not that easy to understand the design and be able to contribute, but my analysis shows that the offending line is this one: kratos/identity/credentials.go Line 121 in 6da1bd6
I put a debug statement there and can see that we have:
So, to me the design seems a bit off. Why is this comparison even happening. The request payload doesn't even accept credentials (?), so why are we comparing them in the first place? Furthermore, the Update method in manager.go also compares verifiable addresses. I don't understand why this is being compared either. Updating an identity should only look at the traits, and potentially the credentials, if there was a way to specify the credentials as part of the payload. The current implementation compares both credentials and verifiable addresses against what's in the database, and that doesn't make much sense? So, what's needed is probably a bit of refactoring of the Admin API. First, the part of the identity that we are interested in updating are the traits, so the request payload should basically only require the id of the identity, the schema id and the traits. Everything else should be handled under the hood. Verifiable addresses seems like an internal construct, and will probably be of little interest to the client. Secondly, we need a way to specify the credentials as part of the update operation (we would need this for the POST operation as well). For now, I can fix this by disabling a few line of code in the relevant places, but I'm afraid I don't know the code well enough, or understand the basic design well enough to be able to contribute a fix for this. But hopefully, I've saved you some time to analyze the problem. |
Good analysis! So the problem with the Admin API is the following: An Admin should not be able to set the password for a user manually. Instead, a flow where the user, for example, receives an email with a link that activates their account is preferred. Google solved this pretty well also, where you get a temporary password that you have to change once logged in. As you can see, it would be foolish to allow an Admin to just "set" the password. We do however need that functionality also, because it might need to be possible to "import" users. Here the question however is how we're going to deal with the different password hashing algorithms. Unfortunately, the traits compose several credentials. This includes verified addresses, recovery addresses, and - amongst others - the login with password id (eg your email)�. Allowing an admin to make modifications for those would be pretty bad unless we have a good strategy to solve the above points. What you're looking at is code that prevents someone from changing an identity's credential. We'll only be allowing that through the Admin API if the above questions have been answered. What you're seeing however appears to be a bug! Because the comparison is made between a |
I ran into this today and came to similar conclusions. I noticed there's an UpdateTraits() method in manager.go that first copies the original identity into the updated identity and then sets the Traits over the top of the updated identity object. I thought perhaps there's another API call I should be using to make use of this method but I couldn't find anything actually invoking this UpdateTraits() method. Even if this is the way to go would it support email address changes? Since the email address is both a trait, and in the addresses[] array I wasn't sure if updating only the email address trait would suffice. |
Describe the bug
When using the identity schema below, I can not update an identity using the
PUT /identities/{id}
endpoint:Reproducing the bug
To reproduce, first create an identity:
Then, take the response body as request body and try to update the identity:
Server logs
time="2020-05-27T09:27:54Z" level=info msg="started handling request" method=PUT name="admin#http://127.0.0.1:4434" remote="127.0.0.1:56402" request=/identities/be0ab6e6-25b0-453a-af33-f6a2efbb2ea4
time="2020-05-27T09:27:54Z" level=error msg="An error occurred while handling a request" code=403 debug= details="map[]" error="The requested action was forbidden" reason="A field was modified that updates one or more credentials-related settings. This action was blocked because an unprivileged method was used to execute the update. This is either a configuration issue or a bug and should be reported to the system administrator." request-id= status=403 writer=JSON
time="2020-05-27T09:27:54Z" level=info msg="completed handling request" method=PUT name="admin#http://127.0.0.1:4434" remote="127.0.0.1:56402" request=/identities/be0ab6e6-25b0-453a-af33-f6a2efbb2ea4 status=403 text_status=Forbidden took=31.68649ms
Server configuration
Expected behavior
I expect it would be possible to update the identity. It should also be possible to update only the traits of the identity, without having to send the verifiable addresses.
Environment
The text was updated successfully, but these errors were encountered: