Skip to content

feat: add namespace blocking functionality for JWT authentication - #313

Merged
domdomegg merged 4 commits into
mainfrom
adamj/blocked-namespaces
Aug 27, 2025
Merged

domdomegg merged 4 commits into
mainfrom
adamj/blocked-namespaces

Conversation

@domdomegg

Copy link
Copy Markdown
Member

Summary

Implements a denylist mechanism to prevent blocked namespaces from publishing packages:

  • Added BlockedNamespaces field to JWTManager struct for maintaining the denylist
  • Added validation logic in GenerateTokenResponse that checks user permissions against blocked namespaces
  • Admins with global permissions (*) bypass the blocking logic
  • Added comprehensive test coverage for all blocking scenarios

Fixes #98

Implements a denylist mechanism to block specific namespaces from publishing packages. Admins with global permissions bypass the blocking logic. This addresses namespace abuse prevention requirements.

Fixes #98

🏠 Remote-Dev: homespace
Comment thread internal/auth/blocks.go

// BlockedNamespaces contains a list of namespaces that are not allowed to publish packages.
// This is used as a denylist mechanism to prevent abuse.
var BlockedNamespaces = []string{

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

note: why a file and not a database table?

  • git gives us free audit, access control (e.g. 2PC via GitHub required reviews)
  • we expect this list to be pretty small and infrequently updated
  • do the simple thing that works: can add the db table later if needed

@domdomegg

Copy link
Copy Markdown
Member Author

@claude please review

@claude

claude Bot commented Aug 27, 2025 •

Copy link
Copy Markdown
Contributor

Claude finished @domdomegg's task —— View job


Code Review: Namespace Blocking Implementation

Overall solid implementation with good test coverage. The approach is clean and the security logic is sound. A few observations below:

Detailed Review Findings

✅ Strengths

Security Design:

  • Proper admin bypass logic using global permissions (* pattern)
  • Blocking check happens before token generation, preventing unauthorized access
  • Clear error messages guide users to raise issues if blocked incorrectly

Implementation Quality:

  • Clean separation of concerns with blocks.go containing the denylist
  • Comprehensive test coverage (100% of blocking scenarios)
  • Good use of existing HasPermission method for consistency

Code Quality:

  • Well-documented functions and clear variable names
  • Proper error handling and meaningful error messages
  • Test setup includes proper cleanup with defer statements

🔍 Minor Considerations

File Organization (internal/auth/blocks.go:5)

  • Your rationale for using a file vs database makes sense for this use case
  • Consider adding a comment about the audit trail benefit for future maintainers

Edge Case Handling (internal/auth/jwt.go:87)

  • The blocking logic appends /test to check permissions: blockedNamespace+"/test"
  • This works correctly but might be unclear to future readers
  • Consider extracting to a constant or adding a comment explaining why /test is used

Test Isolation (internal/auth/jwt_test.go:301-303)

  • Tests modify global BlockedNamespaces variable with proper cleanup
  • This pattern works but could be fragile if tests run in parallel
  • Consider dependency injection for the blocked namespaces list in future refactoring

🎯 Specific Code References

  • Global admin bypass: internal/auth/jwt.go:75-82 correctly identifies * permissions
  • Blocking validation: internal/auth/jwt.go:84-91 properly skips blocking for admins
  • Error handling: internal/auth/jwt.go:88 provides helpful error message with issue reporting URL
  • Test coverage: internal/auth/jwt_test.go:287-400 covers all critical scenarios

Recommendation: ✅ Approve

This implementation correctly addresses issue #98 with a secure, well-tested approach. The file-based denylist is appropriate for the expected small scale and infrequent updates.


@domdomegg
domdomegg merged commit 9d04671 into main Aug 27, 2025
8 checks passed
@domdomegg
domdomegg deleted the adamj/blocked-namespaces branch August 27, 2025 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow blacklisting GitHub users, organizations, or DNS namespaces

2 participants