Skip to content

Conversation

Quantum-Sicarius
Copy link

I'm submitting this fix for issue #21406 where system robots with wildcard project permissions (/project/*/robot) couldn't create project-level robots.

Being new to Harbor development, I want to be transparent about the scope of this change and request thorough review from experienced maintainers.

Main change in src/common/security/robot/context.go:117:

// Added missing filterRobotPolicies parameter for system robots
evaluators = evaluators.Add(rbac_project.NewEvaluator(s.ctl, rbac_project.NewBuilderForPolicies(s.GetUsername(), proPolicies, filterRobotPolicies)))

Root cause: System robots were missing consistent RBAC policy filtering - project-level robots had filterRobotPolicies but system robots didn't, creating permission inconsistencies.

Additional changes:

  • Enhanced robot.go with hasWildcardRobotPermission() method for wildcard validation
  • Updated requireAccess() to handle system robot wildcard permissions
  • Improved CreateRobot() permission validation logic

Testing completed:

Areas needing review:

  • RBAC changes for unintended permission side effects
  • Security implications of the filterRobotPolicies addition
  • Validation that wildcard permission logic is sound
  • Harbor-specific patterns I may have missed

This is a focused fix addressing the specific permission gap, but given the RBAC implications I'd appreciate careful review.

Fixes #21406

Copy link

codecov bot commented Sep 13, 2025

Codecov Report

❌ Patch coverage is 34.37500% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.88%. Comparing base (c8c11b4) to head (f705aac).
⚠️ Report is 568 commits behind head on main.

Files with missing lines Patch % Lines
src/server/v2.0/handler/robot.go 27.58% 21 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main   #22352       +/-   ##
===========================================
+ Coverage   45.36%   65.88%   +20.51%     
===========================================
  Files         244     1072      +828     
  Lines       13333   115962   +102629     
  Branches     2719     2927      +208     
===========================================
+ Hits         6049    76397    +70348     
- Misses       6983    35331    +28348     
- Partials      301     4234     +3933     
Flag Coverage Δ
unittests 65.88% <34.37%> (+20.51%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/common/security/robot/context.go 93.15% <100.00%> (ø)
src/server/v2.0/handler/robot.go 14.17% <27.58%> (ø)

... and 984 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Quantum-Sicarius
Copy link
Author

I've pushed two additional commits:

Commit 952ea2a - Formatting

  • Applied gofmt to Go files
  • Applied black to Python files
  • May have changed Python formatting from project standards - let me know if this should be reverted

Commit 671c112 - Tests

  • Added TestHasWildcardRobotPermission unit test with 9 cases covering the new helper function
  • Updated integration test test_03_SystemRobotCreatesProjectRobot to include required repository:pull permission

The 163 line increase is mostly test code (155 lines). The original implementation remains unchanged.

Copy link
Contributor

@bupd bupd left a comment

Choose a reason for hiding this comment

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

Overall LGTM,

Tested, it works I can now create Project Robot Accounts with system robot account

I would suggest to remove the additional formatting in test_robot_account.py

@Quantum-Sicarius Quantum-Sicarius force-pushed the 21406-fix-system-robot-create-project-robot branch from 671c112 to c267182 Compare September 15, 2025 17:02
…roject robots

System robots with wildcard project permissions (/project/*/robot) were unable
to create project-level robots due to insufficient RBAC validation. This fix
enhances the permission validation logic with two layers:

1. Enhanced requireAccess() method to handle wildcard permissions for system robots
2. Added fallback creator robot lookup in CreateRobot() method

Also includes helper function hasWildcardRobotPermission() to reduce code duplication
and comprehensive integration test.

Fixes goharbor#21406

Signed-off-by: Thomas <thomas@quantum-sicarius.za.net>
Signed-off-by: Thomas Scholtz <thomas@labs.epiuse.com>
- Run gofmt on Go files to fix formatting issues
- Apply black formatter to Python test file
- Fix Python linting issues (unused imports, comparison style)
- Remove unused local variables in Python tests

This resolves CI formatting failures.

Signed-off-by: Thomas Scholtz <thomas@labs.epiuse.com>
…ements

- Add TestHasWildcardRobotPermission with 9 test cases covering:
  - Positive cases: wildcard project permissions for robot actions
  - Negative cases: wrong resource, action, scope, or nil permissions
  - Edge cases: multiple permissions and boundary conditions

- Enhance test_03_SystemRobotCreatesProjectRobot integration test:
  - Add repository:pull permission to work around robot library constraints
  - Improve test documentation and permission setup
  - Ensure test properly validates system robot creation capabilities

- Validates privilege escalation prevention in existing test suite
- Ensures comprehensive coverage of wildcard permission scenarios
- Provides thorough testing of system robot functionality

The unit tests verify the core hasWildcardRobotPermission helper function
that enables system robots with wildcard permissions to create project
robots while maintaining security boundaries and preventing privilege
escalation.

Signed-off-by: Thomas Scholtz <thomas@labs.epiuse.com>
- Revert excessive black formatting changes from previous commit
- Remove unused harbor_url import from test_robot_account.py
- Preserve test_03_SystemRobotCreatesProjectRobot functionality
- Maintain original project formatting style for maintainer review

This addresses maintainer feedback to undo black formatting while
keeping functional improvements and the new integration test intact.

Signed-off-by: Thomas Scholtz <thomas@labs.epiuse.com>
@Quantum-Sicarius Quantum-Sicarius force-pushed the 21406-fix-system-robot-create-project-robot branch from c267182 to f705aac Compare September 18, 2025 13:31
@Vad1mo Vad1mo self-requested a review September 18, 2025 14:35
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.

Error when creating project Robot Accounts using System Robot Accounts
6 participants