Nikasa, home Request an invite
DocsOutside services

Outside services

Your app's calls to outside services reach the real service on the first run and are answered from a recording after that, so a vendor's answers cannot differ between builds.

On this page

Your app may call services outside the sandbox, such as a payment provider, an email service or a login provider. This page explains what Nikasa does with those calls, and how to choose which hosts may be reached.

During a compare #

Nikasa compares builds, not vendors. So the first run reaches the real service, and every later run is answered from a recording of it. Both builds then get the same answers.

  1. The first old run runs alone and reaches outside hosts live. Every HTTP call Nikasa can read to such a host, on port 80 or 443, is recorded in the compare's folder under outside/.
  2. Every later run, of either build, sends those hosts to a small server in the sandbox that answers from that recording.
  3. A request it has no answer for goes to the real host, is reported with its content, and is added to the recording.
  4. A value that differs on every run, such as a nonce or an install id, is left out of matching after one miss. The report names it under matched loosely.
  5. A host Nikasa cannot answer for stays live, and the report says why.

The report ends with one block, never counted as a change, saying how each outside host was handled. What a vendor answers is shown for information and never counted.

Answers that are too large to keep #

An answer of 1 MiB or more got in step 3 cannot be kept whole, so it is not added. That call goes to the real host in every later run.

The report names it beside its host as too large to keep, so live in every run, with the call. report.json lists these calls under too_large in the host's row.

Old run 1's answers are read from the capture and have no such limit.

Hosts Nikasa cannot answer for #

The report gives one of these reasons:

  • encrypted, without logged keys;
  • not HTTP;
  • another port;
  • a stream;
  • a client that refused the run's certificate;
  • reached by address, after a lookup gave that address out.

Choose what may leave #

Without a list, the report drafts one from the hosts the runs reached, ready to paste into your app file:

yaml
x-nk:
  outside: [api.example.com, "*.images.example.net"]

An entry is one of two forms:

Entry What it allows
api.example.com That name only.
*.example.net Names under the suffix, not the suffix itself.

With a list, every other name fails to resolve. The report names it as blocked, and in which builds, so a new host in the new build stands out at once. The list also applies to nk try, nk run and nk record.

A list works on names, and the sandbox's gateway works on the addresses they answer. Calls made by address says what that stops and what it leaves open.

Block everything, or check the recording #

Flag What it does
--offline Nothing outside the sandbox can be reached or resolved.
--live-outside Every run reaches outside hosts live and nothing is recorded, to check that answering from the recording hides nothing. It does not go with --offline or a pack's recordings.

What a recording keeps #

While nk record runs, your app's calls to outside services reach the real services once. Nikasa keeps each one as a recorded answer, called a cassette.

A cassette is a WireMock stub you can read, kept in the pack's cassettes/mappings/<host>/. An answer over 1 MB is kept in cassettes/__files/ beside it.

What a cassette holds:

  • Calls over HTTP/1 and HTTP/2 are kept alike. A gRPC call over HTTP/2 is not kept as a cassette.
  • Credentials in requests are left out.
  • Session cookies vendors set are replaced.
  • A field that changed between the self-check's runs, such as a timestamp, is left out of matching and listed in pack.json.

Cassettes answer on the standard ports only, 80 and 443. A call to another port reads as not answered. A pack with no cassettes, and no tokens to make fresh, runs like any other compare.

Compare with a pack that has cassettes #

Nothing leaves the sandbox. A WireMock container answers every outside call from the cassettes, over HTTPS too, using a certificate authority made for that run. Both builds get the same answers.

Situation What happens
A new or changed outside call that only the new build makes, and no recording answers It stops with an error, the report says why, and it is a change.
An outside call no recording answers that the old build makes too The pack is out of date, and the compare exits 2. Record it again.
A client refuses the run's certificate, for a host with a cassette, because it trusts only roots it carries itself The compare stops with exit 2. A service that does not run the build is listed as seen in the background instead.
Recorded answers older than 90 days They are flagged. Record again to refresh them.

A call nothing in the build's requests asked for #

This does not stop the compare when it comes from either of these:

  • a service that does not run the build, meaning its image is the same on both sides and is not the one being compared;
  • the build itself, before the first request.

A timer, such as a side service's telemetry, often does not fire during the recording. The report lists such a call as seen in the background and does not count it. A pack whose app really needs that answer is the case to record again.

For the build's own call once requests have begun, Nikasa decides from the runs:

  • It means the pack is out of date when it comes after the same request in every run of each build that makes it.
  • It looks like a timer, and is listed as seen in the background too, when it comes after no fixed request, skips a run, or also comes before the first request.
  • With fewer than 3 such runs, or no request times, Nikasa cannot tell and calls the pack out of date.

Logins through an outside provider #

What happens with an outside identity provider, such as Auth0, Okta or Entra, depends on what the run starts from.

The run What it does with the provider
A compare from a pack that sends a token it did not get inside the sandbox, or whose recorded answers hold one Answers in the provider's place and never calls it, in any run. The rest of this section is about this case.
Any other compare Treats the provider's host as one more outside host. The first old run reaches it live, and later runs follow the steps above.
nk try and nk run with no pack Reach it live, so point the app at a test tenant.
nk record Logs in through the real provider, with your real issuer.

For each token the pack sends that it did not get inside the sandbox, every compare run makes a fresh one: the same claims, its times moved to now, signed with a key made for that run.

The sandbox answers as the issuer of those tokens, and a recorded request to the provider's token endpoint gets a fresh token. This also covers tokens your services fetch themselves, through a client-credentials grant or a refresh.

Make your app trust the issuer #

In nk/app.yaml, have the app's issuer setting read NK_ISSUER, with your real issuer as the default:

yaml
services:
  app:
    environment:
      SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: ${NK_ISSUER:-https://login.example.com/}

nk init writes this for you when it recognises the setting:

  • Spring's ..._JWT_ISSUER_URI;
  • Quarkus's ..._AUTH_SERVER_URL;
  • ASP.NET's ...__Authority;
  • a *_ISSUER, *_ISSUER_URL or ISSUER_BASE_URL variable holding a URL.

nk record uses the real issuer, and a compare sets NK_ISSUER. The report says how many tokens were made fresh, and each run folder keeps identity.json.

Other cases #

Your app What to do or what happens
Refuses an http issuer, as ASP.NET does by default Pass --https-issuer to give it an https one.
Has a fixed issuer: no service reads NK_ISSUER, and the recording shows it trusting that issuer The issuer's own host answers inside the sandbox instead, with the run's key. This works for Node, Java, .NET, Python and Go.
Has a fixed issuer where that cannot run, for example an issuer on a port other than 80 or 443 The compare stops before any run with exit 2.
Runs an identity provider inside the sandbox, such as a Keycloak in your compose file It needs none of this, as long as its realm is imported the same way every run. See The app file.

The report's note says which way a compare took and why.

Tokens that stay as recorded #

  • A token signed with a shared secret (HS256 and the like), or not signed at all. Your app checks it against a secret Nikasa does not have. The compare's note says when the first such token expires.
  • Opaque tokens that are not JWTs.

Next steps #

Written for nk 0.3.14. Something wrong or unclear? Write to hello@nikasa.dev.