Skip to content
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

Add OIDC user to the functional test #3235

Merged

Conversation

npalaska
Copy link
Member

@npalaska npalaska commented Feb 7, 2023

PBENCH-1070

To facilitate the removal of the dependency on the internal user API and internal users table we need to update the functional tests to not use the internal APIs.

Functional tests should move to using OIDC tokens by making a Admin REST API request to the OIDC server (Keycloak) directly as the server won't be providing those capabilities on its endpoints.

This PR is currently rebased on top of PR #3114

@npalaska npalaska self-assigned this Feb 7, 2023
@npalaska npalaska added this to the v0.72 milestone Feb 7, 2023
@npalaska npalaska force-pushed the pbench_1070 branch 2 times, most recently from ae1a077 to 73ac125 Compare February 8, 2023 16:50
@npalaska npalaska marked this pull request as ready for review February 8, 2023 16:50
@npalaska
Copy link
Member Author

npalaska commented Feb 8, 2023

Note:

  1. These changes introduce the OIDC admin functionality for the client to use where the user directly communicates with the OIDC server and gets the token and the Dashboard is not involved in this handshake.
  2. These changes are only related to functional tests and do not update the unit tests to use the OIDC-compliant tokens and users. With PR Further cleanup for the auth module #3114 we segregated the operational Pbench-server where we can either deploy the server with OpenID or the with an internal tokens table. In this effort, we have reverted unit tests to use the internal tokens, I'll fix this in another PR that handles only unit tests changes.

from requests.structures import CaseInsensitiveDict


class OIDCAdmin:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the Connection class in the lib/pbench/server/auth/__init__.py module which we should probably re-use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to defer reviewing this code until this change is made.

Copy link
Member

@portante portante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not re-add the same code that is already in the Connection class.

@@ -468,7 +468,7 @@ def token_introspect_offline(self, token: str) -> JSON:
token,
self._pem_public_key,
algorithms=[self._TOKEN_ALG],
audience=self.client_id,
audience=["account", self.client_id],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this audience coming from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I forgot to add a comment here.
Basically, if a user logs in with a username and password directly with a Keycloak rest API using private client then the aud claim included in the token is account
for example this request:

requests.post(
        "<token_endpoint>",
        headers=<{headers}>,
        data={"client_id": "pbench-server-client", "client_secret": <secret>,
              "scope": "profile email", "grant_type": "password", "username": user, "password": "123"},
        verify=False
    )

will generate a token that has a payload like following:

{'exp': 1675890382, 
'iat': 1675890082,
'jti': 'a8dc9cca-d734-4758-ab1d-be6510fe85b2', 
'iss': 'http://localhost:8090/realms/pbench-server', 
'aud': 'account', 
'sub': '9202c4a9-5901-46dc-9b8e-2643a5f4372e', 
'typ': 'Bearer', 
'azp': 'pbench-server-client', 
'session_state': '5730b4b1-bdb3-438c-a308-d3c1f8108fd8', ....}

And right now our functional test user is logging in using the Keycloak Rest API, so I had to include this claim to get the functional tests to pass.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be fixed now. I have added a client scope in the Keycloak configuration that will add the Pbench openid client (pbench-dashboard) in the aud claim by default. So the functional test user tokens should be able to get validated now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@portante can we resolve this comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't require comments to be resolved before merging. Forgive me, but I have not had the time to review the changes in detail.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, can you consider removing your objection to this PR, its blocking the merge.

Copy link
Member

@dbutenhof dbutenhof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I got finished; but I just realized I left comments so I might as well publish them before today ends.

lib/pbench/test/functional/server/test_user.py Outdated Show resolved Hide resolved
lib/pbench/server/api/resources/__init__.py Show resolved Hide resolved
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the dependencies of this PR, should it be moved to draft mode?

from requests.structures import CaseInsensitiveDict


class OIDCAdmin:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to defer reviewing this code until this change is made.

lib/pbench/test/functional/server/conftest.py Outdated Show resolved Hide resolved
lib/pbench/test/functional/server/conftest.py Outdated Show resolved Hide resolved
@npalaska npalaska marked this pull request as draft February 9, 2023 18:08
@npalaska
Copy link
Member Author

npalaska commented Feb 9, 2023

Converted this to the draft mode again, I need to work on the new users table that we talked about in the design sync meeting.

@portante
Copy link
Member

portante commented Feb 9, 2023

Converted this to the draft mode again, I need to work on the new users table that we talked about in the design sync meeting.

Please don't create a new users table. We already have one.

@npalaska
Copy link
Member Author

npalaska commented Feb 9, 2023

Converted this to the draft mode again, I need to work on the new users table that we talked about in the design sync meeting.

Please don't create a new users table. We already have one.

Well, we can't use the current users table, it has user credentials information in it. So we have to drop it entirely and create a have a new one without all the user login stuff.

@dbutenhof
Copy link
Member

Converted this to the draft mode again, I need to work on the new users table that we talked about in the design sync meeting.

Please don't create a new users table. We already have one.

Well, we can't use the current users table, it has user credentials information in it. So we have to drop it entirely and create a have a new one without all the user login stuff.

That's a semantic distinction I wouldn't worry about. You probably want to drop most of the existing columns. We only need a uuid = Column(String, unique=True) and a username = Column(String)... The new "API key" (similarly reworked/simplified AuthToken table will want a foreign key link, so probably also the same old id = Column(Integer, primary_key=True, autoincrement=True). We might want to capture Pbench-specific "profile" stuff here, and one way would be a simple profile = Column(JSON) where we can store anything we want.

Copy link
Member

@portante portante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rebase this on the openid-connect branch?

@npalaska npalaska changed the base branch from main to openid-connect February 10, 2023 18:51
@npalaska
Copy link
Member Author

I changed the base but I'll rebase it on the openid-connect in some time.

Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you've added support for the json parameter, you should revert the changes to add the str type to the data parameter (I'm hoping there's no reason why you cannot do that...). And, there are a bunch of nits which you should fix. And, I've got some suggestions, questions, and the odd request.

lib/pbench/client/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
lib/pbench/test/functional/server/test_connect.py Outdated Show resolved Hide resolved
lib/pbench/client/oidc_admin.py Outdated Show resolved Hide resolved
lib/pbench/client/oidc_admin.py Outdated Show resolved Hide resolved
lib/pbench/client/oidc_admin.py Outdated Show resolved Hide resolved
dbutenhof
dbutenhof previously approved these changes Feb 15, 2023
lib/pbench/test/functional/server/test_connect.py Outdated Show resolved Hide resolved
lib/pbench/test/unit/server/auth/test_auth.py Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
webbnh
webbnh previously approved these changes Feb 15, 2023
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, Nikhil.

Just a couple of tiny nits if you are so inclined.

lib/pbench/client/oidc_admin.py Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Outdated Show resolved Hide resolved
lib/pbench/server/auth/__init__.py Show resolved Hide resolved
Copy link
Member

@webbnh webbnh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it!

lib/pbench/server/auth/__init__.py Show resolved Hide resolved
@portante portante dismissed their stale review February 21, 2023 01:19

No longer participating in the review cycle for this PR.

@npalaska npalaska merged commit ffc8c5d into distributed-system-analysis:openid-connect Feb 21, 2023
npalaska added a commit to npalaska/pbench that referenced this pull request Mar 9, 2023
* Use OIDC user for the functional test

Functional tests should move to using OIDC tokens by making an Admin REST API request to the OIDC server (Keycloak) directly as the server won't be providing Register/Login capabilities on its endpoints.

- Create a new scope in the Keycloak to add OIDC client name in aud claim (required for the authentication)
- Functional test user registration happens directly with the OIDC server using the Admin token
- Functional test user makes a REST API call to get the OIDC token

PBENCH-1070
npalaska added a commit that referenced this pull request Mar 13, 2023
* Use OIDC user for the functional test

Functional tests should move to using OIDC tokens by making an Admin REST API request to the OIDC server (Keycloak) directly as the server won't be providing Register/Login capabilities on its endpoints.

- Create a new scope in the Keycloak to add OIDC client name in aud claim (required for the authentication)
- Functional test user registration happens directly with the OIDC server using the Admin token
- Functional test user makes a REST API call to get the OIDC token

PBENCH-1070
npalaska added a commit to npalaska/pbench that referenced this pull request Mar 27, 2023
* Use OIDC user for the functional test

Functional tests should move to using OIDC tokens by making an Admin REST API request to the OIDC server (Keycloak) directly as the server won't be providing Register/Login capabilities on its endpoints.

- Create a new scope in the Keycloak to add OIDC client name in aud claim (required for the authentication)
- Functional test user registration happens directly with the OIDC server using the Admin token
- Functional test user makes a REST API call to get the OIDC token

PBENCH-1070
npalaska added a commit to npalaska/pbench that referenced this pull request Mar 27, 2023
* Use OIDC user for the functional test

Functional tests should move to using OIDC tokens by making an Admin REST API request to the OIDC server (Keycloak) directly as the server won't be providing Register/Login capabilities on its endpoints.

- Create a new scope in the Keycloak to add OIDC client name in aud claim (required for the authentication)
- Functional test user registration happens directly with the OIDC server using the Admin token
- Functional test user makes a REST API call to get the OIDC token

PBENCH-1070
npalaska added a commit to npalaska/pbench that referenced this pull request Mar 28, 2023
* Use OIDC user for the functional test

Functional tests should move to using OIDC tokens by making an Admin REST API request to the OIDC server (Keycloak) directly as the server won't be providing Register/Login capabilities on its endpoints.

- Create a new scope in the Keycloak to add OIDC client name in aud claim (required for the authentication)
- Functional test user registration happens directly with the OIDC server using the Admin token
- Functional test user makes a REST API call to get the OIDC token

PBENCH-1070
npalaska added a commit to npalaska/pbench that referenced this pull request Mar 30, 2023
* Use OIDC user for the functional test

Functional tests should move to using OIDC tokens by making an Admin REST API request to the OIDC server (Keycloak) directly as the server won't be providing Register/Login capabilities on its endpoints.

- Create a new scope in the Keycloak to add OIDC client name in aud claim (required for the authentication)
- Functional test user registration happens directly with the OIDC server using the Admin token
- Functional test user makes a REST API call to get the OIDC token

PBENCH-1070
npalaska added a commit to npalaska/pbench that referenced this pull request Mar 31, 2023
* Use OIDC user for the functional test

Functional tests should move to using OIDC tokens by making an Admin REST API request to the OIDC server (Keycloak) directly as the server won't be providing Register/Login capabilities on its endpoints.

- Create a new scope in the Keycloak to add OIDC client name in aud claim (required for the authentication)
- Functional test user registration happens directly with the OIDC server using the Admin token
- Functional test user makes a REST API call to get the OIDC token

PBENCH-1070
npalaska added a commit that referenced this pull request Mar 31, 2023
* Use OIDC user for the functional test

Functional tests should move to using OIDC tokens by making an Admin REST API request to the OIDC server (Keycloak) directly as the server won't be providing Register/Login capabilities on its endpoints.

- Create a new scope in the Keycloak to add OIDC client name in aud claim (required for the authentication)
- Functional test user registration happens directly with the OIDC server using the Admin token
- Functional test user makes a REST API call to get the OIDC token

PBENCH-1070
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants