1313require_relative 'buildpack'
1414
1515module VCAP ::CloudController
16- class ProcessModel < Sequel ::Model ( :processes )
16+ class ProcessModel < Sequel ::Model ( :processes ) # rubocop:disable Metrics/ClassLength
1717 include Serializer
1818
1919 plugin :serialization
@@ -34,7 +34,8 @@ def after_initialize
3434 NO_APP_PORT_SPECIFIED = -1
3535 DEFAULT_HTTP_PORT = 8080
3636 DEFAULT_PORTS = [ DEFAULT_HTTP_PORT ] . freeze
37- UNLIMITED_LOG_RATE = -1
37+ DEFAULT_USER = 'vcap' . freeze
38+ UNLIMITED_LOG_RATE = -1
3839
3940 many_to_one :app , class : 'VCAP::CloudController::AppModel' , key : :app_guid , primary_key : :guid , without_guid_generation : true
4041 many_to_one :revision , class : 'VCAP::CloudController::RevisionModel' , key : :revision_guid , primary_key : :guid , without_guid_generation : true
@@ -267,7 +268,8 @@ def validation_policies
267268 ReadinessHealthCheckPolicy . new ( self , readiness_health_check_invocation_timeout , readiness_health_check_type , readiness_health_check_http_endpoint ,
268269 readiness_health_check_interval ) ,
269270 DockerPolicy . new ( self ) ,
270- PortsPolicy . new ( self )
271+ PortsPolicy . new ( self ) ,
272+ ProcessUserPolicy . new ( self , permitted_users )
271273 ]
272274 end
273275
@@ -391,6 +393,12 @@ def started_command
391393 specified_commands [ type ] || revision . droplet &.process_start_command ( type ) || ''
392394 end
393395
396+ def run_action_user
397+ return user if user . present?
398+
399+ docker? ? docker_run_action_user : DEFAULT_USER
400+ end
401+
394402 def specified_or_detected_command
395403 command . presence || detected_start_command
396404 end
@@ -446,15 +454,15 @@ def debug
446454
447455 delegate :cnb? , to : :app
448456
457+ delegate :windows_gmsa_credential_refs , to : :app
458+
449459 def database_uri
450460 service_binding_uris = service_bindings . map do |binding |
451461 binding . credentials [ 'uri' ] if binding . credentials . present?
452462 end . compact
453463 DatabaseUriGenerator . new ( service_binding_uris ) . database_uri
454464 end
455465
456- delegate :windows_gmsa_credential_refs , to : :app
457-
458466 def max_app_disk_in_mb
459467 VCAP ::CloudController ::Config . config . get ( :maximum_app_disk_in_mb )
460468 end
@@ -564,6 +572,18 @@ def open_ports
564572
565573 private
566574
575+ def permitted_users
576+ Set . new ( [ DEFAULT_USER ] ) + Config . config . get ( :additional_allowed_process_users )
577+ end
578+
579+ def docker_run_action_user
580+ return DEFAULT_USER unless docker?
581+
582+ docker_exec_metadata = Oj . load ( execution_metadata )
583+ container_user = docker_exec_metadata [ 'user' ]
584+ container_user . presence || 'root'
585+ end
586+
567587 def non_unique_process_types
568588 return [ ] unless app
569589
0 commit comments