Skip to main content

Who changed what: audit records for API gateway configuration

Follow a gateway change through G8's role check, audit record and engine check, see why one is refused, and read what the record keeps afterwards.

By The G8 team Operations

What you will have at the end

You will know what happens between the moment someone selects Save in the G8 console and the moment the engine serves the new configuration, and what is written down at each step. Three attempts are walked through on a real Environment: a change a Viewer may not make, a change the engine refuses, and a change that goes through. Each leaves a record, and the records are read afterwards: in the audit log, in the CSV export, in the server’s log line and as markers on the Analytics chart.

Prerequisites

  • An Environment with a Route to change. The examples use payments-api and orders-api in the Environment Staging.
  • Two users: one with a role that manages Routes (nora.becker, the platform administrator here) and one with the Viewer role on the Environment (tom.weber).
  • Traffic on the Route and a Prometheus the Environment reads, for the last section.

Three questions an auditor asks

Ask an auditor what they need from an API gateway and you get three questions: who changed it, what exactly changed, and could anyone have changed it without a trace. G8 is built so that the answer to the third is no. The rest of this article shows the mechanism rather than asserting it.

What happens before a change is applied

A change made through G8 passes three checks, in this order, and each one that fails leaves a record of its own.

Role check. The person’s role in that Environment must carry the permission the change needs. tom.weber holds the Viewer role on Staging: the console shows him the Routes list but no Edit button, and a PUT on the Route sent with his session is refused with 403 and the permission it needed, routes.manage. The attempt is in the audit log as Access denied, with his name, the permission and the API route he called.

Audit record. For a change the role allows, G8 opens the audit record before it calls the engine. The record carries the actor, the Environment, the object and the configuration before the change; it is completed with the configuration after. A change that cannot be recorded is not applied.

Engine check. The engine validates the configuration. If it refuses, the console shows the refusal, nothing is applied and the audit record is completed as Failed, with the engine’s reason.

The audit log of Staging after the three attempts of this article, newest first: two refused saves by nora.becker, the denied attempt by tom.weber, and the successful changes before them.

The environment audit log with two Route updated rows marked Failed, an Access denied row for tom.weber marked Denied, and successful Route updated rows below Refusals are rows like any other. The Failed and Denied badges sit beside the action, and the Result filter at the top narrows the list to them.

A refusal under the field

Many mistakes never reach the engine. The console draws every form from the engine’s own schema, so a value the schema forbids is refused while you type. Here the Count of a limit-count Plugin was set to 0: the field turns red, the message sits under it, and the footer counts the fields that need attention. Nothing was sent, so nothing was recorded.

The limit-count form with Count set to 0, the field outlined in red and the message Count must be more than 0 under it A schema refusal stays in the form. The audit log starts where a request leaves the console.

A refusal by the engine

Some mistakes pass the schema and fail on the engine. The Raw JSON view of payments-api was edited to point at an Upstream that does not exist in the Environment, and saved. The console answers with the engine’s refusal under the editor, and the Route stays as it was: the engine still holds the old Upstream, which was checked afterwards against the engine directly.

The Raw JSON editor of payments-api with upstream_id set to an id that does not exist, the Save route button, and under it the message The engine refused the save The refusal names the field and the reason. The Unsaved changes marker stays on, because nothing was saved.

This attempt is in the audit log as Route updated · Failed, with the reason validation_failed, the detail upstream "00000000000000099999" does not exist in this environment, the field it concerns and the modified index of the Route before the attempt. The index after is empty: there is no after.

The denied attempt

Open the Access denied row and the record names what was tried and what was missing: the actor tom.weber and his session, the Environment, the permission routes.manage, the API route PUT /api/environments/{id}/gateway/routes/{rid} and the request id.

The Access denied audit record: actor tom.weber, reason missing_permission, permission routes.manage and the API route that was called A refused attempt keeps the permission it needed. That is the answer to “could they have changed it”: they tried, and this is what stopped them.

What a completed record keeps

A change that goes through has the same header, and a Change section below it. The limit-count Plugin on orders-api was changed to answer 429 instead of the engine’s default; the record shows the Route before and after, side by side, with the added line marked. Secrets are masked on both sides: the Redis password reads ••••, and a record whose masked values changed says so in a line under the diff.

The Change section of an audit record: the orders-api Route before and after, with the added line rejected_code 429 marked and the Redis password masked on both sides One line changed, and the record shows exactly that line. The modified index of the Route before and after is in the header of each side.

Above the diff, every record carries:

  • Event: the action and its code, such as route.updated, the result, the reason, and when the record was started and completed.
  • Actor: a user or a service account, the name, the source (local or directory) and the session.
  • Target: the type, the name and the id of the object, the Environment, and a link to the object as it is now.
  • Request: the request id, the IP address, and the other events the same request produced.
  • Details: the metadata as stored, such as the masked paths that changed.

The record pages carry no edit and no delete action. What was written stays as it was written, for 365 days by default; the operator sets the retention.

Reading the records elsewhere

CSV. The Export CSV button on the audit log writes the current filter to a file with one row per event: id, at, completed_at, action, result, reason, actor_type, actor_name, actor_source, environment, target_type, target_id, request_id, ip, meta, target_name. The export is itself an event, audit.exported, with the filter and the number of rows it returned.

The server’s log. Every completed record is also a JSON line in the G8 server’s log, with the same fields, so your log collector receives it the moment it is written:

{"msg":"audit","event_id":44,"phase":"complete","action":"audit.exported","result":"success",
 "actor_name":"nora.becker","environment":"staging","target_type":"audit_log",
 "meta":{"format":"csv","rows":34},"persisted":true}

Analytics. Open a Route’s Analytics tab and the successful changes to that Route in the window are drawn on the request chart as numbered markers, listed under it with the actor. A change in the error rate can be read next to the change that caused it.

The request chart of the payments-api Route over the last hour, with numbered change markers at the times the Route was created and its Plugins were added The markers are the audit log on the chart: one per completed change. A refusal leaves a row in the log and no marker here, because nothing changed.

What to do next

  • Decide who may change what: roles are assigned per Environment under Users & access, and a Viewer reads the Routes, Services, Upstreams and Consumers of the Environment and changes nothing, as the denied attempt above shows. The permission model is described on Change control and audit.
  • Point your log collector at the G8 server’s log and alert on access.denied and on "result":"failure".
  • Read how a change is promoted between Environments, and how the copy appears in the audit log, on Change control and audit.
Next step

See G8 in a demo

We’ll show you the console with APIs and AI traffic like yours, and answer the questions these articles leave open.

  1. 01Demo
  2. 02Proof of conceptOn Docker for a quick start, or on the infrastructure you plan to run G8 on.
  3. 03LicenseWe prepare a quote for your edition and nodes, and you receive a signed license file.