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

OLS-546: Use cluster id as user id #882

Merged
merged 2 commits into from
Jun 3, 2024

Conversation

onmete
Copy link
Contributor

@onmete onmete commented May 7, 2024

Description

Use cluster id as user id

Type of change

  • New feature

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label May 7, 2024
@openshift-ci-robot
Copy link

openshift-ci-robot commented May 7, 2024

@onmete: This pull request references OLS-546 which is a valid jira issue.

In response to this:

Description

Use cluster id as user id

Type of change

  • New feature

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 7, 2024
@openshift-ci openshift-ci bot requested review from bparees and tisnik May 7, 2024 08:24
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 7, 2024
ols/utils/auth_dependency.py Outdated Show resolved Hide resolved
mocked_call = MagicMock()
mocked_call.get_cluster_custom_object.return_value = cluster_id
mock_get_custom_objects_api.return_value = mocked_call
assert get_cluster_id() == "some-cluster-id"
Copy link
Contributor

Choose a reason for hiding this comment

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

prob. use real UUID? will it be tested in the code btw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean ensuring what we get from the cluster as id is really uuid? That seems like an overkill to me, but I can add it if you think it is reasonable.

@codecov-commenter
Copy link

codecov-commenter commented May 7, 2024

Codecov Report

Attention: Patch coverage is 88.63636% with 5 lines in your changes are missing coverage. Please review.

Project coverage is 95.24%. Comparing base (de85e97) to head (a7dbbea).
Report is 12 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #882      +/-   ##
==========================================
- Coverage   95.34%   95.24%   -0.10%     
==========================================
  Files          54       54              
  Lines        2211     2252      +41     
==========================================
+ Hits         2108     2145      +37     
- Misses        103      107       +4     
Files Coverage Δ
ols/constants.py 100.00% <100.00%> (ø)
ols/utils/auth_dependency.py 77.55% <88.09%> (+4.65%) ⬆️

... and 4 files with indirect coverage changes

@onmete
Copy link
Contributor Author

onmete commented May 9, 2024

@bparees @xrajesh The user id in the e2e CI is "system:serviceaccount:openshift-lightspeed:test-user". In order to have the feature in the PR covered by e2e test, I need to hit the /authorized endpoint as the "kube:admin". Would you know an easy way how to do it besides updating the the request model of that endpoint to allow post user (which I'm not sure if we want to do)? Another option would be to remove the e2e test.

@xrajesh
Copy link
Contributor

xrajesh commented May 9, 2024

@onmete The tests are using the test-user's token. here . You can make a API call as kubeadmin by getting the kubeadmin's token. I am thinking we are logging in as the kubeadmin. Hence kubeadmin_token=$(oc whoami -t) should give us the kubeadmin token. We will need a function just like def get_user_token(name: str) -> str: to run the oc whoami -t . If you make use of that token and make a OLS api call, it should get you "kube:admin"

@onmete onmete force-pushed the cluster-id-as-user-id branch 2 times, most recently from 1dca8fc to 21c3045 Compare May 14, 2024 09:06
@@ -206,7 +238,7 @@ async def __call__(self, request: Request) -> tuple[str, str]:
status_code=403, detail="Forbidden: Invalid or expired token"
)
if user_info.user.username == "kube:admin":
user_info.user.uid = DEFAULT_KUBEADMIN_UID
user_info.user.uid = get_cluster_id()
Copy link
Contributor

Choose a reason for hiding this comment

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

the cluster id isn't going to change between user queries, so we should just fetch it once during OLS startup and then use that value every time we get a request from kubeadmin.

this will also help avoid anther issue you're not handling here, which is what happens if getting the cluster id fails? you log the errors in the helper, but ultimately return None to the caller.

if you fetch it during startup you can retry + refuse to start until we successfully get the cluster id.

it also removes the extra/repeated api calls.

@@ -728,6 +728,29 @@ def test_forbidden_user():
assert response.status_code == requests.codes.forbidden


# TODO: disabled until we figure out how to get the token that returns
# user kube:admin in the CI
Copy link
Contributor

Choose a reason for hiding this comment

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

we can at least have a legitimate test of the get_cluster_id helper, right? (not really an e2e test since you won't be going through the OLS server, but since we have a cluster stood up, you can test that the get_cluster_id helper gets the right value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was thinking about it too as a backup when we can't do e2e.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 15, 2024
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 15, 2024
@onmete
Copy link
Contributor Author

onmete commented May 15, 2024

/retest

@onmete onmete force-pushed the cluster-id-as-user-id branch 6 times, most recently from c0114a4 to e6b1429 Compare May 21, 2024 13:25
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 21, 2024
@xrajesh
Copy link
Contributor

xrajesh commented May 29, 2024

@onmete minor change proposed - otherwise - this LGTM.

@xrajesh
Copy link
Contributor

xrajesh commented May 31, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label May 31, 2024
@tisnik
Copy link
Contributor

tisnik commented May 31, 2024

/approve

Copy link

openshift-ci bot commented May 31, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tisnik

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 31, 2024
@tisnik
Copy link
Contributor

tisnik commented May 31, 2024

/retest

@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD 03e4fd5 and 2 for PR HEAD a089664 in total

@onmete
Copy link
Contributor Author

onmete commented May 31, 2024

Service hiccup - {'errors': [{'status': 500, 'detail': 'Could not get the SSO public key', 'meta': {'response_by': 'gateway'}}]}

/retest

@onmete
Copy link
Contributor Author

onmete commented Jun 3, 2024

/retest

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jun 3, 2024
@tisnik
Copy link
Contributor

tisnik commented Jun 3, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 3, 2024
@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD abde71b and 2 for PR HEAD 573addf in total

@onmete
Copy link
Contributor Author

onmete commented Jun 3, 2024

/retest

@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD dc5d14f and 1 for PR HEAD 573addf in total

@openshift-ci-robot
Copy link

/retest-required

Remaining retests: 0 against base HEAD 272d13f and 0 for PR HEAD 573addf in total

@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jun 3, 2024
@onmete
Copy link
Contributor Author

onmete commented Jun 3, 2024

/retest

@tisnik
Copy link
Contributor

tisnik commented Jun 3, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 3, 2024
Copy link

openshift-ci bot commented Jun 3, 2024

@onmete: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@openshift-merge-bot openshift-merge-bot bot merged commit 9dc0ed3 into openshift:main Jun 3, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants