Skip to content

Enhance add-access-rule command UX with intuitive name-based flags#3758

Draft
rkoster wants to merge 1 commit intomainfrom
enhance-add-access-rule-ux
Draft

Enhance add-access-rule command UX with intuitive name-based flags#3758
rkoster wants to merge 1 commit intomainfrom
enhance-add-access-rule-ux

Conversation

@rkoster
Copy link
Copy Markdown

@rkoster rkoster commented Apr 10, 2026

Summary

This PR enhances the user experience of the add-access-rule command by replacing the positional GUID-based SELECTOR argument with intuitive flags that accept human-readable names and support cross-space/org resolution.

Related to: cloudfoundry/community#1438

Motivation

The original add-access-rule command required users to manually construct GUID-based selectors (e.g., cf:app:d76446a1-f429-4444-8797-be2f78b75b08), which was cumbersome and error-prone. This PR follows CF CLI conventions from commands like add-network-policy to provide a more user-friendly interface.

Changes

Command Interface Improvements

Before:

cf add-access-rule allow-frontend apps.identity cf:app:d76446a1-f429-4444-8797-be2f78b75b08 --hostname backend

After:

# Simple case - app in current space
cf add-access-rule allow-frontend apps.identity --source-app frontend-app --hostname backend

# Cross-space access
cf add-access-rule allow-other apps.identity --source-app api-client --source-space other-space --hostname backend

# Cross-org access
cf add-access-rule allow-prod apps.identity --source-app client --source-space prod-space --source-org prod-org --hostname api

# Space-level rule
cf add-access-rule allow-monitoring apps.identity --source-space monitoring --hostname api

# Org-level rule
cf add-access-rule allow-platform apps.identity --source-org platform --hostname shared-api

# Any authenticated app
cf add-access-rule allow-all apps.identity --source-any --hostname public-api

# Advanced: raw selector still supported
cf add-access-rule allow-raw apps.identity --selector cf:app:GUID --hostname backend

New Flags

  • --source-app APP_NAME - Specify source app by name (resolves to GUID)
  • --source-space SPACE_NAME - Specify space context for app lookup or create space-level rule
  • --source-org ORG_NAME - Specify org context for space/app lookup or create org-level rule
  • --source-any - Allow any authenticated app
  • --selector SELECTOR - Raw GUID-based selector for advanced users

Terminology Update

  • Renamed all "target" terminology to "source" throughout codebase
  • Access rules specify the source (who can access), not the target
  • Updated AccessRuleWithRoute.TargetNameSourceName
  • Updated resolveAccessRuleTarget()resolveAccessRuleSource()
  • Updated access-rules list command table header: "target" → "source"

Enhanced Output

The command now displays verbose output showing both human-readable source and the resolved selector:

Adding access rule allow-frontend for route backend.apps.identity as admin...
  scope: app, source: frontend-app
  selector: cf:app:d76446a1-f429-4444-8797-be2f78b75b08
OK

Validation & Error Handling

  • Validates exactly one primary source is specified
  • Provides helpful error messages when app not found in current space
  • Suggests using --source-space and --source-org flags for cross-space/org access
  • Follows CF CLI patterns from add-network-policy command

Domain Integration

  • Added --enforce-access-rules and --access-rules-scope flags to create-shared-domain and create-private-domain commands
  • Updated domain resource with new fields

Testing

  • ✅ 17 comprehensive test cases for add-access-rule command
  • ✅ Updated 19 actor tests to use new SourceName field
  • ✅ All tests passing (36/36)
  • ✅ Covers validation, resolution, error handling, and cross-space/org scenarios

Breaking Changes

  • Removed positional SELECTOR argument - This is a breaking change, but acceptable since the access rules feature has not been released yet
  • Users must now use one of the new flags (--source-app, --source-space, --source-org, --source-any, or --selector) instead

Checklist

  • Tests added/updated and passing
  • Documentation (help text) updated
  • Breaking changes documented
  • Follows CF CLI conventions
  • Manual testing against live CF deployment (requires CAPI backend support)

Next Steps

This PR is marked as draft pending:

  1. Manual testing against a CF deployment with access rules API support
  2. Integration testing with full CF ecosystem
  3. Review from CF CLI maintainers

This commit improves the user experience for the add-access-rule command
by replacing the positional GUID-based SELECTOR argument with intuitive
flags that accept human-readable names and support cross-space/org resolution.

Changes:

**Command Interface:**
- Remove positional SELECTOR argument (breaking change, acceptable for unreleased feature)
- Add new flags: --source-app, --source-space, --source-org, --source-any, --selector
- Support hierarchical name resolution:
  - --source-app APP_NAME (looks in current space)
  - --source-app APP_NAME --source-space SPACE (cross-space in current org)
  - --source-app APP_NAME --source-space SPACE --source-org ORG (cross-org)
  - --source-space SPACE (space-level rule)
  - --source-org ORG (org-level rule)
  - --source-any (allow any authenticated app)
  - --selector SELECTOR (raw GUID-based selector for advanced users)
- Validate exactly one primary source is specified
- Display verbose output showing resolved selector for transparency

**Terminology Update:**
- Rename all "target" terminology to "source" throughout codebase
- Access rules specify the source (who can access), not the target
- Update AccessRuleWithRoute.TargetName → SourceName
- Update resolveAccessRuleTarget() → resolveAccessRuleSource()
- Update access-rules list command table header: "target" → "source"

**Error Handling:**
- Provide helpful error messages when app not found in current space
- Suggest using --source-space and --source-org flags for cross-space/org access
- Follow CF CLI patterns from add-network-policy command

**Testing:**
- Add 17 comprehensive test cases for add-access-rule command
- Update 19 actor tests to use new SourceName field
- All tests passing (36/36)

**Domain Integration:**
- Add enforce_access_rules support to create-shared-domain and create-private-domain
- Add --enforce-access-rules and --access-rules-scope flags
- Update domain resource with new fields

Examples:

  # Simple case - app in current space
  cf add-access-rule allow-frontend apps.identity --source-app frontend-app --hostname backend

  # Cross-space access
  cf add-access-rule allow-other apps.identity --source-app api-client --source-space other-space --hostname backend

  # Cross-org access
  cf add-access-rule allow-prod apps.identity --source-app client --source-space prod-space --source-org prod-org --hostname api

  # Space-level rule
  cf add-access-rule allow-monitoring apps.identity --source-space monitoring --hostname api

  # Org-level rule
  cf add-access-rule allow-platform apps.identity --source-org platform --hostname shared-api

  # Any authenticated app
  cf add-access-rule allow-all apps.identity --source-any --hostname public-api

Related to: cloudfoundry/community#1438
@rkoster
Copy link
Copy Markdown
Author

rkoster commented Apr 10, 2026

Don't worry about this PR just yet, just doing some more POC work on the RFC: cloudfoundry/community#1438

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.

1 participant