Skip to content

Modular logistics and supply chain operating system (LSOS)

ci(postman): remove the temporary credential diagnostics

Ronald A. Richardsone6d0fe3a1b3d
diff --git a/.github/actions/postman-contract/action.yml b/.github/actions/postman-contract/action.yml
index d615d520..25047c84 100644
--- a/.github/actions/postman-contract/action.yml
+++ b/.github/actions/postman-contract/action.yml
@@ -265,140 +265,6 @@ runs:
fi
echo "✔ API key authenticates (HTTP 200)."
- # ------------------------------------------------------------------------
- # TEMPORARY DIAGNOSTIC — remove once the two failures below are explained.
- #
- # Two contract failures have survived repeated re-runs and every explanation
- # so far has been inference rather than evidence:
- #
- # fleetops GET /v1/organizations 401 {"errors":["Invalid platform API token."]}
- # storefront GET /storefront/v1/stores 400 {"errors":["Stores cannot have stores!"]}
- #
- # What is already ruled out, by a real Postman CLI 1.46.0 run of the
- # PUBLISHED collections against a local echo server:
- # * Both requests carry a request-level Authorization header while their
- # collection also declares a collection-level bearer auth. The
- # request-level header WINS — the echo server received
- # "Bearer <platform_token>" and "Bearer <network_key>", not the
- # collection-level {{api_key}} / {{storefront_key}}. Auth precedence is
- # NOT the cause, and neither YAML header form (mapping vs list) matters.
- # * An EMPTY --env-var does not drop the header and does not fall back to
- # the collection auth either — the CLI sends a bare "Authorization: Bearer".
- #
- # That leaves exactly two possibilities per failure, and this step separates
- # them. It deliberately sits in its own step with the SAME `env:` mapping as
- # the collection run, so it exercises the real steps.key.outputs.* plumbing
- # rather than the mint step's shell locals — an output that arrives empty is
- # invisible in the log, because the value is masked either way.
- #
- # A. the curls answer 200 -> the credentials are fine at the source and
- # the fault is in how the run carries them (env plumbing, or session
- # state accumulated across requests).
- # B. the curls answer 401/400 -> the credential is genuinely invalid at the
- # server and the fault is in rotation / persistence / caching.
- #
- # Nothing here is secret-revealing: only lengths and the public key prefixes
- # are printed, never a token body.
- # ------------------------------------------------------------------------
- - name: Diagnose credential plumbing (temporary)
- if: steps.pmauth.outputs.available == 'true'
- shell: bash
- env:
- API_KEY: ${{ steps.key.outputs.api_key }}
- PLATFORM_TOKEN: ${{ steps.key.outputs.platform_token }}
- STOREFRONT_KEY: ${{ steps.key.outputs.storefront_key }}
- NETWORK_KEY: ${{ steps.key.outputs.network_key }}
- BASE_URL: ${{ inputs.base-url }}
- NAMESPACE: ${{ inputs.namespace }}
- run: |
- set -uo pipefail
-
- echo "::group::C. do the step outputs actually arrive non-empty?"
- # ::add-mask:: hides the value, so a step output that arrived EMPTY and one that
- # arrived correct are indistinguishable in the log — which is exactly how two
- # earlier readings of this log went wrong. Length and shape cannot be masked and
- # reveal nothing: no substring of any key is printed, because ::add-mask:: only
- # redacts the whole value and a prefix would go out in the clear.
- shape() {
- if [[ -z "$2" ]]; then
- verdict="EMPTY — this output never made it out of the mint step"
- elif [[ "$2" =~ $3 ]]; then
- verdict="well-formed"
- else
- verdict="NON-EMPTY but does not match $3"
- fi
- printf '%-16s len=%-4s %s\n' "$1" "${#2}" "$verdict"
- }
- shape API_KEY "${API_KEY}" '^flb_(live|test)_[A-Za-z0-9]+$'
- shape PLATFORM_TOKEN "${PLATFORM_TOKEN}" '^flb_platform_[A-Za-z0-9]{64}$'
- shape STOREFRONT_KEY "${STOREFRONT_KEY}" '^store_[a-f0-9]{32}$'
- shape NETWORK_KEY "${NETWORK_KEY}" '^network_[a-f0-9]{32}$'
- echo "::endgroup::"
-
- echo "::group::A. do the credentials work straight from the runner?"
- probe() {
- # $1 label, $2 bearer, $3 url
- code="$(curl -s -o /tmp/diag-body.txt -w '%{http_code}' -H "Authorization: Bearer $2" "$3" || echo 000)"
- printf '%-46s %s %s\n' "$1" "$code" "$(head -c 160 /tmp/diag-body.txt)"
- }
- probe "organizations <- platform_token" "${PLATFORM_TOKEN}" "${BASE_URL}/${NAMESPACE}/organizations"
- # Contrast probe: the org API key is what the collection-level auth would send.
- # If THIS is the token reaching the endpoint, the 401 is an auth-precedence
- # problem after all; if it 401s while the platform probe 200s, it is not.
- probe "organizations <- api_key (contrast)" "${API_KEY}" "${BASE_URL}/${NAMESPACE}/organizations"
- probe "network stores <- network_key" "${NETWORK_KEY}" "${BASE_URL}/storefront/${NAMESPACE}/stores"
- probe "network stores <- storefront_key (contrast)" "${STOREFRONT_KEY}" "${BASE_URL}/storefront/${NAMESPACE}/stores"
- echo "::endgroup::"
-
- echo "::group::D. does a shared session leak the store scope into the network call?"
- # SetStorefrontSession is cookie-backed and the Postman CLI keeps a cookie jar
- # for the whole collection, so every request in the Storefront run shares ONE
- # Laravel session. setKey() nulls storefront_store before setting the network
- # branch, so a network call after a store call SHOULD be clean — but that is
- # the assumption the 400 contradicts, and it has never been tested with a jar.
- #
- # Sequence below mirrors the run: a store-key request first (List Network
- # Stores is preceded by store-scoped requests), then the network-key request
- # on the SAME jar. A 400 here while the jarless probe above returned 200 is
- # the whole answer.
- jar="$(mktemp)"
- seq_probe() {
- code="$(curl -s -o /tmp/diag-body.txt -w '%{http_code}' -c "$jar" -b "$jar" \
- -H "Authorization: Bearer $2" "$3" || echo 000)"
- printf '%-46s %s %s\n' "$1" "$code" "$(head -c 160 /tmp/diag-body.txt)"
- }
- seq_probe "1. about <- storefront_key (jar)" "${STOREFRONT_KEY}" "${BASE_URL}/storefront/${NAMESPACE}/about"
- seq_probe "2. network stores <- network_key (same jar)" "${NETWORK_KEY}" "${BASE_URL}/storefront/${NAMESPACE}/stores"
- seq_probe "3. network stores <- network_key (repeat)" "${NETWORK_KEY}" "${BASE_URL}/storefront/${NAMESPACE}/stores"
- rm -f "$jar"
- echo "::endgroup::"
-
- echo "::group::B. what does the API itself think, inside the container?"
- # Read-only introspection. Only PHP double quotes are used below so the
- # surrounding single-quoted --execute needs no escaping gymnastics.
- #
- # NOT probed here: opcache. `artisan tinker` runs under the CLI SAPI, whose
- # opcache is a different arena from FrankenPHP's workers, so anything it
- # reported about cached bytecode would be about the wrong process. Whether the
- # workers are running the overlaid class is answered behaviourally by probes
- # A and D instead.
- docker compose exec -T application php artisan tinker --execute="
- \$hash = \Fleetbase\Models\Setting::system(\"platform_api.token_hash\");
- echo \"platform hash = \" . (is_string(\$hash) && \$hash !== \"\" ? \"set, \" . strlen(\$hash) . \" chars, algo \" . substr(\$hash, 0, 4) : var_export(\$hash, true)) . PHP_EOL;
- echo \"rotated_at = \" . var_export(\Fleetbase\Models\Setting::system(\"platform_api.token_rotated_at\"), true) . PHP_EOL;
- echo \"cache.default = \" . config(\"cache.default\") . PHP_EOL;
- echo \"session.driver = \" . config(\"session.driver\") . PHP_EOL;
- echo \"core-api = \" . \Composer\InstalledVersions::getPrettyVersion(\"fleetbase/core-api\") . PHP_EOL;
- if (class_exists(\"\Fleetbase\Storefront\Http\Middleware\SetStorefrontSession\")) {
- echo \"storefront-api = \" . \Composer\InstalledVersions::getPrettyVersion(\"fleetbase/storefront-api\") . PHP_EOL;
- \$f = (new ReflectionClass(\"\Fleetbase\Storefront\Http\Middleware\SetStorefrontSession\"))->getFileName();
- \$src = file_get_contents(\$f);
- echo \"SetStorefrontSession = \" . \$f . \" (mtime \" . date(\"c\", filemtime(\$f)) . \")\" . PHP_EOL;
- echo \" setKey clears store scope on disk = \" . (preg_match(\"/storefront_store.{0,24}=> *null/\", \$src) ? \"yes\" : \"NO — the overlay did not land\") . PHP_EOL;
- }
- " 2>&1 || echo "(tinker probe failed)"
- echo "::endgroup::"
-
- name: Install Postman CLI
if: steps.pmauth.outputs.available == 'true'
shell: bash
@@ -420,139 +286,6 @@ runs:
token: ${{ inputs.github-token }}
path: .postman
- # ------------------------------------------------------------------------
- # TEMPORARY DIAGNOSTIC — the second half of the pair, remove with the other.
- #
- # The first diagnostic established, from this runner, that:
- # * every credential arrives well-formed and non-empty;
- # * platform_token gets 200 from /v1/organizations and network_key gets
- # 200 from /storefront/v1/stores, jarless AND over a shared cookie jar;
- # * the CONTRAST probes reproduce both failures exactly — api_key gets
- # 401 "Invalid platform API token." and storefront_key gets
- # 400 "Stores cannot have stores!".
- #
- # So the credentials are fine and the run is reaching those endpoints with
- # the COLLECTION-level credential instead of the request-level one. For
- # storefront that is already conclusive: only a valid store key can produce
- # a 400 there, an empty or unresolved bearer gives 401.
- #
- # What is still unproven is the mechanism, and it must not be guessed again.
- # Locally, Postman CLI 1.46.0 sends the request-level header — verified
- # against an echo server. This runner installs whatever is current (1.47.0
- # on attempts 1-3, 1.47.2 on 4-5) and is logged in, neither of which the
- # local test reproduced. A request-level `auth:` block is NOT the fix and
- # must not be tried: it makes the request vanish from the collection and
- # aborts the run with "items were not found", measured, id present or not.
- #
- # This step settles it by running the two failing requests through THIS
- # runner's CLI, in its logged-in state, against a local echo server, with
- # sentinel values in place of real credentials:
- #
- # SENTINEL_COLLECTION_AUTH -> the collection-level bearer won
- # SENTINEL_REQUEST_HEADER -> the request-level header won
- #
- # Nothing secret is involved and nothing leaves the runner.
- # ------------------------------------------------------------------------
- - name: Diagnose which credential goes on the wire (temporary)
- if: steps.pmauth.outputs.available == 'true'
- shell: bash
- run: |
- # set +e, not just -uo pipefail. GitHub runs composite steps under
- # `bash -e -o pipefail`, and -uo does NOT clear the -e it inherits. That is
- # not academic: `wait` on a process this step itself SIGTERMs returns 143,
- # -e aborted the step there, and because a failed step skips the ones after
- # it, the whole "Run Postman collections" step was skipped — the diagnostic
- # took out the thing it was meant to diagnose. A diagnostic must never be
- # able to fail the job, hence the explicit `exit 0` at the end too.
- set +e
- set -uo pipefail
- POSTMAN_DIR="${GITHUB_WORKSPACE:-$PWD}/.postman"
- ECHO="${RUNNER_TEMP:-/tmp}/wire-echo.py"
- WIRE="${RUNNER_TEMP:-/tmp}/wire.log"
-
- # printf rather than a heredoc: an unindented heredoc terminator would end
- # this YAML block scalar. Double quotes only in the Python, so the
- # single-quoted shell arguments need no escaping.
- printf '%s\n' \
- 'import http.server' \
- 'class H(http.server.BaseHTTPRequestHandler):' \
- ' def do_GET(self):' \
- ' if self.path.startswith("/__ready"):' \
- ' self.send_response(200)' \
- ' self.end_headers()' \
- ' return' \
- ' v = self.headers.get("Authorization") or ""' \
- ' if "SENTINEL_COLLECTION_AUTH" in v:' \
- ' tag = "COLLECTION-BEARER (inherited)"' \
- ' elif "SENTINEL_REQUEST_HEADER" in v:' \
- ' tag = "REQUEST-LEVEL (the requests own credential)"' \
- ' else:' \
- ' tag = "NEITHER: " + repr(v)' \
- ' print("WIRE " + self.path.split("?")[0] + " -> " + tag, flush=True)' \
- ' self.send_response(200)' \
- ' self.send_header("Content-Type", "application/json")' \
- ' self.end_headers()' \
- ' self.wfile.write(b"[]")' \
- ' def log_message(self, *a):' \
- ' pass' \
- 'http.server.HTTPServer(("127.0.0.1", 8099), H).serve_forever()' > "$ECHO"
-
- python3 "$ECHO" > "$WIRE" 2>&1 &
- echo_pid=$!
- for i in $(seq 1 20); do
- # The server answers /__ready without logging it, so the wire log contains
- # only real requests and "did anything arrive?" is a straight emptiness test.
- curl -fsS --max-time 1 http://127.0.0.1:8099/__ready >/dev/null 2>&1 && break
- [[ $i -eq 20 ]] && { echo "::warning::wire echo server never came up; skipping"; kill "$echo_pid" 2>/dev/null; exit 0; }
- sleep 0.5
- done
-
- # Same cd as the real runner: the CLI resolves paths against its own cwd.
- (
- cd "$POSTMAN_DIR" || exit 1
- postman collection run "postman/collections/Fleetbase API" -r cli \
- --env-var "base_url=http://127.0.0.1:8099" \
- --env-var "namespace=v1" \
- --env-var "api_key=SENTINEL_COLLECTION_AUTH" \
- --env-var "platform_token=SENTINEL_REQUEST_HEADER" \
- -i "List Organizations" > /dev/null 2>&1
- postman collection run "postman/collections/Fleetbase Storefront API" -r cli \
- --env-var "base_url=http://127.0.0.1:8099" \
- --env-var "namespace=v1" \
- --env-var "api_prefix=storefront" \
- --env-var "storefront_key=SENTINEL_COLLECTION_AUTH" \
- --env-var "network_key=SENTINEL_REQUEST_HEADER" \
- -i "List Network Stores" > /dev/null 2>&1
- ) || true
-
- sleep 1
- # Every one of these is a plausible non-zero: kill races the exit, wait
- # reports the signal as 143, and grep returns 1 when the log is empty.
- kill "$echo_pid" 2>/dev/null || true
- wait "$echo_pid" 2>/dev/null || true
- echo "Postman CLI: $(postman --version 2>&1 | head -1)"
- # The echo server maps the header to a LABEL rather than echoing it. Printing
- # the raw value was useless: the runner rendered both lines as "***", so the
- # log could not say which sentinel belonged to which request, and the verdict
- # below would have read "collection" even if only one of the two did that.
- echo "--- what the two failing requests actually put on the wire ---"
- cat "$WIRE" 2>/dev/null || true
- [[ -s "$WIRE" ]] || echo "(nothing reached the echo server)"
- # Verdict per request, not for the pair. Two requests, and they can disagree.
- if [[ ! -s "$WIRE" ]]; then
- echo "=> Neither request executed. Check for 'items were not found'."
- elif grep -q "COLLECTION-BEARER" "$WIRE"; then
- echo "=> At least one request still sends the COLLECTION bearer — read the lines above,"
- echo " each one names its own request. Expected after fleetbase/postman#50: both"
- echo " REQUEST-LEVEL, and both endpoints green in the collection run below."
- else
- echo "=> Both requests send their own credential. This is the fixed state."
- fi
-
- # Belt and braces: a composite step cannot use continue-on-error, so the only
- # way to guarantee this never blocks the collection run is to exit clean.
- exit 0
-
- name: Run Postman collections
if: steps.pmauth.outputs.available == 'true'
shell: bash