Skip to content

Commit 3791874

Browse files
committed
Add validation to prevent access rules on internal domains per RFC
Per RFC requirement (line 246-247): Access rules cannot be created for routes on internal domains (domains created with --internal). Internal routes use container-to-container networking and bypass GoRouter entirely, so GoRouter cannot enforce access rules. Changes: - Add validation in AccessRulesController#create to reject access rules on internal domains with 422 status - Add test coverage for internal domain validation - Error message explains why: internal domains bypass GoRouter
1 parent 9afa57a commit 3791874

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

app/controllers/v3/access_rules_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def create
4444
unauthorized! unless permission_queryer.can_write_to_active_space?(route.space.id)
4545
suspended! unless permission_queryer.is_space_active?(route.space.id)
4646

47+
if route.domain.internal?
48+
unprocessable!('Cannot create access rules for routes on internal domains. Internal routes use container-to-container networking and bypass GoRouter.')
49+
end
4750
unprocessable!("Cannot create access rules for route '#{route.guid}': the route's domain does not have enforce_access_rules enabled.") unless route.domain.enforce_access_rules
4851

4952
# Enforce cf:any exclusivity: if route already has a cf:any rule, reject new rules;

spec/request/access_rules_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616
let(:regular_domain) do
1717
VCAP::CloudController::PrivateDomain.make(owning_organization: org)
1818
end
19+
let(:internal_domain) do
20+
VCAP::CloudController::PrivateDomain.make(
21+
owning_organization: org,
22+
internal: true
23+
)
24+
end
1925

2026
let(:mtls_route) { VCAP::CloudController::Route.make(space: space, domain: mtls_domain) }
2127
let(:regular_route) { VCAP::CloudController::Route.make(space: space, domain: regular_domain) }
28+
let(:internal_route) { VCAP::CloudController::Route.make(space: space, domain: internal_domain) }
2229

2330
let(:valid_uuid) { '11111111-2222-3333-4444-555555555555' }
2431

@@ -93,6 +100,25 @@ def expected_rule_json(rule)
93100
end
94101
end
95102

103+
context 'when the route is on an internal domain' do
104+
let(:request_body) do
105+
{
106+
selector: "cf:app:#{valid_uuid}",
107+
relationships: {
108+
route: { data: { guid: internal_route.guid } }
109+
}
110+
}
111+
end
112+
113+
it 'returns 422 with a message about internal domains' do
114+
post '/v3/access_rules', request_body.to_json, admin_header
115+
116+
expect(last_response.status).to eq(422)
117+
expect(last_response.body).to include('internal domains')
118+
expect(last_response.body).to include('container-to-container networking')
119+
end
120+
end
121+
96122
context 'when the route does not exist' do
97123
let(:request_body) do
98124
{

0 commit comments

Comments
 (0)