redhat-buildpacks / testing

Project aiming to help us to perform e2e tests using Buildpacks
Apache License 2.0
0 stars 3 forks source link

Automate m2m oc/kubectl communication #39

Open cmoulliard opened 1 year ago

cmoulliard commented 1 year ago

Todo

Summary : Automate m2m oc/kubectl communication between a job running as .github/workflow and RHTAP ocp4 clusters running on console.redhat.com

Use case description: The use case should be to support to automate tests running part of a github flow where the oc or kubectl client will execute commands against RHTAP (= ocp clusters running here https://console.redhat.com/preview/hac/application-pipeline) AND without the need to use a personal red hat account but instead a service account.

The use case will require to have/support:

We can configure locally the kubectl/oc client (= kube config) to use the token but the ocp's RHTAP cluster will fail to authenticate the OIDC token as they are not configured to accept the OIDC token. See such a config here: https://medium.com/@charled.breteche/kind-keycloak-securing-kubernetes-api-server-with-oidc-371c5faef902

According to Alexey Kazakov, the RHTAP Proxy accepts as OIDC parameters:

Example of OIDC response received using clientId and SecretID

#### Id token decoded: {
  "exp": 1692634304,
  "iat": 1692633404,
  "auth_time": 0,
  "jti": "288488d7-2603-4fff-a359-a08f1b228bc5",
  "iss": "https://sso.redhat.com/auth/realms/redhat-external",
  "aud": "391f1c4c-fe45-4935-bcee-667b075a9962",
  "sub": "721e665b-93d9-4c12-a772-b69eaee5905a",
  "typ": "ID",
  "azp": "391f1c4c-fe45-4935-bcee-667b075a9962",
  "at_hash": "poKLFijn4MzLPb-SkuHGcw",
  "clientHost": "2a02:a03f:b90f:b800:e420:6d08:dff0:e759",
  "clientId": "391f1c4c-fe45-4935-bcee-667b075a9962",
  "email_verified": false,
  "rh-user-id": "50986588",
  "rh-org-id": "10977452",
  "preferred_username": "service-account-391f1c4c-fe45-4935-bcee-667b075a9962",
  "clientAddress": "2a02:a03f:b90f:b800:e420:6d08:dff0:e759"
}

According to Alexey Kazakov, the preferre_username is the service account name but not the username which generated the SA token. So, we can't map the sso SA to any RHTAP workspace. Right now we require a username because we can tell if this user has permissions to work with specific workspace. We have no idea if some random SA issued by sso has any permissions in a specific workspace (well… we know it doesn’t).

Suggestions to solve it:

Remark: Such a demand already exists https://issues.redhat.com/browse/CRCPLAN-185