Skip to content

Commit f05e01c

Browse files
authored
Add ability to specify the process user in manifests (#4416)
1 parent fdc1c3d commit f05e01c

File tree

9 files changed

+128
-3
lines changed

9 files changed

+128
-3
lines changed

app/actions/space_diff_manifest.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def filter_manifest_app_hash(manifest_app_hash)
9898
hash.slice(
9999
'type',
100100
'command',
101+
'user',
101102
'disk_quota',
102103
'log-rate-limit-per-second',
103104
'health-check-http-endpoint',

app/messages/app_manifest_message.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def process_update_attributes_from_app_level
262262
def process_update_attributes_from_process(params)
263263
mapping = {}
264264
mapping[:command] = params[:command] || 'null' if params.key?(:command)
265+
mapping[:user] = params[:user] if params.key?(:user)
265266
mapping[:health_check_http_endpoint] = params[:health_check_http_endpoint] if params.key?(:health_check_http_endpoint)
266267
mapping[:health_check_timeout] = params[:health_check_timeout] if params.key?(:health_check_timeout)
267268
mapping[:health_check_invocation_timeout] = params[:health_check_invocation_timeout] if params.key?(:health_check_invocation_timeout)

app/messages/manifest_process_update_message.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module VCAP::CloudController
55
class ManifestProcessUpdateMessage < BaseMessage
66
register_allowed_keys %i[
77
command
8+
user
89
health_check_http_endpoint
910
health_check_invocation_timeout
1011
health_check_type
@@ -34,6 +35,12 @@ def self.readiness_health_check_endpoint_and_type_requested?
3435
length: { in: 1..4096, message: 'must be between 1 and 4096 characters' },
3536
if: proc { |a| a.requested?(:command) }
3637

38+
validates :user,
39+
string: true,
40+
allow_nil: true,
41+
length: { in: 1..255, message: 'must be between 1 and 255 characters' },
42+
if: proc { |a| a.requested?(:user) }
43+
3744
validates :health_check_type,
3845
inclusion: {
3946
in: [HealthCheckTypes::PORT, HealthCheckTypes::PROCESS, HealthCheckTypes::HTTP],

app/presenters/v3/app_manifest_presenters/process_properties_presenter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def process_hash(process)
1616
'disk_quota' => add_units(process.disk_quota),
1717
'log-rate-limit-per-second' => add_units_log_rate_limit(process.log_rate_limit),
1818
'command' => process.command,
19+
'user' => process.user,
1920
'health-check-type' => process.health_check_type,
2021
'health-check-http-endpoint' => process.health_check_http_endpoint,
2122
'health-check-invocation-timeout' => process.health_check_invocation_timeout,

docs/v3/source/includes/resources/manifests/_object.md.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ applications:
5454
memory: 500M
5555
log-rate-limit-per-second: 1KB
5656
timeout: 10
57+
user: vcap
5758
- type: worker
5859
command: start-worker.sh
5960
disk_quota: 1G
@@ -122,6 +123,7 @@ Name | Type | Description
122123
---- | ---- | -----------
123124
**type** | _string_ | **(Required)** The identifier for the processes to be configured
124125
**command** | _string_ | The command used to start the process; this overrides start commands from [Procfiles](#procfiles) and buildpacks
126+
**user** | _string_ | The user under which the process runs
125127
**disk_quota** | _string_ | The disk limit for all instances of the web process; <br>this attribute requires a unit of measurement: `B`, `K`, `KB`, `M`, `MB`, `G`, `GB`, `T`, or `TB` in upper case or lower case
126128
**health-check-http-endpoint** | _string_ | Endpoint called to determine if the app is healthy
127129
**health-check-interval** | _integer_ | The interval in seconds between health check requests

spec/unit/actions/space_diff_manifest_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,16 @@ module VCAP::CloudController
8484
end
8585

8686
context 'processes' do
87-
context 'when processes are added' do
87+
context 'when processes are updated' do
8888
before do
8989
default_manifest['applications'][0]['processes'][0]['memory'] = '2048M'
90+
default_manifest['applications'][0]['processes'][0]['user'] = 'ContainerUser'
9091
end
9192

9293
it 'returns the correct diff' do
9394
expect(subject).to contain_exactly(
94-
{ 'op' => 'replace', 'path' => '/applications/0/processes/0/memory', 'was' => "#{process1.memory}M", 'value' => '2048M' }
95+
{ 'op' => 'replace', 'path' => '/applications/0/processes/0/memory', 'was' => "#{process1.memory}M", 'value' => '2048M' },
96+
{ 'op' => 'add', 'path' => '/applications/0/processes/0/user', 'value' => 'ContainerUser' }
9597
)
9698
end
9799
end

spec/unit/messages/app_manifest_message_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ module VCAP::CloudController
721721
'readiness_health_check_http_endpoint' => 'potato potahto',
722722
'readiness_health_check_interval' => 'yucca',
723723
'command' => '',
724+
'user' => '',
724725
'timeout' => 'yam'
725726
}
726727
end
@@ -738,6 +739,7 @@ module VCAP::CloudController
738739
'readiness_health_check_invocation_timeout' => 'cat-jicima',
739740
'readiness_health_check_interval' => -1,
740741
'command' => '',
742+
'user' => '',
741743
'timeout' => 'yam'
742744
}
743745
end
@@ -751,10 +753,11 @@ module VCAP::CloudController
751753
it 'includes the type of the process in the error message' do
752754
message = AppManifestMessage.create_from_yml(params_from_yaml)
753755
expect(message).not_to be_valid
754-
expect(message.errors).to have(27).items
756+
expect(message.errors).to have(29).items
755757

756758
expected_errors = [
757759
'Process "type1": Command must be between 1 and 4096 characters',
760+
'Process "type1": User must be between 1 and 255 characters',
758761
'Process "type1": Disk quota must use a supported unit: B, K, KB, M, MB, G, GB, T, or TB',
759762
'Process "type1": Log rate limit per second is not a number',
760763
'Process "type1": Instances must be greater than or equal to 0',
@@ -770,6 +773,7 @@ module VCAP::CloudController
770773
'Process "type1": Readiness health check http endpoint must be a valid URI path',
771774
'Process "type1": Readiness health check type must be "http" to set a health check HTTP endpoint',
772775
'Process "type2": Command must be between 1 and 4096 characters',
776+
'Process "type2": User must be between 1 and 255 characters',
773777
'Process "type2": Disk quota must use a supported unit: B, K, KB, M, MB, G, GB, T, or TB',
774778
'Process "type2": Log rate limit per second must use a supported unit: B, K, KB, M, MB, G, GB, T, or TB',
775779
'Process "type2": Instances is not a number',

spec/unit/messages/manifest_process_update_message_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,59 @@ module VCAP::CloudController
6262
expect(message.errors[:command]).to include('must be between 1 and 4096 characters')
6363
end
6464
end
65+
66+
context 'when command is just right' do
67+
let(:params) { { command: './start.sh' } }
68+
69+
it 'is valid' do
70+
expect(message).to be_valid
71+
end
72+
end
73+
end
74+
75+
describe 'user' do
76+
context 'when user is not a string' do
77+
let(:params) { { user: 32.77 } }
78+
79+
it 'is valid' do
80+
expect(message).not_to be_valid
81+
expect(message.errors[:user]).to include('must be a string')
82+
end
83+
end
84+
85+
context 'when user is nil' do
86+
let(:params) { { user: nil } }
87+
88+
it 'is not valid' do
89+
expect(message).to be_valid
90+
end
91+
end
92+
93+
context 'when user is too long' do
94+
let(:params) { { user: 'a' * 256 } }
95+
96+
it 'is not valid' do
97+
expect(message).not_to be_valid
98+
expect(message.errors[:user]).to include('must be between 1 and 255 characters')
99+
end
100+
end
101+
102+
context 'when user is empty' do
103+
let(:params) { { user: '' } }
104+
105+
it 'is not valid' do
106+
expect(message).not_to be_valid
107+
expect(message.errors[:user]).to include('must be between 1 and 255 characters')
108+
end
109+
end
110+
111+
context 'when user is just right' do
112+
let(:params) { { command: 'vcap' } }
113+
114+
it 'is valid' do
115+
expect(message).to be_valid
116+
end
117+
end
65118
end
66119

67120
describe 'health_check_type' do

spec/unit/presenters/v3/app_manifest_presenters/process_properties_presenter_spec.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,60 @@ module VCAP::CloudController::Presenters::V3::AppManifestPresenters
6767
'timeout' => 30
6868
})
6969
end
70+
71+
context 'nullable fields' do
72+
context 'when command is present' do
73+
let(:process) do
74+
VCAP::CloudController::ProcessModel.make(
75+
command: './start-command'
76+
)
77+
end
78+
79+
it 'includes command in the hash' do
80+
hash = subject.process_hash(process)
81+
expect(hash).to include('command' => './start-command')
82+
end
83+
end
84+
85+
context 'when command is not present' do
86+
let(:process) do
87+
VCAP::CloudController::ProcessModel.make(
88+
command: nil
89+
)
90+
end
91+
92+
it 'does not include command in the hash' do
93+
hash = subject.process_hash(process)
94+
expect(hash).not_to include('command')
95+
end
96+
end
97+
98+
context 'when user is present' do
99+
let(:process) do
100+
VCAP::CloudController::ProcessModel.make(
101+
user: 'ContainerUser'
102+
)
103+
end
104+
105+
it 'includes user in the hash' do
106+
hash = subject.process_hash(process)
107+
expect(hash).to include('user' => 'ContainerUser')
108+
end
109+
end
110+
111+
context 'when user is not present' do
112+
let(:process) do
113+
VCAP::CloudController::ProcessModel.make(
114+
user: nil
115+
)
116+
end
117+
118+
it 'does not include user in the hash' do
119+
hash = subject.process_hash(process)
120+
expect(hash).not_to include('user')
121+
end
122+
end
123+
end
70124
end
71125

72126
describe '#add_units_log_rate_limit' do

0 commit comments

Comments
 (0)