Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions jobs/cloud_controller_ng/spec
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ consumes:
optional: true

properties:
cc.admin_token_network_policy.enabled:
description: Restrict validated administrative bearer tokens to allowed source networks before user creation and API authorization. Requires a Cloud Controller version supporting this policy. Empty allowed_cidrs denies all administrative tokens when enabled.
default: false
cc.admin_token_network_policy.allowed_cidrs:
description: Numeric IPv4/IPv6 addresses or CIDRs allowed to use administrative tokens after trusted proxy resolution and NAT. Use the same allowlist in UAA to restrict issuance and UAA usage.
default: []
cc.admin_token_network_policy.trusted_proxies:
description: Numeric addresses or CIDRs of actual ingress proxies (including Gorouters). Only these peers may supply forwarded source addresses. No proxies are trusted by default. Do not list client networks here; secure the Nginx-to-Puma Unix socket against untrusted local access.
default: []
cc.admin_token_network_policy.additional_protected_scopes:
description: Additional exact scope/authority names to protect beyond uaa.admin, cloud_controller.admin, cloud_controller.admin_read_only, cloud_controller.global_auditor, and zones.<id>.admin. Cannot remove built-in protected scopes.
default: []
ssl.skip_cert_verify:
description: "specifies that the job is allowed to skip ssl cert verification"
default: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ migration_psql_concurrent_statement_timeout_in_seconds: <%= p("ccdb.migration_ps
skip_bigint_id_migration: <%= p("ccdb.skip_bigint_id_migration") %>
login:
url: <%= p("login.enabled") ? login_url : uaa_url %>
admin_token_network_policy:
enabled: <%= p('cc.admin_token_network_policy.enabled') %>
allowed_cidrs: <%= p('cc.admin_token_network_policy.allowed_cidrs').to_json %>
trusted_proxies: <%= p('cc.admin_token_network_policy.trusted_proxies').to_json %>
additional_protected_scopes: <%= p('cc.admin_token_network_policy.additional_protected_scopes').to_json %>
uaa:
url: <%= uaa_url %>
internal_url: <%= "https://#{p("cc.uaa.internal_url")}:#{p("uaa.ssl.port")}" %>
Expand Down
6 changes: 4 additions & 2 deletions jobs/cloud_controller_ng/templates/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ limit_req_zone $http_authorization zone=<%= zone['name'] %>:10m rate=<%= zone['l
<% end %>
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real_IP "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_connect_timeout 10;
Expand Down Expand Up @@ -139,7 +140,8 @@ limit_req_zone $http_authorization zone=<%= zone['name'] %>:10m rate=<%= zone['l
<% end %>
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real_IP "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_connect_timeout 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
access_log /var/vcap/sys/log/cloud_controller_ng/nginx-access.log main;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real_IP "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_connect_timeout 10;
Expand Down Expand Up @@ -100,6 +101,10 @@ location ~ /v3/droplets/.*/upload {

# Pass altered request body to a backend
location @cc_uploads {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real_IP "";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://cloud_controller;
}

Expand Down
21 changes: 21 additions & 0 deletions spec/cloud_controller_ng/cloud_controller_ng_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,27 @@ module Test
end.not_to raise_error
end

describe 'administrative token network policy' do
it 'defaults to disabled with no allowed networks or trusted proxies' do
rendered = YAML.safe_load(template.render(merged_manifest_properties, consumes: links))
expect(rendered['admin_token_network_policy']).to eq(
'enabled' => false, 'allowed_cidrs' => [], 'trusted_proxies' => [], 'additional_protected_scopes' => []
)
end

it 'renders explicit policy networks, trusted proxies, and additional protected scopes' do
configured = {
'enabled' => true,
'allowed_cidrs' => ['192.0.2.0/24', '2001:db8::/32'],
'trusted_proxies' => ['10.0.0.1/32'],
'additional_protected_scopes' => ['clients.write']
}
merged_manifest_properties['cc']['admin_token_network_policy'] = configured
rendered = YAML.safe_load(template.render(merged_manifest_properties, consumes: links))
expect(rendered['admin_token_network_policy']).to eq(configured)
end
end

describe 'app_domains' do
it 'accepts a list of domain hashes and domain strings' do
template_hash = YAML.safe_load(template.render(merged_manifest_properties, consumes: links))
Expand Down
15 changes: 15 additions & 0 deletions spec/cloud_controller_ng/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ module Test
expect(@rendered_file).to include('log_format main escape=default')
end

it 'overwrites the canonical source header and removes its Rack-normalized alias on internal ingress' do
expect(@rendered_file).to include('X-Real-IP $remote_addr;', 'X-Real_IP "";')
expect(@rendered_file).not_to include('X-Real_IP $remote_addr;')
end

context 'when json escaping for access log is configured' do
let(:manifest_properties) { { 'cc' => { 'nginx_access_log_escaping' => 'json' } } }

Expand Down Expand Up @@ -111,6 +116,16 @@ module Test

describe 'nginx_external_endpoints.conf' do
let(:template) { job.template('config/nginx_external_endpoints.conf') }

it 'sanitizes the source headers in every public proxy location including uploads' do
rendered = template.render({}, consumes: {})
proxy_locations = rendered.scan(/location[^\{]+\{[^}]*proxy_pass\s+http:\/\/cloud_controller;[^}]*\}/)
expect(proxy_locations).not_to be_empty
proxy_locations.each do |location|
expect(location).to include('X-Real-IP $remote_addr;', 'X-Real_IP "";', 'X-Forwarded-For $proxy_add_x_forwarded_for;')
end
expect(rendered).not_to include('X-Real_IP $remote_addr;')
end
let(:manifest_properties) { {} }

before do
Expand Down
Loading