jmsperu commented on PR #14205:
URL: https://github.com/apache/cloudstack/pull/14205#issuecomment-7112280099

   Tested the PR head (4eb70e4e84) as a full build of main with a fresh 
database, against a small test identity provider that I can make misbehave on 
purpose (discovery document, JWKS with two RS256 keys, token endpoint with 
client_secret_basic). API level only, through registerOauthProvider, oauthlogin 
and verifyOAuthCodeAndGetUser. The PR does not apply to 4.22, so this was not 
run on our 4.22.1.1 lab.
   
   What works:
   
   | Check | Result |
   |---|---|
   | Register with type=oidc and issuerurl | OK |
   | type=oidc without issuerurl | refused: "Parameter issuerurl is mandatory 
for an oidc OAuth provider" |
   | Two providers with different names (same issuer) | both registered, login 
works through each |
   | Same name twice | refused |
   | Valid id_token, email matches a user | logged in |
   | Wrong signature | refused: "The id_token signature is not valid" |
   | alg none | refused (same message) |
   | Unknown kid | refused: "No matching signing key was published by the 
identity provider" |
   | Wrong audience | refused: "Audience mismatch" |
   | Wrong issuer in the token | refused: "Issuer mismatch" |
   | No email claim | refused |
   | email_verified=false | refused, also with 
oauth2.oidc.require.verified.email=false |
   | email_verified missing | refused with the setting on (the message names 
the setting), accepted with the setting off |
   | Email with no CloudStack user | refused |
   | listOauthProvider without a session | does not return the secret key |
   
   Things I would change:
   
   1. Several failures give HTTP 200 with an empty body instead of an error. No 
session is created, so this is not a security problem, but the caller gets 
nothing to show. Seen for: the identity provider rejecting the code 
(invalid_grant), a wrong client secret (401 from the token endpoint), an 
expired id_token ("unknown exception writing api response ... JwtException: The 
token has expired" in the log), an unreachable issuer or a discovery document 
naming another issuer, an id_token for another email than the one in the 
request, and verifyOAuthCodeAndGetUser with a bad signature or a rejected code. 
These paths throw CloudRuntimeException or JwtException, and oauthlogin only 
converts CloudAuthenticationException. The GitHub provider throws 
CloudRuntimeException in the same way, so part of this is older than the PR, 
but it would be good to return a 531 with a message for all of them here.
   
   2. registerOauthProvider accepts an issuer that does not answer, and one 
whose discovery document names a different issuer. The mistake only shows at 
the first login, and then as the empty reply above. Reading the discovery 
document at registration (or at least a warning in the response) would help.
   
   3. The response of registerOauthProvider says "enabled": false for an oidc 
provider while listOauthProvider says true for the same provider straight 
after. The register response seems to compare the provider name with 
oauth2.plugins, which cannot match a free name.
   
   4. The API name in the code is registerOauthProvider (small "a"); 
registerOAuthProvider gives "Unknown API command". Worth a line in the 
documentation.
   
   Not tested: the login page button and redirect in the UI, providers 
registered for a domain, a real identity provider (Keycloak, Entra, Authentik), 
ES256 keys, key rotation.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to