Class: LittleGhost::Network::AuthorizerServer
- Inherits:
-
Object
- Object
- LittleGhost::Network::AuthorizerServer
- Defined in:
- lib/little_ghost/network/authorizer_server.rb
Overview
Serves Envoy's headers-only external authorization protocol over a private Unix socket. Application callbacks are trusted and execute in the host.
Constant Summary collapse
- MAX_HEADER_BYTES =
:nodoc:
32_768- MAX_CLIENTS =
64- READ_TIMEOUT =
5- SHUTDOWN_TIMEOUT =
1- ALWAYS_REMOVE =
%w[authorization proxy-authorization cookie x-forwarded-for x-forwarded-host x-forwarded-proto].freeze
Instance Attribute Summary collapse
-
#socket_path ⇒ Object
readonly
Returns the value of attribute socket_path.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(socket_path:, authorizer:, run: nil) ⇒ AuthorizerServer
constructor
A new instance of AuthorizerServer.
- #start ⇒ Object
Constructor Details
#initialize(socket_path:, authorizer:, run: nil) ⇒ AuthorizerServer
Returns a new instance of AuthorizerServer.
18 19 20 21 22 23 24 25 26 |
# File 'lib/little_ghost/network/authorizer_server.rb', line 18 def initialize(socket_path:, authorizer:, run: nil) @socket_path = socket_path @authorizer = @run = run @mutex = Mutex.new @clients = [] @workers = [] @stopping = false end |
Instance Attribute Details
#socket_path ⇒ Object (readonly)
Returns the value of attribute socket_path.
28 29 30 |
# File 'lib/little_ghost/network/authorizer_server.rb', line 28 def socket_path @socket_path end |
Instance Method Details
#close ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/little_ghost/network/authorizer_server.rb', line 38 def close @stopping = true @server&.close unless @server&.closed? clients, workers = @mutex.synchronize { [@clients.dup, @workers.dup] } clients.each { |client| client.close unless client.closed? } workers.each do |worker| next if worker.join(SHUTDOWN_TIMEOUT) worker.kill worker.join end @thread&.join unless @thread == Thread.current File.unlink(socket_path) if File.exist?(socket_path) nil end |
#start ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/little_ghost/network/authorizer_server.rb', line 30 def start File.unlink(socket_path) if File.exist?(socket_path) @server = UNIXServer.new(socket_path) File.chmod(0o600, socket_path) @thread = Thread.new { serve } self end |