Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 35c98c9

Browse files
njbennettJaskanwal Pawar
andcommitted
Make basic auth for internal staging completion endpoints optional
- Optional specifically only when Kubernetes configuration is provided [#175080278] Co-authored-by: Nat Bennett <nbennett@pivotal.io> Co-authored-by: Jaskanwal Pawar <jpawar@pivotal.io>
1 parent 72f2de6 commit 35c98c9

5 files changed

Lines changed: 36 additions & 14 deletions

File tree

app/controllers/internal/staging_completion_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def self.dependencies
1515
def initialize(*)
1616
super
1717
auth = Rack::Auth::Basic::Request.new(env)
18+
19+
if Config.kubernetes_api_configured?
20+
return
21+
end
22+
1823
unless auth.provided? && auth.basic? && auth.credentials == InternalApi.credentials
1924
raise CloudController::Errors::NotAuthenticated
2025
end

lib/cloud_controller/config_schemas/api_schema.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ class ApiSchema < VCAP::Config
9696
auth_password: String,
9797
},
9898

99-
internal_api: {
100-
auth_user: String,
101-
auth_password: String,
102-
},
10399

104100
staging: {
105101
timeout_in_seconds: Integer,
@@ -393,6 +389,11 @@ class ApiSchema < VCAP::Config
393389
optional(:temporary_oci_buildpack_mode) => enum('oci-phase-1', NilClass),
394390
enable_declarative_asset_downloads: bool,
395391
},
392+
393+
internal_api: {
394+
auth_user: String,
395+
auth_password: String,
396+
},
396397
),
397398

398399
}

lib/cloud_controller/config_schemas/clock_schema.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ class ClockSchema < VCAP::Config
5656
optional(:ca_cert_path) => String,
5757
},
5858

59-
internal_api: {
60-
auth_user: String,
61-
auth_password: String,
62-
},
63-
6459
staging: {
6560
timeout_in_seconds: Integer,
6661
**VCAP::Config::Dsl.omit_on_k8s(
@@ -216,6 +211,11 @@ class ClockSchema < VCAP::Config
216211
optional(:temporary_oci_buildpack_mode) => enum('oci-phase-1', NilClass),
217212
enable_declarative_asset_downloads: bool,
218213
},
214+
215+
internal_api: {
216+
auth_user: String,
217+
auth_password: String,
218+
},
219219
),
220220
}
221221
end

lib/cloud_controller/config_schemas/worker_schema.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ class WorkerSchema < VCAP::Config
4747
optional(:ca_cert_path) => String,
4848
},
4949

50-
internal_api: {
51-
auth_user: String,
52-
auth_password: String,
53-
},
54-
5550
staging: {
5651
timeout_in_seconds: Integer,
5752
**VCAP::Config::Dsl.omit_on_k8s(
@@ -221,6 +216,11 @@ class WorkerSchema < VCAP::Config
221216
optional(:temporary_oci_buildpack_mode) => enum('oci-phase-1', NilClass),
222217
enable_declarative_asset_downloads: bool,
223218
},
219+
220+
internal_api: {
221+
auth_user: String,
222+
auth_password: String,
223+
},
224224
),
225225
}
226226
end

spec/unit/controllers/internal/staging_completion_controller_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ module VCAP::CloudController
3939
let(:one_hour_in_nanoseconds) { (1.hour.to_i * 1e9).to_i }
4040

4141
before do
42+
TestConfig.override({ kubernetes: nil })
43+
4244
allow(VCAP::CloudController::Metrics::StatsdUpdater).to receive(:new).and_return(statsd_updater)
4345
end
4446

@@ -184,6 +186,20 @@ module VCAP::CloudController
184186
end
185187

186188
describe 'authentication' do
189+
context 'when running in Kubernetes' do
190+
before do
191+
TestConfig.override({ kubernetes: { host_url: 'example.com' } })
192+
end
193+
194+
context 'when missing authentication' do
195+
it 'succeeds' do
196+
header('Authorization', nil)
197+
post url, MultiJson.dump(staging_response)
198+
expect(last_response.status).to eq(200)
199+
end
200+
end
201+
end
202+
187203
context 'when missing authentication' do
188204
it 'fails with authentication required' do
189205
header('Authorization', nil)

0 commit comments

Comments
 (0)