-
Notifications
You must be signed in to change notification settings - Fork 516
Description
I have been trying to get Kiali's OpenID integration. The scenario we want is to have Kiali's dashboard exposed to the development teams in a Public URL and they can log in into Kiali with their Azure AD's credentials.
My setup is like this:
Kiali Operator: v.1.24
AKS: version 1.18.8
We have a AKS + AAD cluster integrated like so:

My Kiali Spec has the following configuration:
cr:
spec:
auth:
strategy: openid
openid:
client_id: <myClientId>
issuer_uri: <myIssuerURI>
authorization_endpoint: <my/authorizeEndpoint>
scopes: ["openid", "profile", "email"]My app registration on AKS has the following manifest with obscured ids
{
"id": "secretid",
"acceptMappedClaims": null,
"accessTokenAcceptedVersion": 2,
"addIns": [],
"allowPublicClient": null,
"appId": "appId",
"appRoles": [],
"oauth2AllowUrlPathMatching": false,
"createdDateTime": "2020-09-25T19:20:08Z",
"groupMembershipClaims": "SecurityGroup",
"oauth2AllowIdTokenImplicitFlow": true,
"oauth2AllowImplicitFlow": true,
"oauth2Permissions": [],
"preAuthorizedApplications": [],
"publisherDomain": "publisherDomain",
"samlMetadataUrl": null,
"signInUrl": null,
"signInAudience": "AzureADMyOrg",
"tags": [
"notApiConsumer",
"webApp"
],
"tokenEncryptionKeyId": null,
...other secret configs...
}Here is where it gets interesting:
I get two possible issuerUris from my Azure App registration on Azure.
In the Overview tab you can get your app Endpoints:

Clicking on Endpoint I get the /.wellknown endpoint which gives me a couple of options:

I can use the issuer-uri given me there or I can use the same authorization endpoint in the issuer-uri slot.
Example authorization endpoint:
https://login.microsoftonline.com/your-id-here/oauth2/v2.0/authorize
Example issuer endpoint:
https://login.microsoftonline.com/your-id-here/v2.0
Through extensive testing we noticed that when using the Authorization endpoint on the issuer-uri field we are using OpenId's Implicit Flow
When using the regular issuer uri we are using the Authorization Code Flow.
I was not able to make neither approach work and will go into detail of each one below:
Implicit Code Flow
To use Implicit Code Flow we use the /authorize endpoint twice, like so:
cr:
spec:
auth:
strategy: openid
openid:
client_id: <myClientId>
issuer_uri: https://login.microsoftonline.com/your-id-here/oauth2/v2.0/authorize
authorization_endpoint: https://login.microsoftonline.com/your-id-here/oauth2/v2.0/authorize
scopes: ["openid", "profile", "email"]Describing the flow:
After Clicking on Log in, we can see through the network tab that kiali redirects us to a /kiali/api/auth/openid_redirect endpoint.
This will redirect us to our IdP where you can log in normally.
After that the IdP will redirect to your callback (in this case http://localhost/kiali)
id_token
state
session_state
In its form data (Confirming this is Implicit Flow)
however with an unsuccessful login screen with the message
Login unsuccessful: Token is not valid or is expired
I went and looked into the JWT that came back in the id_token field and it has the following structure
{
"aud": "number-here",
"iss": "https://login.microsoftonline.com/issuer-id-here/v2.0",
"iat": number-here,
"nbf": number-here,
"exp": number-here,
"aio": "string-here",
"email": "my-email-here",
"hasgroups": "true",
"name": "Fay, Estevao",
"nonce": "nonce-here",
"oid": "oid-here",
"preferred_username": "my-email-here",
"rh": "hash value here.",
"other-fields": "omitted"
}As we can see this JWT does not have the groups field for us to claim it through Kiali OpenId.
It is necessary because our cluster's RBAC rules (including to our admins) are done by using AKS + AD integration through groups.
I noticed here #3042 that you guys have dismissed groups claim in the past but it would be essential to use AKS + AD integration since RBAC assignments are done directly to User or Group Ids which Kiali is apparently not able to resolve.
Auth Code Flow
To use Auth Code Flow, we need to use the issuer-uri given by us by that same .well-known endpoint in Azure App registration
Sample YAML is like so
cr:
spec:
auth:
strategy: openid
openid:
client_id: <myClientId>
issuer_uri: https://login.microsoftonline.com/your-id-here/v2.0/
authorization_endpoint: https://login.microsoftonline.com/your-id-here/oauth2/v2.0/authorize
scopes: ["openid", "profile", "email"]With this we are using Code Flow described below
Describing the Flow
When we click on login we quickly get logged in through our IdP but get this "Token is not valid or is expired" error with a 401.
{
"error": "Token is not valid or is expired",
"detail": "Unauthorized"
}Debugging through our network tab we can see we first got redirected to the IdP, got redirected back to the callback and then kiali made a request to the authorization endpoint with the Query string parameters
- client_id = myId
- response_type = code
- redirect_uri = http://localhost/kiali
- scope = openid email profile
- nonce = asdolfkjlaskdjf
- state = auishfiohaside
Confirming this is the Auth Code Flow.
However, through the standard OpenId Code Flow, at some point the returned code needs to be sent back to the IdP with the client secret which Kiali's docs briefly mention here:
Register Kiali as a client application in your OpenId Server. Use the root path of your Kiali instance as the callback URL. If the OpenId Server provides you a client secret, or if you manually set a client secret, issue the following command to create a Kubernetes secret holding the OpenId client secret:
kubectl create secret generic kiali --from-literal="oidc-secret=$CLIENT_SECRET" -n $NAMESPACE
Which considering that we know that getting oidc flags from cloud provided kubernetes (specially ones created by tools like terraform) is next to impossible as see here #3084. Also we are using a GitOps Approach to installing Kiali, Istio and the likes, so It would be nice to have a strategy of inserting a client key (if necessary) in a way that is not exposed in our git repositories (but I would understand if it were impossible)
This makes is impossible to setup a simple OpenId connect with Azure AKS since we cannot send the secret back to the IdP (which explaing why i'm getting a 401).
However by using https://oidcdebugger.com/ and Postman I can see that if Kiali were to send the correct secret in this flow, we would get the groups in the JWT id_token like so:
{
"aud": "aud-id-here",
"iss": "https://login.microsoftonline.com/id-here/v2.0",
"iat": 1601670894,
"nbf": 1601670894,
"exp": 1601674794,
"aio": "omittingstuff",
"email": "Estevao.Fay-ext@my-email.com",
"groups": [
"groupId1",
"groupId2",
"groupId3"
],
"name": "Fay, Estevao",
"nonce": "boqb7l0suh6",
"oid": "65b8a2",
"preferred_username": "my-email-here"To which I would be able claim groups in kiali if it were a supported feature.
@israel-hdez Asked for me to open a new issue with this! #3084 So here we go! :D
I don't know if I have provided enough information to go forward. I feel like we are close to a solution since we are able to sign in with azure but we are blocked in the next step (which I assume is to check the user's RBAC credentials).
It is our intention to limit as much access to the cluster as possible. Limiting everyone just to visualize Kiali's resources would be ideal. This way we can slowly and securely add more permissions to the teams that need it.
Thanks!

