Revoke token auth error#20762
Conversation
Reviewer's GuideAdds an end-to-end podman-based CLI test to verify that revoking a registry personal access token prevents further image pushes until the user logs out and logs back in, ensuring the regression in SAT-38785 is covered. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The cleanup finalizer is declared as a decorator with
@request.addfinalizer, butaddfinalizerexpects a callable passed as an argument (e.g. define_cleanupand then callrequest.addfinalizer(_cleanup)), otherwise the cleanup may not run as intended. - Consider capturing and asserting the result of
target_sat.cli.User.access_token(..., action='revoke', ...)(e.g. checking exit status or response) so the test explicitly fails if the revoke operation itself does not succeed rather than only inferring it from later push behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The cleanup finalizer is declared as a decorator with `@request.addfinalizer`, but `addfinalizer` expects a callable passed as an argument (e.g. define `_cleanup` and then call `request.addfinalizer(_cleanup)`), otherwise the cleanup may not run as intended.
- Consider capturing and asserting the result of `target_sat.cli.User.access_token(..., action='revoke', ...)` (e.g. checking exit status or response) so the test explicitly fails if the revoke operation itself does not succeed rather than only inferring it from later push behavior.
## Individual Comments
### Comment 1
<location> `tests/foreman/cli/test_container_management.py:597-606` </location>
<code_context>
+ )
+ assert result.status == 0, f'Failed to login to registry: {result.stderr}'
+
+ # Pull a small test image from external registry
+ external_image = 'registry.fedoraproject.org/fedora-minimal:latest'
+ result = target_sat.execute(f'podman pull {external_image}')
+ assert result.status == 0, f'Failed to pull external image: {result.stderr}'
+
+ # Get the image ID
+ result = target_sat.execute('podman images fedora-minimal -q')
+ assert result.status == 0
+ image_id = result.stdout.strip().split('\n')[0]
+ assert image_id, 'Failed to get image ID'
+
+ # Tag image for Satellite registry
</code_context>
<issue_to_address>
**suggestion (testing):** Pulling from an external registry can introduce flakiness; consider handling transient network issues or documenting expectations.
Since this test depends on `registry.fedoraproject.org` being reachable, failures may come from external outages rather than regressions in token handling. If possible, consider adding a retry around `podman pull` or marking the test skip/xfail when the registry is unavailable (e.g., based on the error). Otherwise, a brief comment noting that this external dependency is intentional would help future readers.
Suggested implementation:
```python
# Pull a small test image from external registry.
# Note: This depends on registry.fedoraproject.org being reachable; we retry
# to mitigate transient network issues / external outages rather than
# treating them as regressions in Satellite token handling.
external_image = 'registry.fedoraproject.org/fedora-minimal:latest'
max_pull_attempts = 3
for attempt in range(1, max_pull_attempts + 1):
result = target_sat.execute(f'podman pull {external_image}')
if result.status == 0:
break
if attempt == max_pull_attempts:
assert False, (
f'Failed to pull external image after {max_pull_attempts} attempts; '
'this may be due to transient network issues or the external '
f'registry being unavailable: {result.stderr}'
)
time.sleep(5)
```
To fully apply this change, you also need to:
1. Ensure `import time` is present at the top of `tests/foreman/cli/test_container_management.py`. If it's not there yet, add it alongside the other standard library imports.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
PRT Result |
qcjames53
left a comment
There was a problem hiding this comment.
This looks pretty solid to me, Vijay. The description is spot on and the reproducer steps make sense to me. I had two small changes requested. Would you also mind addressing the failing automation? Can we ignore CI code quality because it's known to be broken?
vsedmik
left a comment
There was a problem hiding this comment.
One question regarding the testing steps
|
|
PRT Result |
|
Could you please squash the commits or drop the ones that are not required? |
3e37eb1 to
d738c1e
Compare
|
|
||
| @request.addfinalizer | ||
| def _cleanup(): | ||
| target_sat.execute(f'podman logout {target_sat.hostname}') |
There was a problem hiding this comment.
Same here, use podman_logout()
There was a problem hiding this comment.
target_sat.podman_login(
username=settings.server.admin_username,
password=settings.server.admin_password,
registry=target_sat.hostname)
target_sat.podman_logout(registry=target_sat.hostname)
methods podman_login() and podman_logout() exist, but they're designed for a different use case (IOP/Red Hat cloud registry)
Since the auth file approach might cache credentials differently (which could affect the token revocation test), I would keep the direct execute() approach for this specific test.
There was a problem hiding this comment.
Ah, but I don't think it would work differently when using tokens, and for using this methods, this can be generalised to cover such use cases in future
d738c1e to
6365ca8
Compare
|
1 similar comment
|
|
PRT Result |
vsedmik
left a comment
There was a problem hiding this comment.
Looks good to me! One tiny proposal to make it even nicer:
6365ca8 to
575ec45
Compare
|
|
PRT Result |
verify registry access after token revoked (cherry picked from commit 75f7ee5)
Problem Statement
Revoking registry access token doesn't revoke client's access to registry repos.
https://issues.redhat.com/browse/SAT-38785
Solution
Upstream katello PR Katello/katello#11625
Newly added test will check the behaviour after token revoke
Related Issues
PRT test Cases example
Summary by Sourcery
Tests: