-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Signal, Action and Policy System #5
Labels
Comments
This was referenced Dec 29, 2023
mostafa
changed the title
Refactor and extend the action system
The signal, action and policy system
Jan 28, 2024
mostafa
changed the title
The signal, action and policy system
The Signal, Action and Policy System
Jan 28, 2024
mostafa
changed the title
The Signal, Action and Policy System
Signal, Action and Policy System
Jan 28, 2024
9 tasks
mostafa
added a commit
to gatewayd-io/gatewayd
that referenced
this issue
Mar 1, 2024
This giant PR adds the very first version of the Act system that was proposed in [this proposal](gatewayd-io/proposals#5). The old way of signaling was static and only supported a single signal: `terminate`. The new system support more signals, adds proper policies that can be easily controlled by the users and the actions are executed in sync and async mode. The Act system consists of these components: 1. **Act Registry**: takes care of registering signals, policies and actions. It also applies policies to signals to produce outputs for actions and runs actions using those outputs. 2. **Signals**: plugins' hooks can return signal(s) as part of their request/response. These signals tell GatewayD what to do. 3. **Policies**: signals pass through predefined policies that will decide whether GatewayD should react to the signal or not. 4. **Actions**: actions run in sync or async mode and perform a function. Sync actions are used to control traffic (passthrough, terminate, etc.) and other parts of the system, and async actions can other things (log, publish a message to Kafka, etc.). 5. **Plugin Registry**: after running a hook on each plugin, the signals are extracted and the policies are applied to those signals. The output of those policy evaluations are returned to the caller, which knows how to run action and use its results. And the code spans over two projects: 1. **GatewayD**: all the above components of the Act system are in GatewayD. 2. **SDK**: types and helper functions for creating and exporting signals are in the SDK. ### Breaking changes The old way of terminating requests don't work anymore, as it was refactored in #442 and all the plugins are updated to pick up the changes.
smnmna99
pushed a commit
to gatewayd-io/gatewayd
that referenced
this issue
Mar 13, 2024
This giant PR adds the very first version of the Act system that was proposed in [this proposal](gatewayd-io/proposals#5). The old way of signaling was static and only supported a single signal: `terminate`. The new system support more signals, adds proper policies that can be easily controlled by the users and the actions are executed in sync and async mode. The Act system consists of these components: 1. **Act Registry**: takes care of registering signals, policies and actions. It also applies policies to signals to produce outputs for actions and runs actions using those outputs. 2. **Signals**: plugins' hooks can return signal(s) as part of their request/response. These signals tell GatewayD what to do. 3. **Policies**: signals pass through predefined policies that will decide whether GatewayD should react to the signal or not. 4. **Actions**: actions run in sync or async mode and perform a function. Sync actions are used to control traffic (passthrough, terminate, etc.) and other parts of the system, and async actions can other things (log, publish a message to Kafka, etc.). 5. **Plugin Registry**: after running a hook on each plugin, the signals are extracted and the policies are applied to those signals. The output of those policy evaluations are returned to the caller, which knows how to run action and use its results. And the code spans over two projects: 1. **GatewayD**: all the above components of the Act system are in GatewayD. 2. **SDK**: types and helper functions for creating and exporting signals are in the SDK. ### Breaking changes The old way of terminating requests don't work anymore, as it was refactored in #442 and all the plugins are updated to pick up the changes.
14 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Problem
When proxying requests and responses between the client(s) and the database in the proxy object, the traffic hooks are called. These hooks allow the plugins to inspect and possibly modify the traffic, provided that they register to those hooks. The return value of the hook functions contain two essential fields (key-value) in the
req.Fields
orresp.Fields
:request
(bytes): the binary request from the client(s).response
(bytes): the binary response from the database or injected by the plugin(s).The plugins can inspect and return a modified request and/or response. Then, GatewayD decides what to do with the modified request and/or response.
Plugins can also influence the traffic flow. To enable this, they should return an extra field to signal GatewayD to terminate the request. The
terminate
(boolean) is a "signal" that dictates an "action" to be taken by GatewayD.GatewayD detects the
terminate
signal and decides whether to act on the signal or not based on a policy, called the termination policy. The termination policy takes either of the following values:stop
(default): terminates the request and returns the response injected into therequest.Fields
by the plugin to the client.continue
: disregards the signal and continues the traffic flow, thus forwarding the packet to the database.The
terminate
signal should be injected into therequest.Fields
and returned by theOnTrafficFromClient
hook function. And only theOnTrafficFromClient
can return this signal (plus a normal or error response) to influence the traffic flow.terminate
Solution
An action system should be developed to account for actions other than just termination of the request:
terminate
signal is returned by the plugin'sOnTrafficFromClient
. The termination policy controls whether to run the action or not. Act system gatewayd#451.terminate
and they should be always synchronous, while external actions queue jobs and run them asynchronously via runners (plugins). External actions can be either sync (?) or async. Make actions extensible via plugins and/or a scripting language gatewayd#467.terminate
action has a quick side-effect of terminating the request, yet calling an API might take more time (and possibly even fail), so it isn't ideal to run the action on the main goroutine. Note that the sync actions exposed by plugins should be called immediately and not queued. Add queueing for async actions gatewayd#464.gatewayd
and it should support multiple queueing systems. Add distributed runner for running actions gatewayd#472.Flowchart
Sequence diagram
Actions
The following is the list of built-in and custom actions.
GatewayD sync actions
terminate
(bool)signal.terminate == true && policy.terminate == "stop"
drop
?)disconnect
reject
transmit
/tx
allow
deny
block
discard
reset
disconnect
?)fallthough
route
forward
upgrade
police
set
noset
create
connect
?)limit
error
response
?)request
response
GatewayD async actions
log
metric
queue
conntrack
mirror
inspect
submit
for inspection?)record
quarantine
call
Plugin or custom actions
cache
alert
notify
run
webhook
rotate
reauth
ebpf
wasm
publish
/produce
subscribe
/consume
Custom debugger actions
debug
breakpoint
pause
step
next
?)continue
abort
Action storage/channel
Currently everything is passed around at the root level of the
request.Fields
.The action can be passed through in the context (metadata) to avoid clashing with the keys injected byThis needs to be abstracted away in something like gRPC metadata. The metadata is passed around in the context object, which is unidirectional from the client (GatewayD) to the server (plugins). However, the plugins can only pass data to GatewayD using the returnedHandleClientMessage
(specifically theTerminate
message) from the PostgreSQL wire protocol parser.request.Fields
(and theerror
, which is not designed for this task). This means that a custom field should be created to handle the action(s).Policies and actions
Note to self: Policies dictate actions. For example, a simple policy would be equality to a value
(query.where.id == 1)
. Policies can be stored anywhere, including a policy engine like OPA.TODO
Related
Resources
Resources
The text was updated successfully, but these errors were encountered: